| 1 | // RUN: %clangxx -fsanitize=integer -g0 %s -o %t |
| 2 | |
| 3 | // Suppression by symbol name (unsigned-integer-overflow:do_overflow below) |
| 4 | // requires the compiler-rt runtime to be able to symbolize stack addresses. |
| 5 | // REQUIRES: can-symbolize |
| 6 | // UNSUPPORTED: android |
| 7 | // Output differs on OpenBSD longer by displaying the values. |
| 8 | // XFAIL: target={{.*openbsd.*}} |
| 9 | |
| 10 | // Fails without any suppression. |
| 11 | // RUN: %env_ubsan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s |
| 12 | |
| 13 | // RUN: echo "signed-integer-overflow:%t" > %t.wrong-supp |
| 14 | // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.wrong-supp"' not %run %t 2>&1 | FileCheck %s |
| 15 | |
| 16 | // RUN: echo "unsigned-integer-overflow:do_overflow" > %t.func-supp |
| 17 | // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t |
| 18 | // FIXME: The '%t' substitution can't be used for the module name because it |
| 19 | // contains a colon, so we have to use the basename, which is |
| 20 | // suppressions.cpp.tmp. |
| 21 | // RUN: echo "unsigned-integer-overflow:suppressions.cpp.tmp" > %t.module-supp |
| 22 | // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' %run %t |
| 23 | |
| 24 | // Note: file-level suppressions should work even without debug info. |
| 25 | // RUN: echo "unsigned-integer-overflow:%s" > %t.file-supp |
| 26 | // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.file-supp"' %run %t |
| 27 | |
| 28 | // Suppressions don't work for unrecoverable kinds. |
| 29 | // RUN: %clangxx -fsanitize=integer -fno-sanitize-recover=integer %s -o %t-norecover |
| 30 | // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' not %run %t-norecover 2>&1 | FileCheck %s |
| 31 | |
| 32 | #include <stdint.h> |
| 33 | |
| 34 | extern "C" void do_overflow() { |
| 35 | (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull)); |
| 36 | // CHECK: runtime error: unsigned integer overflow |
| 37 | } |
| 38 | |
| 39 | int main() { |
| 40 | do_overflow(); |
| 41 | return 0; |
| 42 | } |
| 43 | |