1*7c3d14c8STreehugger Robot // RUN: %clangxx -DLSH_OVERFLOW -DOP='<<' -fsanitize=shift-base -fno-sanitize-recover=shift %s -o %t1 && not %run %t1 2>&1 | FileCheck %s --check-prefix=CHECK-LSH_OVERFLOW
2*7c3d14c8STreehugger Robot // RUN: %clangxx -DLSH_OVERFLOW -DOP='<<=' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t2 && not %run %t2 2>&1 | FileCheck %s --check-prefix=CHECK-LSH_OVERFLOW
3*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='<<' -fsanitize=shift-exponent -fno-sanitize-recover=shift %s -o %t3 && not %run %t3 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
4*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='>>' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t4 && not %run %t4 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
5*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='<<=' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t5 && not %run %t5 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
6*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='>>=' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t6 && not %run %t6 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
7*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='<<' -fsanitize=shift-exponent -fno-sanitize-recover=shift %s -o %t7 && not %run %t7 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
8*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='>>' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t8 && not %run %t8 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
9*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='<<=' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t9 && not %run %t9 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
10*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='>>=' -fsanitize=shift -fno-sanitize-recover=shift %s -o %t10 && not %run %t10 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
11*7c3d14c8STreehugger Robot
12*7c3d14c8STreehugger Robot // RUN: %clangxx -DLSH_OVERFLOW -DOP='<<' -fsanitize=shift-exponent -fno-sanitize-recover=shift %s -o %t12 && %run %t12
13*7c3d14c8STreehugger Robot // RUN: %clangxx -DLSH_OVERFLOW -DOP='>>' -fsanitize=shift-exponent -fno-sanitize-recover=shift %s -o %t13 && %run %t13
14*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='<<' -fsanitize=shift-base -fno-sanitize-recover=shift %s -o %t14 && %run %t14
15*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_LOW -DOP='>>' -fsanitize=shift-base -fno-sanitize-recover=shift %s -o %t15 && %run %t15
16*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='<<' -fsanitize=shift-base -fno-sanitize-recover=shift %s -o %t16 && %run %t16
17*7c3d14c8STreehugger Robot // RUN: %clangxx -DTOO_HIGH -DOP='>>' -fsanitize=shift-base -fno-sanitize-recover=shift %s -o %t17 && %run %t17
18*7c3d14c8STreehugger Robot
19*7c3d14c8STreehugger Robot #include <stdint.h>
20*7c3d14c8STreehugger Robot
main()21*7c3d14c8STreehugger Robot int main() {
22*7c3d14c8STreehugger Robot int a = 1;
23*7c3d14c8STreehugger Robot unsigned b = 1;
24*7c3d14c8STreehugger Robot
25*7c3d14c8STreehugger Robot a <<= 31; // ok in C++11, not ok in C99/C11
26*7c3d14c8STreehugger Robot b <<= 31; // ok
27*7c3d14c8STreehugger Robot b <<= 1; // still ok, unsigned
28*7c3d14c8STreehugger Robot
29*7c3d14c8STreehugger Robot #ifdef LSH_OVERFLOW
30*7c3d14c8STreehugger Robot // CHECK-LSH_OVERFLOW: shift.cpp:[[@LINE+1]]:5: runtime error: left shift of negative value -2147483648
31*7c3d14c8STreehugger Robot a OP 1;
32*7c3d14c8STreehugger Robot #endif
33*7c3d14c8STreehugger Robot
34*7c3d14c8STreehugger Robot #ifdef TOO_LOW
35*7c3d14c8STreehugger Robot a = 0;
36*7c3d14c8STreehugger Robot // CHECK-TOO_LOW: shift.cpp:[[@LINE+1]]:5: runtime error: shift exponent -3 is negative
37*7c3d14c8STreehugger Robot a OP (-3);
38*7c3d14c8STreehugger Robot #endif
39*7c3d14c8STreehugger Robot
40*7c3d14c8STreehugger Robot #ifdef TOO_HIGH
41*7c3d14c8STreehugger Robot a = 0;
42*7c3d14c8STreehugger Robot // CHECK-TOO_HIGH: shift.cpp:[[@LINE+1]]:5: runtime error: shift exponent 32 is too large for 32-bit type 'int'
43*7c3d14c8STreehugger Robot a OP 32;
44*7c3d14c8STreehugger Robot #endif
45*7c3d14c8STreehugger Robot }
46