diff options
| author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-10-09 19:34:32 +0000 |
|---|---|---|
| committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-10-09 19:34:32 +0000 |
| commit | 68b3014cd3a1018a95ea5dec579fb7db067f35ba (patch) | |
| tree | 2af2f2975db7a7b8c8f2ff132436af6025623351 /compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp | |
| parent | a88397d9bacf0fc59ad4c5cfd244648528aeb195 (diff) | |
| download | bcm5719-llvm-68b3014cd3a1018a95ea5dec579fb7db067f35ba.tar.gz bcm5719-llvm-68b3014cd3a1018a95ea5dec579fb7db067f35ba.zip | |
Add a runtime diagnostics library for Clang's -fcatch-undefined-behavior.
llvm-svn: 165533
Diffstat (limited to 'compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp')
| -rw-r--r-- | compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp b/compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp new file mode 100644 index 00000000000..33a15313f3d --- /dev/null +++ b/compiler-rt/lib/ubsan/lit_tests/Integer/shift.cpp @@ -0,0 +1,37 @@ +// RUN: %clang -DLSH_OVERFLOW -DOP='<<' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=LSH_OVERFLOW +// RUN: %clang -DLSH_OVERFLOW -DOP='<<=' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=LSH_OVERFLOW +// RUN: %clang -DTOO_LOW -DOP='<<' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_LOW +// RUN: %clang -DTOO_LOW -DOP='>>' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_LOW +// RUN: %clang -DTOO_LOW -DOP='<<=' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_LOW +// RUN: %clang -DTOO_LOW -DOP='>>=' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_LOW +// RUN: %clang -DTOO_HIGH -DOP='<<' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_HIGH +// RUN: %clang -DTOO_HIGH -DOP='>>' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_HIGH +// RUN: %clang -DTOO_HIGH -DOP='<<=' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_HIGH +// RUN: %clang -DTOO_HIGH -DOP='>>=' -fcatch-undefined-behavior %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=TOO_HIGH + +#include <stdint.h> + +int main() { + int a = 1; + unsigned b = 1; + + a <<= 31; // ok in C++11, not ok in C99/C11 + b <<= 31; // ok + b <<= 1; // still ok, unsigned + +#ifdef LSH_OVERFLOW + // CHECK-LSH_OVERFLOW: shift.cpp:24:5: fatal error: left shift of negative value -2147483648 + a OP 1; +#endif + +#ifdef TOO_LOW + // CHECK-TOO_LOW: shift.cpp:29:5: fatal error: shift exponent -3 is negative + a OP (-3); +#endif + +#ifdef TOO_HIGH + a = 0; + // CHECK-TOO_HIGH: shift.cpp:35:5: fatal error: shift exponent 32 is too large for 32-bit type 'int' + a OP 32; +#endif +} |

