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
8int foo(char *p, char *q) {
9 return p <= q;
10}
11
12char global[8192] = {};
13char small_global[7] = {};
14
15int main() {
16 // Heap allocated memory.
17 char *p = (char *)malloc(size: 42);
18 int r = foo(p, NULL);
19 free(ptr: p);
20
21 p = (char *)malloc(size: 1024);
22 foo(NULL, q: p);
23 free(ptr: p);
24
25 p = (char *)malloc(size: 4096);
26 foo(p, NULL);
27 free(ptr: p);
28
29 // Global variable.
30 foo(p: &global[0], NULL);
31 foo(p: &global[1000], NULL);
32
33 p = &small_global[0];
34 foo(p, NULL);
35
36 // Stack variable.
37 char stack[10000];
38 foo(p: &stack[0], NULL);
39 foo(NULL, q: &stack[9000]);
40
41 return 0;
42}
43

source code of compiler-rt/test/asan/TestCases/invalid-pointer-pairs-compare-null.cpp