1// 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 3// 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 7 8// FIXME: %t.file.blacklist is like "src:x:\path\to\clang\test\CodeGen\address-safety-attr.cpp" 9// REQUIRES: shell 10 11// The sanitize_address attribute should be attached to functions 12// when AddressSanitizer is enabled, unless no_sanitize_address attribute 13// is present. 14 15// WITHOUT: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] 16// BLFILE: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] 17// BLFUNC: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] 18// ASAN: NoAddressSafety1{{.*}}) [[NOATTR:#[0-9]+]] 19__attribute__((no_sanitize_address)) 20int NoAddressSafety1(int *a) { return *a; } 21 22// WITHOUT: NoAddressSafety2{{.*}}) [[NOATTR]] 23// BLFILE: NoAddressSafety2{{.*}}) [[NOATTR]] 24// BLFUNC: NoAddressSafety2{{.*}}) [[NOATTR]] 25// ASAN: NoAddressSafety2{{.*}}) [[NOATTR]] 26__attribute__((no_sanitize_address)) 27int NoAddressSafety2(int *a); 28int NoAddressSafety2(int *a) { return *a; } 29 30// WITHOUT: AddressSafetyOk{{.*}}) [[NOATTR]] 31// BLFILE: AddressSafetyOk{{.*}}) [[NOATTR]] 32// BLFUNC: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]] 33// ASAN: AddressSafetyOk{{.*}}) [[WITH:#[0-9]+]] 34int AddressSafetyOk(int *a) { return *a; } 35 36// WITHOUT: BlacklistedFunction{{.*}}) [[NOATTR]] 37// BLFILE: BlacklistedFunction{{.*}}) [[NOATTR]] 38// BLFUNC: BlacklistedFunction{{.*}}) [[NOATTR]] 39// ASAN: BlacklistedFunction{{.*}}) [[WITH]] 40int BlacklistedFunction(int *a) { return *a; } 41 42// WITHOUT: TemplateAddressSafetyOk{{.*}}) [[NOATTR]] 43// BLFILE: TemplateAddressSafetyOk{{.*}}) [[NOATTR]] 44// BLFUNC: TemplateAddressSafetyOk{{.*}}) [[WITH]] 45// ASAN: TemplateAddressSafetyOk{{.*}}) [[WITH]] 46template<int i> 47int TemplateAddressSafetyOk() { return i; } 48 49// WITHOUT: TemplateNoAddressSafety{{.*}}) [[NOATTR]] 50// BLFILE: TemplateNoAddressSafety{{.*}}) [[NOATTR]] 51// BLFUNC: TemplateNoAddressSafety{{.*}}) [[NOATTR]] 52// ASAN: TemplateNoAddressSafety{{.*}}) [[NOATTR]] 53template<int i> 54__attribute__((no_sanitize_address)) 55int TemplateNoAddressSafety() { return i; } 56 57int force_instance = TemplateAddressSafetyOk<42>() 58 + TemplateNoAddressSafety<42>(); 59 60// Check that __cxx_global_var_init* get the sanitize_address attribute. 61int global1 = 0; 62int global2 = *(int*)((char*)&global1+1); 63// WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] 64// BLFILE: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] 65// BLFUNC: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]] 66// ASAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]] 67 68// WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} } 69// WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind } 70 71// 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 } 77 78// ASAN: attributes [[NOATTR]] = { nounwind{{.*}} } 79// ASAN: attributes [[WITH]] = { nounwind sanitize_address{{.*}} } 80// ASAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_address } 81