blob: f35fa1f959ae5ab74ebfb4062a3df19894a49900 [file] [log] [blame]
Peter Collingbourne49d29ed2013-10-20 21:29:32 +00001// RUN: %clangxx -DLSH_OVERFLOW -DOP='<<' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-LSH_OVERFLOW
2// RUN: %clangxx -DLSH_OVERFLOW -DOP='<<=' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-LSH_OVERFLOW
3// RUN: %clangxx -DTOO_LOW -DOP='<<' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
4// RUN: %clangxx -DTOO_LOW -DOP='>>' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
5// RUN: %clangxx -DTOO_LOW -DOP='<<=' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
6// RUN: %clangxx -DTOO_LOW -DOP='>>=' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_LOW
7// RUN: %clangxx -DTOO_HIGH -DOP='<<' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
8// RUN: %clangxx -DTOO_HIGH -DOP='>>' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
9// RUN: %clangxx -DTOO_HIGH -DOP='<<=' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
10// RUN: %clangxx -DTOO_HIGH -DOP='>>=' -fsanitize=shift %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-TOO_HIGH
Richard Smith6ebe4512012-10-09 19:34:32 +000011
12#include <stdint.h>
13
14int main() {
15 int a = 1;
16 unsigned b = 1;
17
18 a <<= 31; // ok in C++11, not ok in C99/C11
19 b <<= 31; // ok
20 b <<= 1; // still ok, unsigned
21
22#ifdef LSH_OVERFLOW
Will Dietz7cbd7e52012-12-02 18:43:33 +000023 // CHECK-LSH_OVERFLOW: shift.cpp:24:5: runtime error: left shift of negative value -2147483648
Richard Smith6ebe4512012-10-09 19:34:32 +000024 a OP 1;
25#endif
26
27#ifdef TOO_LOW
Will Dietz7cbd7e52012-12-02 18:43:33 +000028 // CHECK-TOO_LOW: shift.cpp:29:5: runtime error: shift exponent -3 is negative
Richard Smith6ebe4512012-10-09 19:34:32 +000029 a OP (-3);
30#endif
31
32#ifdef TOO_HIGH
33 a = 0;
Will Dietz7cbd7e52012-12-02 18:43:33 +000034 // CHECK-TOO_HIGH: shift.cpp:35:5: runtime error: shift exponent 32 is too large for 32-bit type 'int'
Richard Smith6ebe4512012-10-09 19:34:32 +000035 a OP 32;
36#endif
37}