in this example program (supplied by Pascal Cuoq), UBSan should either error in both cases, or in neither of them (I would argue that it should not error in either case, but ymmv):
void f(int a) {
a ? 0 : 0x7fffffff + 1;
}
void g(int a) {
a ? 0 : 0 >> 32;
}
int main(void) {
f(1);
g(1);
}
instead, however, UBSan errors on the shift bug, but not on the overflowing addition. when this program is run, this is the output we see:
/app/example.c:6:13: runtime error: shift exponent 32 is too large for 32-bit type 'int'
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.c:6:13 in
Yeah, seems like a case where the code is unreachable, so the program does not invoke UB so far as I know - so it's a false positive for UBSan to diagnose it.
Extended Description
https://gcc.godbolt.org/z/WxKjWMo47
in this example program (supplied by Pascal Cuoq), UBSan should either error in both cases, or in neither of them (I would argue that it should not error in either case, but ymmv):
void f(int a) { a ? 0 : 0x7fffffff + 1; }
void g(int a) { a ? 0 : 0 >> 32; }
int main(void) { f(1); g(1); }
instead, however, UBSan errors on the shift bug, but not on the overflowing addition. when this program is run, this is the output we see:
/app/example.c:6:13: runtime error: shift exponent 32 is too large for 32-bit type 'int' SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior /app/example.c:6:13 in