r243668 - repress tail call optimization when performing use-after-dtor sanitization

Naomi Musgrave nmusgrave at google.com
Thu Jul 30 10:59:47 PDT 2015


Author: nmusgrave
Date: Thu Jul 30 12:59:46 2015
New Revision: 243668

URL: http://llvm.org/viewvc/llvm-project?rev=243668&view=rev
Log:
repress tail call optimization when performing use-after-dtor sanitization

Reviewers: eugenis, kcc

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D11613

Added:
    cfe/trunk/test/CodeGenCXX/sanitize-dtor-tail-call.cpp
Modified:
    cfe/trunk/lib/CodeGen/CGClass.cpp

Modified: cfe/trunk/lib/CodeGen/CGClass.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGClass.cpp?rev=243668&r1=243667&r2=243668&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGClass.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGClass.cpp Thu Jul 30 12:59:46 2015
@@ -1369,6 +1369,8 @@ static bool CanSkipVTablePointerInitiali
 
 // Generates function call for handling object poisoning, passing in
 // references to 'this' and its size as arguments.
+// Disables tail call elimination, to save emitted callback from
+// being optimized away.
 static void EmitDtorSanitizerCallback(CodeGenFunction &CGF,
                                       const CXXDestructorDecl *Dtor) {
   const ASTRecordLayout &Layout =
@@ -1383,6 +1385,8 @@ static void EmitDtorSanitizerCallback(Co
       llvm::FunctionType::get(CGF.VoidTy, ArgTypes, false);
   llvm::Value *Fn =
       CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback");
+
+  CGF.CurFn->addFnAttr("disable-tail-calls", "true");
   CGF.EmitNounwindRuntimeCall(Fn, Args);
 }
 

Added: cfe/trunk/test/CodeGenCXX/sanitize-dtor-tail-call.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/sanitize-dtor-tail-call.cpp?rev=243668&view=auto
==============================================================================
--- cfe/trunk/test/CodeGenCXX/sanitize-dtor-tail-call.cpp (added)
+++ cfe/trunk/test/CodeGenCXX/sanitize-dtor-tail-call.cpp Thu Jul 30 12:59:46 2015
@@ -0,0 +1,20 @@
+// Test -fsanitize-memory-use-after-dtor
+// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s
+
+struct Simple {
+  int x_;
+  Simple() {
+    x_ = 5;
+  }
+  ~Simple() {
+    x_ += 1;
+  }
+};
+
+Simple s;
+// Simple internal member is poisoned by compiler-generated dtor
+// CHECK-LABEL: define {{.*}}SimpleD2Ev
+// CHECK: {{\s*}}call void @__sanitizer_dtor_callback
+// CHECK-NOT: {{\s*}}call void @__sanitizer_dtor_callback
+// CHECK-NOT: {{\s*}}tail call void @__sanitizer_dtor_callback
+// CHECK: ret void





More information about the cfe-commits mailing list