blob: f94efd62c9c0f38ac9f6f3c67b368b9ba40d767f [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
Alexey Samsonov7e73f942013-03-06 10:54:18 +00003// RUN: echo "src:%s" > %t.file.blacklist
4// RUN: echo "fun:*BlacklistedFunction*" > %t.func.blacklist
5// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.file.blacklist | FileCheck -check-prefix=BLFILE %s
6// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.func.blacklist | FileCheck -check-prefix=BLFUNC %s
Kostya Serebryany71efba02012-01-24 19:25:38 +00007
Alexey Samsonov7e73f942013-03-06 10:54:18 +00008// FIXME: %t.file.blacklist is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp"
NAKAMURA Takumiea8bca72013-01-18 14:11:04 +00009// REQUIRES: shell
10
Kostya Serebryany85aee962013-02-26 06:58:27 +000011// The sanitize_address attribute should be attached to functions
12// when AddressSanitizer is enabled, unless no_sanitize_address attribute
Kostya Serebryany71efba02012-01-24 19:25:38 +000013// is present.
14
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000015// WITHOUT: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000016// BLFILE: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
17// BLFUNC: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000018// ASAN: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000019__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000020int NoAddressSafety1(int *a) { return *a; }
21
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000022// WITHOUT: NoAddressSafety2{{.*}}) [[NOATTR]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000023// BLFILE: NoAddressSafety2{{.*}}) [[NOATTR]]
24// BLFUNC: NoAddressSafety2{{.*}}) [[NOATTR]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000025// ASAN: NoAddressSafety2{{.*}}) [[NOATTR]]
Kostya Serebryany85aee962013-02-26 06:58:27 +000026__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000027int NoAddressSafety2(int *a);
28int NoAddressSafety2(int *a) { return *a; }
29
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000030// WITHOUT: AddressSafetyOk{{.*}}) [[NOATTR]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000031// BLFILE: AddressSafetyOk{{.*}}) [[NOATTR]]
32// BLFUNC: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000033// ASAN: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000034int AddressSafetyOk(int *a) { return *a; }
35
Alexey Samsonov7e73f942013-03-06 10:54:18 +000036// WITHOUT: BlacklistedFunction{{.*}}) [[NOATTR]]
37// BLFILE: BlacklistedFunction{{.*}}) [[NOATTR]]
38// BLFUNC: BlacklistedFunction{{.*}}) [[NOATTR]]
39// ASAN: BlacklistedFunction{{.*}}) [[WITH]]
40int BlacklistedFunction(int *a) { return *a; }
41
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000042// WITHOUT: TemplateAddressSafetyOk{{.*}}) [[NOATTR]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000043// BLFILE: TemplateAddressSafetyOk{{.*}}) [[NOATTR]]
44// BLFUNC: TemplateAddressSafetyOk{{.*}}) [[WITH]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000045// ASAN: TemplateAddressSafetyOk{{.*}}) [[WITH]]
Bill Wendlingf7a9da02013-02-20 07:22:19 +000046template<int i>
47int TemplateAddressSafetyOk() { return i; }
48
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000049// WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000050// BLFILE: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
51// BLFUNC: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000052// ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
Kostya Serebryany71efba02012-01-24 19:25:38 +000053template<int i>
Kostya Serebryany85aee962013-02-26 06:58:27 +000054__attribute__((no_sanitize_address))
Kostya Serebryany71efba02012-01-24 19:25:38 +000055int TemplateNoAddressSafety() { return i; }
56
Kostya Serebryany71efba02012-01-24 19:25:38 +000057int force_instance = TemplateAddressSafetyOk<42>()
58 + TemplateNoAddressSafety<42>();
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000059
Kostya Serebryany85aee962013-02-26 06:58:27 +000060// Check that __cxx_global_var_init* get the sanitize_address attribute.
Kostya Serebryanyb9d2b3b2012-06-26 08:56:33 +000061int global1 = 0;
62int global2 = *(int*)((char*)&global1+1);
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000063// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
Alexey Samsonov7e73f942013-03-06 10:54:18 +000064// BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
65// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000066// ASAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
Bill Wendlingf7a9da02013-02-20 07:22:19 +000067
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000068// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
69// WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
Bill Wendlingf7a9da02013-02-20 07:22:19 +000070
Alexey Samsonov7e73f942013-03-06 10:54:18 +000071// BLFILE: attributes [[NOATTR]] = { nounwind{{.*}} }
72// BLFILE: attributes [[NOATTR_NO_TF]] = { nounwind }
73
74// BLFUNC: attributes [[NOATTR]] = { nounwind{{.*}} }
75// BLFUNC: attributes [[WITH]] = { nounwind sanitize_address{{.*}} }
76// BLFUNC: attributes [[WITH_NO_TF]] = { nounwind sanitize_address }
Bill Wendlingbe9e8bf2013-02-28 22:49:57 +000077
78// ASAN: attributes [[NOATTR]] = { nounwind{{.*}} }
79// ASAN: attributes [[WITH]] = { nounwind sanitize_address{{.*}} }
80// ASAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_address }