1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s | FileCheck -check-prefix=WITHOUT %s 2*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread | FileCheck -check-prefix=TSAN %s 3*f4a2713aSLionel Sambuc // RUN: echo "src:%s" > %t 4*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -triple x86_64-apple-darwin -emit-llvm -o - %s -fsanitize=thread -fsanitize-blacklist=%t | FileCheck -check-prefix=BL %s 5*f4a2713aSLionel Sambuc 6*f4a2713aSLionel Sambuc // REQUIRES: shell 7*f4a2713aSLionel Sambuc 8*f4a2713aSLionel Sambuc // The sanitize_thread attribute should be attached to functions 9*f4a2713aSLionel Sambuc // when ThreadSanitizer is enabled, unless no_sanitize_thread attribute 10*f4a2713aSLionel Sambuc // is present. 11*f4a2713aSLionel Sambuc 12*f4a2713aSLionel Sambuc // WITHOUT: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] 13*f4a2713aSLionel Sambuc // BL: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] 14*f4a2713aSLionel Sambuc // TSAN: NoTSAN1{{.*}}) [[NOATTR:#[0-9]+]] 15*f4a2713aSLionel Sambuc __attribute__((no_sanitize_thread)) NoTSAN1(int * a)16*f4a2713aSLionel Sambucint NoTSAN1(int *a) { return *a; } 17*f4a2713aSLionel Sambuc 18*f4a2713aSLionel Sambuc // WITHOUT: NoTSAN2{{.*}}) [[NOATTR]] 19*f4a2713aSLionel Sambuc // BL: NoTSAN2{{.*}}) [[NOATTR]] 20*f4a2713aSLionel Sambuc // TSAN: NoTSAN2{{.*}}) [[NOATTR]] 21*f4a2713aSLionel Sambuc __attribute__((no_sanitize_thread)) 22*f4a2713aSLionel Sambuc int NoTSAN2(int *a); NoTSAN2(int * a)23*f4a2713aSLionel Sambucint NoTSAN2(int *a) { return *a; } 24*f4a2713aSLionel Sambuc 25*f4a2713aSLionel Sambuc // WITHOUT: TSANOk{{.*}}) [[NOATTR]] 26*f4a2713aSLionel Sambuc // BL: TSANOk{{.*}}) [[NOATTR]] 27*f4a2713aSLionel Sambuc // TSAN: TSANOk{{.*}}) [[WITH:#[0-9]+]] TSANOk(int * a)28*f4a2713aSLionel Sambucint TSANOk(int *a) { return *a; } 29*f4a2713aSLionel Sambuc 30*f4a2713aSLionel Sambuc // WITHOUT: TemplateTSANOk{{.*}}) [[NOATTR]] 31*f4a2713aSLionel Sambuc // BL: TemplateTSANOk{{.*}}) [[NOATTR]] 32*f4a2713aSLionel Sambuc // TSAN: TemplateTSANOk{{.*}}) [[WITH]] 33*f4a2713aSLionel Sambuc template<int i> TemplateTSANOk()34*f4a2713aSLionel Sambucint TemplateTSANOk() { return i; } 35*f4a2713aSLionel Sambuc 36*f4a2713aSLionel Sambuc // WITHOUT: TemplateNoTSAN{{.*}}) [[NOATTR]] 37*f4a2713aSLionel Sambuc // BL: TemplateNoTSAN{{.*}}) [[NOATTR]] 38*f4a2713aSLionel Sambuc // TSAN: TemplateNoTSAN{{.*}}) [[NOATTR]] 39*f4a2713aSLionel Sambuc template<int i> 40*f4a2713aSLionel Sambuc __attribute__((no_sanitize_thread)) TemplateNoTSAN()41*f4a2713aSLionel Sambucint TemplateNoTSAN() { return i; } 42*f4a2713aSLionel Sambuc 43*f4a2713aSLionel Sambuc int force_instance = TemplateTSANOk<42>() 44*f4a2713aSLionel Sambuc + TemplateNoTSAN<42>(); 45*f4a2713aSLionel Sambuc 46*f4a2713aSLionel Sambuc // Check that __cxx_global_var_init* get the sanitize_thread attribute. 47*f4a2713aSLionel Sambuc int global1 = 0; 48*f4a2713aSLionel Sambuc int global2 = *(int*)((char*)&global1+1); 49*f4a2713aSLionel Sambuc // WITHOUT: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] 50*f4a2713aSLionel Sambuc // BL: @__cxx_global_var_init{{.*}}[[NOATTR_NO_TF:#[0-9]+]] 51*f4a2713aSLionel Sambuc // TSAN: @__cxx_global_var_init{{.*}}[[WITH_NO_TF:#[0-9]+]] 52*f4a2713aSLionel Sambuc 53*f4a2713aSLionel Sambuc // WITHOUT: attributes [[NOATTR]] = { nounwind{{.*}} } 54*f4a2713aSLionel Sambuc // WITHOUT: attributes [[NOATTR_NO_TF]] = { nounwind } 55*f4a2713aSLionel Sambuc 56*f4a2713aSLionel Sambuc // BL: attributes [[NOATTR]] = { nounwind{{.*}} } 57*f4a2713aSLionel Sambuc // BL: attributes [[NOATTR_NO_TF]] = { nounwind{{.*}} } 58*f4a2713aSLionel Sambuc 59*f4a2713aSLionel Sambuc // TSAN: attributes [[NOATTR]] = { nounwind{{.*}} } 60*f4a2713aSLionel Sambuc // TSAN: attributes [[WITH]] = { nounwind sanitize_thread{{.*}} } 61*f4a2713aSLionel Sambuc // TSAN: attributes [[WITH_NO_TF]] = { nounwind sanitize_thread } 62