blob: 827f8d15b4d02242138b52e2827e0550e4085a4d [file] [log] [blame]
Bill Wendling3bba3ef2013-02-20 19:30:01 +00001// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
2// 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
Bill Wendling3bba3ef2013-02-20 19:30:01 +00004// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %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 Wendling3bba3ef2013-02-20 19:30:01 +000013// WITHOUT: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
14// BL: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
15// ASAN: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000016__attribute__((no_address_safety_analysis))
17int NoAddressSafety1(int *a) { return *a; }
18
Bill Wendling3bba3ef2013-02-20 19:30:01 +000019// WITHOUT: NoAddressSafety2{{.*}}) #[[NOATTR]]
20// BL: NoAddressSafety2{{.*}}) #[[NOATTR]]
21// ASAN: NoAddressSafety2{{.*}}) #[[NOATTR]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000022__attribute__((no_address_safety_analysis))
23int NoAddressSafety2(int *a);
24int NoAddressSafety2(int *a) { return *a; }
25
Bill Wendling3bba3ef2013-02-20 19:30:01 +000026// WITHOUT: AddressSafetyOk{{.*}}) #[[NOATTR]]
27// BL: AddressSafetyOk{{.*}}) #[[NOATTR]]
28// ASAN: AddressSafetyOk{{.*}}) #[[WITH:[0-9]+]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000029int AddressSafetyOk(int *a) { return *a; }
30
Bill Wendling3bba3ef2013-02-20 19:30:01 +000031// WITHOUT: TemplateAddressSafetyOk{{.*}}) #[[NOATTR]]
32// BL: TemplateAddressSafetyOk{{.*}}) #[[NOATTR]]
33// ASAN: TemplateAddressSafetyOk{{.*}}) #[[WITH]]
Bill Wendlingf7a9da02013-02-20 07:22:19 +000034template<int i>
35int TemplateAddressSafetyOk() { return i; }
36
Bill Wendling3bba3ef2013-02-20 19:30:01 +000037// WITHOUT: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
38// BL: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
39// ASAN: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000040template<int i>
41__attribute__((no_address_safety_analysis))
42int TemplateNoAddressSafety() { return i; }
43
Kostya Serebryany71efba02012-01-24 19:25:38 +000044int force_instance = TemplateAddressSafetyOk<42>()
45 + TemplateNoAddressSafety<42>();
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000046
47// Check that __cxx_global_var_init* get the address_safety attribute.
48int global1 = 0;
49int global2 = *(int*)((char*)&global1+1);
Bill Wendling3bba3ef2013-02-20 19:30:01 +000050// WITHOUT: @__cxx_global_var_init{{.*}}#1
51// BL: @__cxx_global_var_init{{.*}}#1
Bill Wendlingf7a9da02013-02-20 07:22:19 +000052// ASAN: @__cxx_global_var_init{{.*}}#2
53
Bill Wendling3bba3ef2013-02-20 19:30:01 +000054// WITHOUT: attributes #[[NOATTR]] = { nounwind "target-features"={{.*}} }
55// BL: attributes #[[NOATTR]] = { nounwind "target-features"={{.*}} }
Bill Wendlingf7a9da02013-02-20 07:22:19 +000056
Bill Wendling3bba3ef2013-02-20 19:30:01 +000057// ASAN: attributes #[[NOATTR]] = { nounwind "target-features"={{.*}} }
58// ASAN: attributes #[[WITH]] = { address_safety nounwind "target-features"={{.*}} }