Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / asan / TestCases / invalid-pointer-pairs-subtract-success.cpp
blob6c464cd67129ce39c4b08f3bbde94071c4b6f169
1 // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair
3 // RUN: %env_asan_opts=detect_invalid_pointer_pairs=2 %run %t
4 // RUN: %env_asan_opts=detect_invalid_pointer_pairs=2,detect_stack_use_after_return=0 %run %t
6 #include <assert.h>
7 #include <stdlib.h>
9 int bar(char *p, char *q) {
10 return p - q;
13 char global[10000] = {};
15 int main() {
16 // Heap allocated memory.
17 char *p = (char *)malloc(42);
18 int r = bar(p, p + 20);
19 free(p);
21 // Global variable.
22 bar(&global[0], &global[100]);
23 bar(&global[1000], &global[9000]);
24 bar(&global[500], &global[10]);
25 bar(&global[0], &global[10000]);
27 // Stack variable.
28 char stack[10000];
29 bar(&stack[0], &stack[100]);
30 bar(&stack[1000], &stack[9000]);
31 bar(&stack[500], &stack[10]);
33 return 0;