blob: 20aaebeb48e0cad5cf4cf7ae845fd1aac494f37c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
// RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair
// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2:halt_on_error=0 %run %t 2>&1 | FileCheck %s
#include <assert.h>
#include <stdlib.h>
int foo(char *p, char *q) {
return p - q;
}
char global1[100] = {}, global2[100] = {};
int main() {
// Heap allocated memory.
char *heap1 = (char *)malloc(42);
char *heap2 = (char *)malloc(42);
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(heap1, heap2);
// Global variables.
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(&global1[0], &global2[10]);
// Stack variables.
char stack1, stack2;
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(&stack1, &stack2);
// Mixtures.
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(heap1, &stack1);
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(heap1, &global1[0]);
// CHECK: ERROR: AddressSanitizer: invalid-pointer-pair
// CHECK: #{{[0-9]+ .*}} in main {{.*}}invalid-pointer-pairs-subtract-errors.cc:[[@LINE+1]]
foo(&stack1, &global1[0]);
free(heap1);
free(heap2);
return 0;
}
|