blob: bde0bdabb292fe532aab0b726574235ebab55c9a [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx -fsanitize=signed-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECKS
2// RUN: %clangxx -fsanitize=unsigned-integer-overflow %s -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=CHECKU
3
4int main() {
5 // 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
8 -unsigned(-0x7fffffff - 1); // ok
9 // 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
11 return -(-0x7fffffff - 1);
12}