blob: 88f75a1d5088555a8092f0fc84bcc201a2be2045 [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 Serebryany85aee962013-02-26 06:58:27 +00009// The sanitize_address attribute should be attached to functions
10// when AddressSanitizer is enabled, unless no_sanitize_address attribute
Kostya Serebryany71efba02012-01-24 19:25:38 +000011// is present.
12
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000013// WITHOUT: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
14// BL: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
15// ASAN: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000016__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000017int NoAddressSafety1(int *a) { return *a; }
18
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000019// WITHOUT: NoAddressSafety2{{.*}}) [[NOATTR]]
20// BL: NoAddressSafety2{{.*}}) [[NOATTR]]
21// ASAN: NoAddressSafety2{{.*}}) [[NOATTR]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000022__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000023int NoAddressSafety2(int *a);
24int NoAddressSafety2(int *a) { return *a; }
25
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +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 Wendlingbe9e8bf2013-02-28 22:49:57 +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 Wendlingbe9e8bf2013-02-28 22:49:57 +000037// WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
38// BL: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
39// ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000040template<int i>
Kostya Serebryany85aee962013-02-26 06:58:27 +000041__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000042int 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
Kostya Serebryany85aee962013-02-26 06:58:27 +000047// Check that __cxx_global_var_init* get the sanitize_address attribute.
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000048int global1 = 0;
49int global2 = *(int*)((char*)&global1+1);
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000050// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
51// BL: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
52// ASAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
Bill Wendlingf7a9da02013-02-20 07:22:19 +000053
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000054// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
55// WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
Bill Wendlingf7a9da02013-02-20 07:22:19 +000056
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000057// BL: attributes [[NOATTR]] = { nounwind{{.*}} }
58// BL: attributes [[NOATTR_NO_TF]] = { nounwind }
59
60// ASAN: attributes [[NOATTR]] = { nounwind{{.*}} }
61// ASAN: attributes [[WITH]] = { nounwind sanitize_address{{.*}} }
62// ASAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_address }