1*67e74705SXin Li // Test -fsanitize-memory-use-after-dtor 2*67e74705SXin Li // RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s 3*67e74705SXin Li 4*67e74705SXin Li // The no_sanitize_memory attribute, when applied to a destructor, 5*67e74705SXin Li // represses emission of sanitizing callback 6*67e74705SXin Li 7*67e74705SXin Li template <class T> class Vector { 8*67e74705SXin Li public: 9*67e74705SXin Li int size; ~Vector()10*67e74705SXin Li ~Vector() {} 11*67e74705SXin Li }; 12*67e74705SXin Li 13*67e74705SXin Li struct No_San { 14*67e74705SXin Li Vector<int> v; 15*67e74705SXin Li int x; No_SanNo_San16*67e74705SXin Li No_San() { } 17*67e74705SXin Li __attribute__((no_sanitize_memory)) ~No_San() = default; 18*67e74705SXin Li }; 19*67e74705SXin Li main()20*67e74705SXin Liint main() { 21*67e74705SXin Li No_San *ns = new No_San(); 22*67e74705SXin Li ns->~No_San(); 23*67e74705SXin Li return 0; 24*67e74705SXin Li } 25*67e74705SXin Li 26*67e74705SXin Li // Repressing the sanitization attribute results in no msan 27*67e74705SXin Li // instrumentation of the destructor 28*67e74705SXin Li // CHECK: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]] 29*67e74705SXin Li // CHECK-NOT: call void {{.*}}sanitizer_dtor_callback 30*67e74705SXin Li // CHECK: ret void 31*67e74705SXin Li 32*67e74705SXin Li // CHECK: define {{.*}}No_SanD2Ev{{.*}} [[ATTRIBUTE:#[0-9]+]] 33*67e74705SXin Li // CHECK-NOT: call void {{.*}}sanitizer_dtor_callback 34*67e74705SXin Li // CHECK: call void {{.*}}VectorIiED2Ev 35*67e74705SXin Li // CHECK-NOT: call void {{.*}}sanitizer_dtor_callback 36*67e74705SXin Li // CHECK: ret void 37*67e74705SXin Li 38*67e74705SXin Li // CHECK: define {{.*}}VectorIiED2Ev 39*67e74705SXin Li // CHECK: call void {{.*}}sanitizer_dtor_callback 40*67e74705SXin Li // CHECK: ret void 41*67e74705SXin Li 42*67e74705SXin Li // When attribute is repressed, the destructor does not emit any tail calls 43*67e74705SXin Li // CHECK-NOT: attributes [[ATTRIBUTE]] = {{.*}} sanitize_memory 44