2013-02-22 08:04:55 +08:00
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix=ASAN %s
|
2013-03-06 18:54:18 +08:00
|
|
|
// RUN: echo "src:%s" > %t.file.blacklist
|
|
|
|
// RUN: echo "fun:*BlacklistedFunction*" > %t.func.blacklist
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.file.blacklist | FileCheck -check-prefix=BLFILE %s
|
|
|
|
// RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t.func.blacklist | FileCheck -check-prefix=BLFUNC %s
|
2012-01-25 03:25:38 +08:00
|
|
|
|
2013-03-06 18:54:18 +08:00
|
|
|
// FIXME: %t.file.blacklist is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp"
|
2013-01-18 22:11:04 +08:00
|
|
|
// REQUIRES: shell
|
|
|
|
|
2013-02-26 14:58:27 +08:00
|
|
|
// The sanitize_address attribute should be attached to functions
|
|
|
|
// when AddressSanitizer is enabled, unless no_sanitize_address attribute
|
2012-01-25 03:25:38 +08:00
|
|
|
// is present.
|
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
|
|
|
|
// BLFUNC: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]]
|
2013-02-26 14:58:27 +08:00
|
|
|
__attribute__((no_sanitize_address))
|
2012-01-25 03:25:38 +08:00
|
|
|
int NoAddressSafety1(int *a) { return *a; }
|
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: NoAddressSafety2{{.*}}) [[NOATTR]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: NoAddressSafety2{{.*}}) [[NOATTR]]
|
|
|
|
// BLFUNC: NoAddressSafety2{{.*}}) [[NOATTR]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: NoAddressSafety2{{.*}}) [[NOATTR]]
|
2013-02-26 14:58:27 +08:00
|
|
|
__attribute__((no_sanitize_address))
|
2012-01-25 03:25:38 +08:00
|
|
|
int NoAddressSafety2(int *a);
|
|
|
|
int NoAddressSafety2(int *a) { return *a; }
|
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: AddressSafetyOk{{.*}}) [[NOATTR]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: AddressSafetyOk{{.*}}) [[NOATTR]]
|
|
|
|
// BLFUNC: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]]
|
2012-01-25 03:25:38 +08:00
|
|
|
int AddressSafetyOk(int *a) { return *a; }
|
|
|
|
|
2013-03-06 18:54:18 +08:00
|
|
|
// WITHOUT: BlacklistedFunction{{.*}}) [[NOATTR]]
|
|
|
|
// BLFILE: BlacklistedFunction{{.*}}) [[NOATTR]]
|
|
|
|
// BLFUNC: BlacklistedFunction{{.*}}) [[NOATTR]]
|
|
|
|
// ASAN: BlacklistedFunction{{.*}}) [[WITH]]
|
|
|
|
int BlacklistedFunction(int *a) { return *a; }
|
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: TemplateAddressSafetyOk{{.*}}) [[NOATTR]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: TemplateAddressSafetyOk{{.*}}) [[NOATTR]]
|
|
|
|
// BLFUNC: TemplateAddressSafetyOk{{.*}}) [[WITH]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: TemplateAddressSafetyOk{{.*}}) [[WITH]]
|
2012-01-25 03:25:38 +08:00
|
|
|
template<int i>
|
2013-02-20 15:22:19 +08:00
|
|
|
int TemplateAddressSafetyOk() { return i; }
|
2012-01-25 03:25:38 +08:00
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
|
|
|
|
// BLFUNC: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]]
|
2012-01-25 03:25:38 +08:00
|
|
|
template<int i>
|
2013-02-26 14:58:27 +08:00
|
|
|
__attribute__((no_sanitize_address))
|
2013-02-20 15:22:19 +08:00
|
|
|
int TemplateNoAddressSafety() { return i; }
|
2012-01-25 03:25:38 +08:00
|
|
|
|
|
|
|
int force_instance = TemplateAddressSafetyOk<42>()
|
|
|
|
+ TemplateNoAddressSafety<42>();
|
2012-06-26 16:56:33 +08:00
|
|
|
|
2013-02-26 14:58:27 +08:00
|
|
|
// Check that __cxx_global_var_init* get the sanitize_address attribute.
|
2012-06-26 16:56:33 +08:00
|
|
|
int global1 = 0;
|
|
|
|
int global2 = *(int*)((char*)&global1+1);
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]]
|
|
|
|
// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
|
2013-03-01 06:49:57 +08:00
|
|
|
// ASAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]]
|
2013-02-22 03:44:18 +08:00
|
|
|
|
2013-03-01 06:49:57 +08:00
|
|
|
// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind }
|
2013-02-22 03:44:18 +08:00
|
|
|
|
2013-03-06 18:54:18 +08:00
|
|
|
// BLFILE: attributes [[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// BLFILE: attributes [[NOATTR_NO_TF]] = { nounwind }
|
|
|
|
|
|
|
|
// BLFUNC: attributes [[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// BLFUNC: attributes [[WITH]] = { nounwind sanitize_address{{.*}} }
|
|
|
|
// BLFUNC: attributes [[WITH_NO_TF]] = { nounwind sanitize_address }
|
2013-03-01 06:49:57 +08:00
|
|
|
|
|
|
|
// ASAN: attributes [[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// ASAN: attributes [[WITH]] = { nounwind sanitize_address{{.*}} }
|
|
|
|
// ASAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_address }
|