gnu/gcc/00a0e7d2375850a0256c392005e10c7d28aeac97 tree: make TYPE_OVERFLOW_SANITIZED accept vector types
UBSan instruments signed integral vector arithmetic. However,
TYPE_OVERFLOW_SANITIZED only accepts scalar integral types. Folding can use
the false result to remove a vector operation before UBSan instruments it.
For example:
typedef int v4si __attribute__ ((vector_size (16)));
v4si f (v4si x) { return -(-x); }
Both negations can overflow. The scalar-only predicate lets fold-const reduce
the function to x and remove both diagnostics.
aarch64 -O2 -fsanitize=signed-integer-overflow
-fsanitize-trap=signed-integer-overflow before:
f:
ret
After:
f:
fmov w0, s0
negs w0, w0
bvs .L27
...
neg v31.4s, v0.4s
fmov w0, s31
negs w0, w0
bvs .L27
...
ret
.L27:
brk #1000
Use ANY_INTEGRAL_TYPE_P so the predicate also accepts integral vector types.
The test checks that both vector negations remain for UBSan instrumentation.
Bootstrapped and tested on aarch64-none-linux-gnu.
Tested on x86_64-pc-linux-gnu.
gcc/ChangeLog:
PR sanitizer/88109
* tree.h (TYPE_OVERFLOW_SANITIZED): Use ANY_INTEGRAL_TYPE_P.
gcc/testsuite/ChangeLog:
PR sanitizer/88109
* c-c++-common/ubsan/overflow-vec-3.c: New test.
Signed-off-by: Kyrylo Tkachov <ktkachov@nvidia.com>
2 files changed