nmusgrave created this revision.
nmusgrave added reviewers: eugenis, kcc.
nmusgrave added a subscriber: cfe-commits.

In addition to checking compiler flags, the front-end also examines the 
attributes of the destructor definition to ensure that the SanitizeMemory 
attribute is attached.

http://reviews.llvm.org/D11727

Files:
  lib/CodeGen/CGClass.cpp
  test/CodeGenCXX/sanitize-dtor-callback.cpp

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
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
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);
 }
 
_______________________________________________
cfe-commits mailing list
cfe-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to