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