13d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar// RUN: %clangxx -DOP=n++ -fsanitize=signed-integer-overflow %s -o %t1 && %run %t1 2>&1 | FileCheck %s --check-prefix=PLUS
23d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar// RUN: %clangxx -DOP=++n -fsanitize=signed-integer-overflow %s -o %t2 && %run %t2 2>&1 | FileCheck %s --check-prefix=PLUS
33d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar// RUN: %clangxx -DOP=m-- -fsanitize=signed-integer-overflow %s -o %t3 && %run %t3 2>&1 | FileCheck %s --check-prefix=MINUS
43d763c0d3700e73b3aead8e65e04ec28efc56138Pirama Arumuga Nainar// RUN: %clangxx -DOP=--m -fsanitize=signed-integer-overflow %s -o %t4 && %run %t4 2>&1 | FileCheck %s --check-prefix=MINUS
56ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith
66ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith#include <stdint.h>
76ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith
86ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smithint main() {
96ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith  int n = 0x7ffffffd;
106ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith  n++;
116ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith  n++;
126ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith  int m = -n - 1;
136ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith  OP;
14cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar  // PLUS: incdec-overflow.cpp:[[@LINE-1]]:3: runtime error: signed integer overflow: 2147483647 + 1 cannot be represented in type 'int'
15cdce50bda3603770cc4ef80cbb613c78b8e47a17Pirama Arumuga Nainar  // MINUS: incdec-overflow.cpp:[[@LINE-2]]:3: runtime error: signed integer overflow: -2147483648 - 1 cannot be represented in type 'int'
166ebe45146a2d93eb010b9bb5ea34cb94c6900f83Richard Smith}
17