-
-
Notifications
You must be signed in to change notification settings - Fork 9.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
-Waggressive-loop-optimizations UB warning in to_words52 on 3.0.x, but not 3.1.x/master #21088
Comments
Any idea what's undefined here? 19 iterations is kind of weird too. |
For 1024 bit numbers, it's reaching the final element (20th). I suspect the optimiser is thinking that it could go one further. |
Yeah, this looks like a bug in the compiler. out_len is int so it can go negative without UB. However this cannot really go negative. So this seems to be bogus warning. |
I think it's stepping off the end of the array, even though it isn't really. |
GCC 13.1.0 were reporting a compilation warning with -O2/3 and -Waggressive-loop-optimizations. GCC is raising an undefined behavior in the while loop, so this workaround asserts that `out_len` isn't supposed to go negative. Fixes openssl#21088
concur that its probably a compiler bug, though it looks super odd in disassembly:
Reading -O3 bits is always really hard for me, but that to me looks like the compiler decided to optimize away the entire while (out_len > 0) loop. out I believe gets stored in %rsi (which makes sense), but I don't ever see anything in that assembly that winds up storing a zero to %rsi in the unrolled loop |
GCC 13.1.0 were reporting a compilation warning with -O2/3 and -Waggressive-loop-optimizations. GCC is raising an undefined behavior in the while loop. Replace the while loop with a memset call at the top of the function. Fixes openssl#21088
GCC 13.1.0 were reporting a compilation warning with -O2/3 and -Waggressive-loop-optimizations. GCC is raising an undefined behavior in the while loop. Replace the while loop with a memset call at the top of the function. Fixes openssl#21088
GCC 13.1.0 were reporting a compilation warning with -O2/3 and -Waggressive-loop-optimizations. GCC is raising an undefined behavior in the while loop. Replace the while loop with a memset call at the top of the function. Fixes openssl#21088 CLA: trivial
GCC 13.1.0 were reporting a compilation warning with -O2/3 and -Waggressive-loop-optimizations. GCC is raising an undefined behavior in the while loop. Replace the while loop with a memset call at the top of the function. Fixes openssl#21088 CLA: trivial
Config:
With OpenSSL 3.0.9, I get the following while building with -O2 or -O3:
But OpenSSL 1.1.1u and OpenSSL 3.1.1 are fine.
I spent a while staring at and comparing the branches and was avoiding looking at 3d2b47b given it's pretty large, but I think that's the commit which fixes it on 3.1.x. If I try to (very cheesily) cherry-pick it to 3.0.x just to see if it helps, that works.
That commit is unfortunately pretty large and includes some refactoring as prep work for the optimisation it adds, so it's hard as somone unfamiliar with the codebase to figure out quickly which bits are the actual substantive change suppressing the warning here, or if it's just by chance.
The text was updated successfully, but these errors were encountered: