Home | History | Annotate | Download | only in Darwin
      1 // Main executable is uninstrumented, but linked to ASan runtime.
      2 // Regression test for https://code.google.com/p/address-sanitizer/issues/detail?id=357.
      3 
      4 // RUN: %clangxx -g -O0 %s -c -o %t.o
      5 // RUN: %clangxx_asan -g -O0 %t.o -o %t
      6 // RUN: %run %t 2>&1 | FileCheck %s
      7 
      8 #include <stdio.h>
      9 #include <stdlib.h>
     10 #include <string.h>
     11 
     12 #include "sanitizer/asan_interface.h"
     13 
     14 void test_shadow(char *p, size_t size) {
     15   fprintf(stderr, "p = %p\n", p);
     16   char *q = (char *)__asan_region_is_poisoned(p, size);
     17   fprintf(stderr, "=%zd=\n", q ? q - p : -1);
     18 }
     19 
     20 int main(int argc, char *argv[]) {
     21   char *p = (char *)malloc(10000);
     22   test_shadow(p, 100);
     23   free(p);
     24   // CHECK: =-1=
     25 
     26   test_shadow((char *)&main, 1);
     27   // CHECK: =-1=
     28 
     29   test_shadow((char *)&p, 1);
     30   // CHECK: =-1=
     31 
     32   return 0;
     33 }
     34