1 // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair 2 3 // RUN: %env_asan_opts=detect_invalid_pointer_pairs=1 %run %t 4 5 #include <assert.h> 6 #include <stdlib.h> 7 8 int foo(char *p, char *q) { 9 return p <= q; 10 } 11 12 char global[8192] = {}; 13 char small_global[7] = {}; 14 15 int main() { 16 // Heap allocated memory. 17 char *p = (char *)malloc(42); 18 int r = foo(p, NULL); 19 free(p); 20 21 p = (char *)malloc(1024); 22 foo(NULL, p); 23 free(p); 24 25 p = (char *)malloc(4096); 26 foo(p, NULL); 27 free(p); 28 29 // Global variable. 30 foo(&global[0], NULL); 31 foo(&global[1000], NULL); 32 33 p = &small_global[0]; 34 foo(p, NULL); 35 36 // Stack variable. 37 char stack[10000]; 38 foo(&stack[0], NULL); 39 foo(NULL, &stack[9000]); 40 41 return 0; 42 } 43