[PATCH] D11727: Dtor callback emitted when msan attribute not repressed for this function.

Naomi Musgrave nmusgrave at google.com
Mon Aug 3 15:35:49 PDT 2015


nmusgrave updated this revision to Diff 31276.
nmusgrave added a comment.

- modified test to examine default dtor with and without attribute


http://reviews.llvm.org/D11727

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

Index: test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp
@@ -0,0 +1,51 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+// RUN: %clang_cc1 -DATTRIBUTE -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s --check-prefix=CHECK-ATTR
+
+template <class T> class Vector {
+ public:
+  ~Vector() {}
+};
+
+struct No_San {
+  Vector<int> v;
+  No_San() { }
+#ifdef ATTRIBUTE
+  __attribute__((no_sanitize_memory)) ~No_San() = default;
+#else
+  ~No_San() = default;
+#endif
+};
+
+int main() {
+  No_San *ns = new No_San();
+  ns->~No_San();
+  return 0;
+}
+
+// Repressing the sanitization attribute results in no msan
+// instrumentation of the destructor
+// CHECK: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
+// CHECK: call void {{.*}}No_SanD2Ev
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void
+
+// CHECK-ATTR: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
+// CHECK-ATTR: call void {{.*}}No_SanD2Ev
+// CHECK-ATTR-NOT: call void @__sanitizer_dtor_callback
+// CHECK-ATTR: ret void
+
+
+// CHECK: define {{.*}}No_SanD2Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
+// CHECK: call void {{.*}}Vector
+// CHECK: call void @__sanitizer_dtor_callback
+// CHECK: ret void
+
+// CHECK-ATTR: define {{.*}}No_SanD2Ev{{.*}} [[ATTRIBUTE:#[0-9]+]]
+// CHECK-ATTR: call void {{.*}}Vector
+// CHECK-ATTR-NOT: call void @__sanitizer_dtor_callback
+// CHECK-ATTR: ret void
+
+// When attribute is repressed, the destructor does not emit any tail calls
+// CHECK: attributes [[ATTRIBUTE]] = {{.*}} sanitize_memory
+// CHECK-ATTR-NOT: attributes [[ATTRIBUTE]] = {{.*}} sanitize_memory
Index: test/CodeGenCXX/sanitize-dtor-callback.cpp
===================================================================
--- test/CodeGenCXX/sanitize-dtor-callback.cpp
+++ test/CodeGenCXX/sanitize-dtor-callback.cpp
@@ -67,3 +67,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
+      && SanOpts.has(SanitizerKind::Memory))
     EmitDtorSanitizerCallback(*this, Dtor);
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D11727.31276.patch
Type: text/x-patch
Size: 2899 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150803/76590c39/attachment.bin>


More information about the cfe-commits mailing list