1*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=integer -g0 %s -o %t
2*7c3d14c8STreehugger Robot
3*7c3d14c8STreehugger Robot // Suppression by symbol name (unsigned-integer-overflow:do_overflow below)
4*7c3d14c8STreehugger Robot // requires the compiler-rt runtime to be able to symbolize stack addresses.
5*7c3d14c8STreehugger Robot // REQUIRES: can-symbolize
6*7c3d14c8STreehugger Robot
7*7c3d14c8STreehugger Robot // Fails without any suppression.
8*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1 not %run %t 2>&1 | FileCheck %s
9*7c3d14c8STreehugger Robot
10*7c3d14c8STreehugger Robot // RUN: echo "signed-integer-overflow:%t" > %t.wrong-supp
11*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.wrong-supp"' not %run %t 2>&1 | FileCheck %s
12*7c3d14c8STreehugger Robot
13*7c3d14c8STreehugger Robot // RUN: echo "unsigned-integer-overflow:do_overflow" > %t.func-supp
14*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.func-supp"' %run %t
15*7c3d14c8STreehugger Robot // RUN: echo "unsigned-integer-overflow:%t" > %t.module-supp
16*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' %run %t
17*7c3d14c8STreehugger Robot
18*7c3d14c8STreehugger Robot // Note: file-level suppressions should work even without debug info.
19*7c3d14c8STreehugger Robot // RUN: echo "unsigned-integer-overflow:%s" > %t.file-supp
20*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.file-supp"' %run %t
21*7c3d14c8STreehugger Robot
22*7c3d14c8STreehugger Robot // Suppressions don't work for unrecoverable kinds.
23*7c3d14c8STreehugger Robot // RUN: %clangxx -fsanitize=integer -fno-sanitize-recover=integer %s -o %t-norecover
24*7c3d14c8STreehugger Robot // RUN: %env_ubsan_opts=halt_on_error=1:suppressions='"%t.module-supp"' not %run %t-norecover 2>&1 | FileCheck %s
25*7c3d14c8STreehugger Robot
26*7c3d14c8STreehugger Robot #include <stdint.h>
27*7c3d14c8STreehugger Robot
do_overflow()28*7c3d14c8STreehugger Robot extern "C" void do_overflow() {
29*7c3d14c8STreehugger Robot (void)(uint64_t(10000000000000000000ull) + uint64_t(9000000000000000000ull));
30*7c3d14c8STreehugger Robot // CHECK: runtime error: unsigned integer overflow
31*7c3d14c8STreehugger Robot }
32*7c3d14c8STreehugger Robot
main()33*7c3d14c8STreehugger Robot int main() {
34*7c3d14c8STreehugger Robot do_overflow();
35*7c3d14c8STreehugger Robot return 0;
36*7c3d14c8STreehugger Robot }
37