Fix undefined behavior in regex_macros#201
Conversation
|
Note that this is currently blocked on rust-lang/rust#32804 |
|
@Amanieu Hmm, are you sure? The whole point of the sparse set optimization is that it never actually reads from uninitialized memory. See: http://research.swtch.com/sparse |
|
Actually it does read from uninitialized memory (sparse[i]):
|
|
@Amanieu ah, I see, yeah you're right. (I'd also be fine removing the optimization altogether.) |
|
Removing the optimization entirely is also an option, I think either way is fine. |
|
From an LLVM point of view, I believe it's correct that it's not undefined behavior to read undefined memory, it just returns The unefined behavior, however, is when you start doing things like branching and such. For example here if (nice catch regardless!) |
|
This should work now that |
|
Hmm, just waiting on the Windows CI to go through. |
|
Awesome, thank you! :-) |
The value read in
containsmay be uninitialized, and using such a value is undefined behavior. In particular with LLVM, wheresisundefand can return a different value each time it is read. The solution is to use a volatile load to ensure we already get a real value, not anundef.