blob: a830e23da1b650b956d63c35c163c542b4f1ee4d [file] [log] [blame]
Bill Wendling0c67fc92013-02-22 00:04:55 +00001// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
2// RUN: %clang_cc1 -triple x86_64-apple-darwin -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 Wendling0c67fc92013-02-22 00:04:55 +00004// RUN: %clang_cc1 -triple x86_64-apple-darwin -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 Wendling478bbf32013-02-21 19:44:18 +000050// WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
51// BL: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
52// ASAN: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
Bill Wendlingf7a9da02013-02-20 07:22:19 +000053
Bill Wendling478bbf32013-02-21 19:44:18 +000054// WITHOUT: attributes #[[NOATTR]] = { nounwind{{.*}} }
55// WITHOUT: attributes #[[GVI]] = { nounwind{{.*}} }
56// BL: attributes #[[NOATTR]] = { nounwind{{.*}} }
57// BL: attributes #[[GVI]] = { nounwind{{.*}} }
Bill Wendlingf7a9da02013-02-20 07:22:19 +000058
Bill Wendling478bbf32013-02-21 19:44:18 +000059// ASAN: attributes #[[NOATTR]] = { nounwind{{.*}} }
60// ASAN: attributes #[[WITH]] = { address_safety nounwind{{.*}} }
61// ASAN: attributes #[[GVI]] = { address_safety nounwind{{.*}} }