brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.4 KiB · d0d9226 Raw
75 lines · cpp
1// RUN: %clangxx_asan -O0 %s -o %t -mllvm -asan-detect-invalid-pointer-pair2 3// RUN: %env_asan_opts=detect_invalid_pointer_pairs=2 %run %t4 5#include <assert.h>6#include <stdlib.h>7 8int foo(char *p) {9  char *p2 = p + 20;10  return p > p2;11}12 13int bar(char *p, char *q) {14  return p <= q;15}16 17int baz(char *p, char *q) {18  return p != 0 && p < q;19}20 21char global[8192] = {};22char small_global[7] = {};23 24int main() {25  // Heap allocated memory.26  char *p = (char *)malloc(42);27  int r = foo(p);28  free(p);29 30  p = (char *)malloc(1024);31  bar(p, p + 1024);32  bar(p + 1024, p + 1023);33  bar(p + 1, p + 1023);34  free(p);35 36  p = (char *)malloc(4096);37  bar(p, p + 4096);38  bar(p + 10, p + 100);39  bar(p + 1024, p + 4096);40  bar(p + 4095, p + 4096);41  bar(p + 4095, p + 4094);42  bar(p + 100, p + 4096);43  bar(p + 100, p + 4094);44  free(p);45 46  // Global variable.47  bar(&global[0], &global[1]);48  bar(&global[1], &global[2]);49  bar(&global[2], &global[1]);50  bar(&global[0], &global[100]);51  bar(&global[1000], &global[7000]);52  bar(&global[500], &global[10]);53  p = &global[0];54  bar(p, p + 8192);55  p = &global[8000];56  bar(p, p + 192);57 58  p = &small_global[0];59  bar(p, p + 1);60  bar(p, p + 7);61  bar(p + 7, p + 1);62  bar(p + 6, p + 7);63  bar(p + 7, p + 7);64 65  // Stack variable.66  char stack[10000];67  bar(&stack[0], &stack[100]);68  bar(&stack[1000], &stack[9000]);69  bar(&stack[500], &stack[10]);70 71  baz(0, &stack[10]);72 73  return 0;74}75