| 1 | // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair |
| 2 | |
| 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 |
| 5 | |
| 6 | #include <assert.h> |
| 7 | #include <stdlib.h> |
| 8 | |
| 9 | int bar(char *p, char *q) { |
| 10 | return p - q; |
| 11 | } |
| 12 | |
| 13 | char global[10000] = {}; |
| 14 | |
| 15 | int main() { |
| 16 | // Heap allocated memory. |
| 17 | char *p = (char *)malloc(size: 42); |
| 18 | int r = bar(p, q: p + 20); |
| 19 | free(ptr: p); |
| 20 | |
| 21 | // Global variable. |
| 22 | bar(p: &global[0], q: &global[100]); |
| 23 | bar(p: &global[1000], q: &global[9000]); |
| 24 | bar(p: &global[500], q: &global[10]); |
| 25 | bar(p: &global[0], q: &global[10000]); |
| 26 | |
| 27 | // Stack variable. |
| 28 | char stack[10000]; |
| 29 | bar(p: &stack[0], q: &stack[100]); |
| 30 | bar(p: &stack[1000], q: &stack[9000]); |
| 31 | bar(p: &stack[500], q: &stack[10]); |
| 32 | |
| 33 | return 0; |
| 34 | } |
| 35 | |