xref: /aosp_15_r20/external/compiler-rt/test/ubsan/TestCases/Integer/uincdec-overflow.cpp (revision 7c3d14c8b49c529e04be81a3ce6f5cc23712e4c6)
1*7c3d14c8STreehugger Robot // RUN: %clangxx -DOP=n++ -fsanitize=unsigned-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck --check-prefix=CHECK-INC %s
2*7c3d14c8STreehugger Robot // RUN: %clangxx -DOP=++n -fsanitize=unsigned-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck --check-prefix=CHECK-INC %s
3*7c3d14c8STreehugger Robot // RUN: %clangxx -DOP=m-- -fsanitize=unsigned-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck --check-prefix=CHECK-DEC %s
4*7c3d14c8STreehugger Robot // RUN: %clangxx -DOP=--m -fsanitize=unsigned-integer-overflow %s -o %t4 && %run %t4 2>&1 | FileCheck --check-prefix=CHECK-DEC %s
5*7c3d14c8STreehugger Robot 
6*7c3d14c8STreehugger Robot #include <stdint.h>
7*7c3d14c8STreehugger Robot 
main()8*7c3d14c8STreehugger Robot int main() {
9*7c3d14c8STreehugger Robot   unsigned n = 0xfffffffd;
10*7c3d14c8STreehugger Robot   n++;
11*7c3d14c8STreehugger Robot   n++;
12*7c3d14c8STreehugger Robot   unsigned m = 0;
13*7c3d14c8STreehugger Robot   // CHECK-INC: uincdec-overflow.cpp:15:3: runtime error: unsigned integer overflow: 4294967295 + 1 cannot be represented in type 'unsigned int'
14*7c3d14c8STreehugger Robot   // CHECK-DEC: uincdec-overflow.cpp:15:3: runtime error: unsigned integer overflow: 0 - 1 cannot be represented in type 'unsigned int'
15*7c3d14c8STreehugger Robot   OP;
16*7c3d14c8STreehugger Robot }
17