Index: lib/CodeGen/CGClass.cpp =================================================================== --- lib/CodeGen/CGClass.cpp +++ lib/CodeGen/CGClass.cpp @@ -1479,7 +1479,8 @@ ExitCXXTryStmt(*cast<CXXTryStmt>(Body), true); // Insert memory-poisoning instrumentation. - if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor) + if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor + && CurFn->hasFnAttribute(llvm::Attribute::SanitizeMemory)) EmitDtorSanitizerCallback(*this, Dtor); } Index: test/CodeGenCXX/sanitize-dtor-callback.cpp =================================================================== --- test/CodeGenCXX/sanitize-dtor-callback.cpp +++ test/CodeGenCXX/sanitize-dtor-callback.cpp @@ -11,6 +11,20 @@ // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void +struct No_San { + int x; + No_San() { + x = 5; + } + __attribute__((no_sanitize_memory)) ~No_San() {} +}; +No_San ns; +// Repressing the sanitization attribute results in no msan +// instrumentation of the destructor +// CHECK: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]] +// CHECK-NOT: {{^ *}}call void @__sanitizer_dtor_callback +// CHECK: ret void + struct Inlined { inline ~Inlined() {} }; @@ -58,6 +72,10 @@ // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void +// CHECK-LABEL: define {{.*}}No_SanD2Ev +// CHECK-NOT: call void @__sanitizer_dtor_callback +// CHECK: ret void + // CHECK-LABEL: define {{.*}}InlinedD2Ev // CHECK: call void @__sanitizer_dtor_callback // CHECK-NOT: call void @__sanitizer_dtor_callback @@ -67,3 +85,6 @@ // CHECK: call void @__sanitizer_dtor_callback // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void + +// When attribute is repressed, the destructor does not emit any tail calls +// CHECK-NOT: attributes [[ATTRIBUTE]] = {{.*}} sanitize_memory