blob: d6832a46d703e66c40125080871c9bcd5e798f03 [file] [log] [blame]
Kostya Serebryany71efba02012-01-24 19:25:38 +00001// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck %s
Richard Smithd6396a62012-11-05 22:21:05 +00002// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix ASAN %s
Will Dietz4f45bc02013-01-18 11:30:38 +00003// RUN: echo "src:%s" > %t
4// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t | FileCheck %s
Kostya Serebryany71efba02012-01-24 19:25:38 +00005
NAKAMURA Takumiea8bca72013-01-18 14:11:04 +00006// FIXME: %t is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp"
7// REQUIRES: shell
8
Kostya Serebryany71efba02012-01-24 19:25:38 +00009// The address_safety attribute should be attached to functions
10// when AddressSanitizer is enabled, unless no_address_safety_analysis attribute
11// is present.
12
13// CHECK-NOT: NoAddressSafety1{{.*}} address_safety
14// ASAN-NOT: NoAddressSafety1{{.*}} address_safety
15__attribute__((no_address_safety_analysis))
16int NoAddressSafety1(int *a) { return *a; }
17
18// CHECK-NOT: NoAddressSafety2{{.*}} address_safety
19// ASAN-NOT: NoAddressSafety2{{.*}} address_safety
20__attribute__((no_address_safety_analysis))
21int NoAddressSafety2(int *a);
22int NoAddressSafety2(int *a) { return *a; }
23
24// CHECK-NOT: AddressSafetyOk{{.*}} address_safety
25// ASAN: AddressSafetyOk{{.*}} address_safety
26int AddressSafetyOk(int *a) { return *a; }
27
28// CHECK-NOT: TemplateNoAddressSafety{{.*}} address_safety
29// ASAN-NOT: TemplateNoAddressSafety{{.*}} address_safety
30template<int i>
31__attribute__((no_address_safety_analysis))
32int TemplateNoAddressSafety() { return i; }
33
34// CHECK-NOT: TemplateAddressSafetyOk{{.*}} address_safety
35// ASAN: TemplateAddressSafetyOk{{.*}} address_safety
36template<int i>
37int TemplateAddressSafetyOk() { return i; }
38
39int force_instance = TemplateAddressSafetyOk<42>()
40 + TemplateNoAddressSafety<42>();
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000041
42// Check that __cxx_global_var_init* get the address_safety attribute.
43int global1 = 0;
44int global2 = *(int*)((char*)&global1+1);
45// CHECK-NOT: @__cxx_global_var_init{{.*}}address_safety
46// ASAN: @__cxx_global_var_init{{.*}}address_safety