Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / ubsan / TestCases / Pointer / index-overflow.cpp
blob2ff48cbd1811c28affa4ff657ecacc1baec012e8
1 // RUN: %clangxx -fsanitize=pointer-overflow %s -o %t
2 // RUN: %run %t 2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR2
3 // RUN: %run %t 1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=ERR1
4 // RUN: %run %t 0 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE
5 // RUN: %run %t -1 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE
6 // RUN: %run %t -2 2>&1 | FileCheck %s --implicit-check-not="runtime error:" --check-prefix=SAFE
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
12 int main(int argc, char *argv[]) {
13 // SAFE-NOT: runtime error
14 // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to
15 // ERR2: runtime error: pointer index expression with base {{.*}} overflowed to
16 // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer
17 // ERR1: runtime error: applying non-zero offset to non-null pointer 0x{{.*}} produced null pointer
19 char *p = (char *)(UINTPTR_MAX);
21 printf("%p\n", p + atoi(argv[1]));
23 char *q = (char *)(UINTPTR_MAX);
25 printf("%p\n", p - (-atoi(argv[1])));
27 return 0;