Update condition to remove addition that may cause an overflow.
Resolves PR42814.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 35903 Build 35902: arc lint + arc unit
Event Timeline
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
550–552 | Is Offset==0 == 0'th byte of the constant? |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
551 | This check looks suspicious to me. |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
551 | If Offset can be a negative value, it's possible to get an OOB access when Offset + BytesLoaded <= 0. |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
551 | Okay, sounds plausible. |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
551 | I think with the check as it is, there still could be an overflow *in theory*, e.g. for constants that are int64_max big. Given that we only allow global constants with initializers, this would mean a huge bitcode file, but while you're at it, it might be worth changing the comparisons to if (Offfset <= -BytesLoaded) as well |
test/Transforms/SCCP/ubsan_overflow.ll | ||
---|---|---|
2 | Shouldn't this be opt < %s -sccp -S |
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
551 | Use static_cast? That also makes it obvious whether the cast happens before or after the multiply. |
lgtm with some nits
lib/Analysis/ConstantFolding.cpp | ||
---|---|---|
547 | OOC is there a reason to flip the order of the two checks? If yes, can you please update the commit message (so as to not confuse folks digging through the commit history in the future)? | |
test/Transforms/SCCP/ubsan_overflow.ll | ||
13 | We probably should remove the unreachable. As written the function has unconditional UB which means some other optimization within SCCP could kick in. Probably the best thing to do is to return the value you loaded so that it can't get DCE'd away either (SCCP is unlikely to do that, but you never know). |
OOC is there a reason to flip the order of the two checks? If yes, can you please update the commit message (so as to not confuse folks digging through the commit history in the future)?