Peter Collingbourne | 49d29ed | 2013-10-20 21:29:32 +0000 | [diff] [blame^] | 1 | // 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 Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 3 | |
| 4 | int main() { |
Will Dietz | f359dea | 2012-12-31 06:36:44 +0000 | [diff] [blame] | 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 |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 8 | -unsigned(-0x7fffffff - 1); // ok |
Will Dietz | f359dea | 2012-12-31 06:36:44 +0000 | [diff] [blame] | 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 |
Richard Smith | 6ebe451 | 2012-10-09 19:34:32 +0000 | [diff] [blame] | 11 | return -(-0x7fffffff - 1); |
| 12 | } |