Open milianw opened 6 years ago
Isn't it defined in C/C++ due to promotion rules? AFAIK if you add two shorts and assign the result to short, arguments are first promoted to int's, int's are added and then the result is truncated back to short.
ugh TIL... Considering that this is often not what the developer intended, can we maybe get a flag for this similar to -fsanitize=unsigned-integer-overflow
to catch these?
I once filed LLVM bug #21530 about this and feedback was positive but it never got beyond prototype. Maybe try asking in Bugzilla?
(Ah, i though i'we seen this issue here, but failed to find it the first time.) As i have written in LLVM bug #21530, i'm looking into this, and have a functional, working patch. By itself, it's quite simple. But there is at least one known prerequisite blocker that needs to be resolved on the clang's side first.
And the second half - sign change - is finally here too. For integer scalars, i claim that the sanitizer is feature-complete. Only bitfield handling is missing.
Rough overview of not-yet-sanitized constructs, mostly for myself:
EmitCompoundAssignLValue()
EmitScalarPrePostIncDec()
EmitStoreThroughBitfieldLValue()
.
Will be basically impossible, because QualType
can not contain arbitrary-sized type,
and ubsan's TypeDescription
can only handle power-of-two sized types.
Special care needs to be applied, it's not just about truncation, the check should be outside of
that if (Info.StorageSize != Info.Size)
branch, else we will miss sign-changes.Compound assignment operators - done (yay) https://github.com/llvm-mirror/clang/commit/d8a18b8bb0023a295456958e267e84ba1d1f3d1f
Dummy comment to subscribe to this issue
You can just click on "Subscribe" button :)
Overflows for short, char and signed char are not caught by UBSAN. It does work for long long, long and int though: