1 // RUN: %clang_cc1 -no-opaque-pointers -fsanitize=address -emit-llvm -o - %s | FileCheck %s
2 
3 // Test ignorelist functionality.
4 // RUN: echo "src:%s=init" | sed -e 's/\\/\\\\/g' > %t-file.ignorelist
5 // RUN: echo "type:PODWithCtorAndDtor=init" > %t-type.ignorelist
6 // RUN: echo "type:NS::PODWithCtor=init" >> %t-type.ignorelist
7 // RUN: %clang_cc1 -no-opaque-pointers -fsanitize=address -fsanitize-ignorelist=%t-file.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST
8 // RUN: %clang_cc1 -no-opaque-pointers -fsanitize=address -fsanitize-ignorelist=%t-type.ignorelist -emit-llvm -o - %s | FileCheck %s --check-prefix=IGNORELIST
9 
10 struct PODStruct {
11   int x;
12 };
13 PODStruct s1;
14 
15 struct PODWithDtor {
16   ~PODWithDtor() { }
17   int x;
18 };
19 PODWithDtor s2;
20 
21 struct PODWithCtorAndDtor {
22   PODWithCtorAndDtor() { }
23   ~PODWithCtorAndDtor() { }
24   int x;
25 };
26 PODWithCtorAndDtor s3;
27 
28 namespace NS {
29 class PODWithCtor {
30 public:
31   PODWithCtor() {}
32 };
33 
34 const volatile PODWithCtor array[5][5];
35 }
36 
37 // Check that ASan init-order checking ignores structs with trivial default
38 // constructor.
39 
40 // CHECK: @s1 ={{.*}} global
41 // CHECK-NOT: sanitize_address_dyninit
42 // CHECK: @s2 ={{.*}} global
43 // CHECK-NOT: sanitize_address_dyninit
44 // CHECK: @s3 ={{.*}} global {{.*}}, sanitize_address_dyninit
45 // CHECK: @{{.*}}array{{.*}} ={{.*}} global {{.*}}, sanitize_address_dyninit
46 
47 // CHECK: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]
48 // CHECK: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
49 // CHECK: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
50 // CHECK: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 true, i1 false}
51 // CHECK: ![[GLOB_4]] = !{{{.*}}class.NS::PODWithCtor{{.*}}, i1 true, i1 false}
52 
53 // IGNORELIST: @s1 ={{.*}} global
54 // IGNORELIST-NOT: sanitize_address_dyninit
55 // IGNORELIST: @s2 ={{.*}} global
56 // IGNORELIST-NOT: sanitize_address_dyninit
57 // IGNORELIST: @s3 ={{.*}} global
58 // IGNORELIST-NOT: sanitize_address_dyninit
59 // IGNORELIST: @{{.*}}array{{.*}} ={{.*}} global
60 // IGNORELIST-NOT: sanitize_address_dyninit
61 
62 // IGNORELIST: !llvm.asan.globals = !{![[GLOB_1:[0-9]+]], ![[GLOB_2:[0-9]+]], ![[GLOB_3:[0-9]+]], ![[GLOB_4:[0-9]+]]}
63 // IGNORELIST: ![[GLOB_1]] = !{%struct.PODStruct* {{.*}}, i1 false, i1 false}
64 // IGNORELIST: ![[GLOB_2]] = !{%struct.PODWithDtor* {{.*}}, i1 false, i1 false}
65 // IGNORELIST: ![[GLOB_3]] = !{%struct.PODWithCtorAndDtor* {{.*}}, i1 false, i1 false}
66 // IGNORELIST: ![[GLOB_4]] = !{{{.*}}class.NS::PODWithCtor{{.*}}, i1 false, i1 false}
67