blob: aedbbc2bcb5050aa4a1cbf03fd6c65940e1ed053 [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
Bill Wendlingf7a9da02013-02-20 07:22:19 +000013// CHECK: NoAddressSafety1{{.*}}#0
14// ASAN: NoAddressSafety1{{.*}}#0
Kostya Serebryany71efba02012-01-24 19:25:38 +000015__attribute__((no_address_safety_analysis))
16int NoAddressSafety1(int *a) { return *a; }
17
Bill Wendlingf7a9da02013-02-20 07:22:19 +000018// CHECK: NoAddressSafety2{{.*}}#0
19// ASAN: NoAddressSafety2{{.*}}#0
Kostya Serebryany71efba02012-01-24 19:25:38 +000020__attribute__((no_address_safety_analysis))
21int NoAddressSafety2(int *a);
22int NoAddressSafety2(int *a) { return *a; }
23
Bill Wendlingf7a9da02013-02-20 07:22:19 +000024// CHECK: AddressSafetyOk{{.*}}#0
25// ASAN: AddressSafetyOk{{.*}}#1
Kostya Serebryany71efba02012-01-24 19:25:38 +000026int AddressSafetyOk(int *a) { return *a; }
27
Bill Wendlingf7a9da02013-02-20 07:22:19 +000028// CHECK: TemplateAddressSafetyOk{{.*}}#0
29// ASAN: TemplateAddressSafetyOk{{.*}}#1
30template<int i>
31int TemplateAddressSafetyOk() { return i; }
32
33// CHECK: TemplateNoAddressSafety{{.*}}#0
34// ASAN: TemplateNoAddressSafety{{.*}}#0
Kostya Serebryany71efba02012-01-24 19:25:38 +000035template<int i>
36__attribute__((no_address_safety_analysis))
37int TemplateNoAddressSafety() { return i; }
38
Kostya Serebryany71efba02012-01-24 19:25:38 +000039int 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);
Bill Wendlingf7a9da02013-02-20 07:22:19 +000045// CHECK: @__cxx_global_var_init{{.*}}#1
46// ASAN: @__cxx_global_var_init{{.*}}#2
47
48// CHECK: attributes #0 = { nounwind "target-features"={{.*}} }
49// CHECK: attributes #1 = { nounwind }
50
51// ASAN: attributes #0 = { nounwind "target-features"={{.*}} }
52// ASAN: attributes #1 = { address_safety nounwind "target-features"={{.*}} }
53// ASAN: attributes #2 = { address_safety nounwind }