3 ms·
> compiler flag that could be used to enable a trap if unsigned arithmetic resulted in wrap-around, as in the above case when the vector is of length zero. I m
by jcelerier 3y ago
> compiler flag that could be used to enable a trap if unsigned arithmetic resulted in wrap-around, as in the above case when the vector is of length zero.
I mean.. this is exactly what -fsanitize=integer does in clang.
I never saw a signed overflow UB, but how many "perfectly defined" yet horrendously wrong cases like this one this sanitizer has helped me find...
- gregfjohnson 3y agoThanks so much - I was unaware of this clang flag. I just confirmed, it does exactly what I was hoping for! I suggested that this be an optional flag, not the default behavior. I could see using it for unit-test/static-analysis builds where performance is not the main concern. (I have not looked at the generated assembly or done a performance comparison, but it might be that the -fsanitize=integer flag would slow the generated code down.)
- jcelerier 3y agoAnything that starts with -fsanitize is really only meant for debugging, definitely not production.