diff options
author | Naomi Musgrave <nmusgrave@google.com> | 2015-07-30 17:59:46 +0000 |
---|---|---|
committer | Naomi Musgrave <nmusgrave@google.com> | 2015-07-30 17:59:46 +0000 |
commit | 21792b145d1399292bd4a6ea7a835449cfd4e627 (patch) | |
tree | a9b0e25aba6bd477f60453a40180e09cd2731be5 | |
parent | 46951b596870d0e8895c355a8ad3459c54e78fb2 (diff) | |
download | bcm5719-llvm-21792b145d1399292bd4a6ea7a835449cfd4e627.tar.gz bcm5719-llvm-21792b145d1399292bd4a6ea7a835449cfd4e627.zip |
repress tail call optimization when performing use-after-dtor sanitization
Reviewers: eugenis, kcc
Subscribers: cfe-commits
Differential Revision: http://reviews.llvm.org/D11613
llvm-svn: 243668
-rw-r--r-- | clang/lib/CodeGen/CGClass.cpp | 4 | ||||
-rw-r--r-- | clang/test/CodeGenCXX/sanitize-dtor-tail-call.cpp | 20 |
2 files changed, 24 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CGClass.cpp b/clang/lib/CodeGen/CGClass.cpp index ac96afe31b8..a078beb9da1 100644 --- a/clang/lib/CodeGen/CGClass.cpp +++ b/clang/lib/CodeGen/CGClass.cpp @@ -1369,6 +1369,8 @@ static bool CanSkipVTablePointerInitialization(ASTContext &Context, // 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(CodeGenFunction &CGF, 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); } diff --git a/clang/test/CodeGenCXX/sanitize-dtor-tail-call.cpp b/clang/test/CodeGenCXX/sanitize-dtor-tail-call.cpp new file mode 100644 index 00000000000..c82f0746388 --- /dev/null +++ b/clang/test/CodeGenCXX/sanitize-dtor-tail-call.cpp @@ -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 |