blob: 6bee3eea29802e78799eafa8f241a1b0428d494e [file] [log] [blame]
Peter Collingbourne49d29ed2013-10-20 21:29:32 +00001// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECKS
2// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECKU
Richard Smith6ebe4512012-10-09 19:34:32 +00003
4int main() {
Will Dietzf359dea2012-12-31 06:36:44 +00005 // CHECKS-NOT: runtime error
6 // CHECKU: negate-overflow.cpp:[[@LINE+2]]:3: runtime error: negation of 2147483648 cannot be represented in type 'unsigned int'
7 // CHECKU-NOT: cast to an unsigned
Richard Smith6ebe4512012-10-09 19:34:32 +00008 -unsigned(-0x7fffffff - 1); // ok
Will Dietzf359dea2012-12-31 06:36:44 +00009 // CHECKS: negate-overflow.cpp:[[@LINE+2]]:10: runtime error: negation of -2147483648 cannot be represented in type 'int'; cast to an unsigned type to negate this value to itself
10 // CHECKU-NOT: runtime error
Richard Smith6ebe4512012-10-09 19:34:32 +000011 return -(-0x7fffffff - 1);
12}