2013-02-21 03:30:01 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s
|
|
|
|
// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address | FileCheck -check-prefix=ASAN %s
|
2013-01-18 19:30:38 +08:00
|
|
|
// RUN: echo "src:%s" > %t
|
2013-02-21 03:30:01 +08:00
|
|
|
// RUN: %clang_cc1 -emit-llvm -o - %s -fsanitize=address -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s
|
2012-01-25 03:25:38 +08:00
|
|
|
|
2013-01-18 22:11:04 +08:00
|
|
|
// FIXME: %t is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp"
|
|
|
|
// REQUIRES: shell
|
|
|
|
|
2012-01-25 03:25:38 +08:00
|
|
|
// The address_safety attribute should be attached to functions
|
|
|
|
// when AddressSanitizer is enabled, unless no_address_safety_analysis attribute
|
|
|
|
// is present.
|
|
|
|
|
2013-02-21 03:30:01 +08:00
|
|
|
// WITHOUT: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
|
|
|
|
// BL: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
|
|
|
|
// ASAN: NoAddressSafety1{{.*}}) #[[NOATTR:[0-9]+]]
|
2012-01-25 03:25:38 +08:00
|
|
|
__attribute__((no_address_safety_analysis))
|
|
|
|
int NoAddressSafety1(int *a) { return *a; }
|
|
|
|
|
2013-02-21 03:30:01 +08:00
|
|
|
// WITHOUT: NoAddressSafety2{{.*}}) #[[NOATTR]]
|
|
|
|
// BL: NoAddressSafety2{{.*}}) #[[NOATTR]]
|
|
|
|
// ASAN: NoAddressSafety2{{.*}}) #[[NOATTR]]
|
2012-01-25 03:25:38 +08:00
|
|
|
__attribute__((no_address_safety_analysis))
|
|
|
|
int NoAddressSafety2(int *a);
|
|
|
|
int NoAddressSafety2(int *a) { return *a; }
|
|
|
|
|
2013-02-21 03:30:01 +08:00
|
|
|
// WITHOUT: AddressSafetyOk{{.*}}) #[[NOATTR]]
|
|
|
|
// BL: AddressSafetyOk{{.*}}) #[[NOATTR]]
|
|
|
|
// ASAN: AddressSafetyOk{{.*}}) #[[WITH:[0-9]+]]
|
2012-01-25 03:25:38 +08:00
|
|
|
int AddressSafetyOk(int *a) { return *a; }
|
|
|
|
|
2013-02-21 03:30:01 +08:00
|
|
|
// WITHOUT: TemplateAddressSafetyOk{{.*}}) #[[NOATTR]]
|
|
|
|
// BL: TemplateAddressSafetyOk{{.*}}) #[[NOATTR]]
|
|
|
|
// 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-02-21 03:30:01 +08:00
|
|
|
// WITHOUT: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
|
|
|
|
// BL: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
|
|
|
|
// ASAN: TemplateNoAddressSafety{{.*}}) #[[NOATTR]]
|
2012-01-25 03:25:38 +08:00
|
|
|
template<int i>
|
2013-02-20 15:22:19 +08:00
|
|
|
__attribute__((no_address_safety_analysis))
|
|
|
|
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
|
|
|
|
|
|
|
// Check that __cxx_global_var_init* get the address_safety attribute.
|
|
|
|
int global1 = 0;
|
|
|
|
int global2 = *(int*)((char*)&global1+1);
|
2013-02-22 03:44:18 +08:00
|
|
|
// WITHOUT: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
|
|
|
|
// BL: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
|
|
|
|
// ASAN: @__cxx_global_var_init{{.*}}#[[GVI:[0-9]+]]
|
|
|
|
|
|
|
|
// WITHOUT: attributes #[[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// WITHOUT: attributes #[[GVI]] = { nounwind{{.*}} }
|
|
|
|
// BL: attributes #[[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// BL: attributes #[[GVI]] = { nounwind{{.*}} }
|
|
|
|
|
|
|
|
// ASAN: attributes #[[NOATTR]] = { nounwind{{.*}} }
|
|
|
|
// ASAN: attributes #[[WITH]] = { address_safety nounwind{{.*}} }
|
|
|
|
// ASAN: attributes #[[GVI]] = { address_safety nounwind{{.*}} }
|