1 // RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair
3 // RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 %run %t 2>&1 | FileCheck %s
8 int foo(char *p
, char *q
) {
12 char global1
[100] = {}, global2
[100] = {};
13 char __attribute__((used
)) smallest_global
[5] = {};
14 char small_global
[7] = {};
15 char __attribute__((used
)) little_global
[10] = {};
16 char __attribute__((used
)) medium_global
[4000] = {};
17 char large_global
[5000] = {};
18 char __attribute__((used
)) largest_global
[6000] = {};
21 // Heap allocated memory.
22 char *heap1
= (char *)malloc(42);
23 char *heap2
= (char *)malloc(42);
25 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
26 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
31 heap1
= (char *)malloc(1024);
32 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
33 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
34 foo(heap1
, heap1
+ 1025);
35 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
36 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
37 foo(heap1
+ 1024, heap1
+ 1025);
40 heap1
= (char *)malloc(4096);
41 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
42 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
43 foo(heap1
, heap1
+ 4097);
44 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
45 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
49 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
50 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
51 foo(&global1
[0], &global2
[10]);
53 char *p
= &small_global
[0];
56 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
57 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
59 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
60 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
62 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
63 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
65 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
66 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
70 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
71 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
73 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
74 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
76 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
77 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
79 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
80 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
81 foo(p
, &small_global
[0]);
82 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
83 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
88 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
89 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
90 foo(&stack1
, &stack2
);
93 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
94 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]
96 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
97 foo(heap1
, &global1
[0]);
98 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
99 foo(&stack1
, &global1
[0]);
100 // CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
101 // CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-compare-errors.cpp:[[@LINE+1]]