From 7db62e8770f58d4db87bb899113e698a95d1327f Mon Sep 17 00:00:00 2001 From: Naomi Musgrave Date: Wed, 12 Aug 2015 22:07:24 +0000 Subject: [PATCH] Revert "Implement poisoning of only class members in dtor, as opposed to also poisoning fields inherited from base classes." This reverts commit 8dbbf3578a9a5d063232b59e558e5fe46e2cd42c. Rolled back due to buildbot failures on 'ninja check-clang'. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@244820 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGClass.cpp | 39 +++--------- test/CodeGenCXX/sanitize-dtor-callback.cpp | 9 +-- .../sanitize-dtor-derived-class.cpp | 62 ------------------- .../CodeGenCXX/sanitize-dtor-fn-attribute.cpp | 9 +-- 4 files changed, 12 insertions(+), 107 deletions(-) delete mode 100644 test/CodeGenCXX/sanitize-dtor-derived-class.cpp diff --git a/lib/CodeGen/CGClass.cpp b/lib/CodeGen/CGClass.cpp index fea72f6818..740cd4ab4e 100644 --- a/lib/CodeGen/CGClass.cpp +++ b/lib/CodeGen/CGClass.cpp @@ -1376,30 +1376,9 @@ static void EmitDtorSanitizerCallback(CodeGenFunction &CGF, const ASTRecordLayout &Layout = CGF.getContext().getASTRecordLayout(Dtor->getParent()); - // Nothing to poison - if(Layout.getFieldCount() == 0) - return; - - // Construct pointer to region to begin poisoning, and calculate poison - // size, so that only members declared in this class are poisoned. - llvm::Value *OffsetPtr; - CharUnits::QuantityType PoisonSize; - ASTContext &Context = CGF.getContext(); - - llvm::ConstantInt *OffsetSizePtr = llvm::ConstantInt::get( - CGF.SizeTy, Context.toCharUnitsFromBits(Layout.getFieldOffset(0)). - getQuantity()); - - OffsetPtr = CGF.Builder.CreateGEP(CGF.Builder.CreateBitCast( - CGF.LoadCXXThis(), CGF.Int8PtrTy), OffsetSizePtr); - - PoisonSize = Layout.getSize().getQuantity() - - Context.toCharUnitsFromBits(Layout.getFieldOffset(0)).getQuantity(); - llvm::Value *Args[] = { - CGF.Builder.CreateBitCast(OffsetPtr, CGF.VoidPtrTy), - llvm::ConstantInt::get(CGF.SizeTy, PoisonSize)}; - + CGF.Builder.CreateBitCast(CGF.LoadCXXThis(), CGF.VoidPtrTy), + llvm::ConstantInt::get(CGF.SizeTy, Layout.getSize().getQuantity())}; llvm::Type *ArgTypes[] = {CGF.VoidPtrTy, CGF.SizeTy}; llvm::FunctionType *FnType = @@ -1407,8 +1386,6 @@ static void EmitDtorSanitizerCallback(CodeGenFunction &CGF, llvm::Value *Fn = CGF.CGM.CreateRuntimeFunction(FnType, "__sanitizer_dtor_callback"); - // Disables tail call elimination, to prevent the current stack frame from - // disappearing from the stack trace. CGF.CurFn->addFnAttr("disable-tail-calls", "true"); CGF.EmitNounwindRuntimeCall(Fn, Args); } @@ -1491,13 +1468,6 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) { // the caller's body. if (getLangOpts().AppleKext) CurFn->addFnAttr(llvm::Attribute::AlwaysInline); - - // Insert memory-poisoning instrumentation, before final clean ups, - // to ensure this class's members are protected from invalid access. - if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor - && SanOpts.has(SanitizerKind::Memory)) - EmitDtorSanitizerCallback(*this, Dtor); - break; } @@ -1507,6 +1477,11 @@ void CodeGenFunction::EmitDestructorBody(FunctionArgList &Args) { // Exit the try if applicable. if (isTryBody) ExitCXXTryStmt(*cast(Body), true); + + // Insert memory-poisoning instrumentation. + if (CGM.getCodeGenOpts().SanitizeMemoryUseAfterDtor + && SanOpts.has(SanitizerKind::Memory)) + EmitDtorSanitizerCallback(*this, Dtor); } void CodeGenFunction::emitImplicitAssignmentOperatorBody(FunctionArgList &Args) { diff --git a/test/CodeGenCXX/sanitize-dtor-callback.cpp b/test/CodeGenCXX/sanitize-dtor-callback.cpp index 078efe88ca..a3ecbcbdd8 100644 --- a/test/CodeGenCXX/sanitize-dtor-callback.cpp +++ b/test/CodeGenCXX/sanitize-dtor-callback.cpp @@ -7,8 +7,7 @@ struct Simple { Simple s; // Simple internal member is poisoned by compiler-generated dtor // CHECK-LABEL: define {{.*}}SimpleD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}SimpleD2Ev +// CHECK: call void @__sanitizer_dtor_callback // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void @@ -18,8 +17,7 @@ struct Inlined { Inlined i; // Simple internal member is poisoned by compiler-generated dtor // CHECK-LABEL: define {{.*}}InlinedD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}InlinedD2Ev +// CHECK: call void @__sanitizer_dtor_callback // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void @@ -46,8 +44,7 @@ Defaulted_Non_Trivial def_non_trivial; // By including a Simple member in the struct, the compiler is // forced to generate a non-trivial destructor. // CHECK-LABEL: define {{.*}}Defaulted_Non_TrivialD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}Defaulted_Non_TrivialD2 +// CHECK: call void @__sanitizer_dtor_callback // CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: ret void diff --git a/test/CodeGenCXX/sanitize-dtor-derived-class.cpp b/test/CodeGenCXX/sanitize-dtor-derived-class.cpp deleted file mode 100644 index 2084d530bc..0000000000 --- a/test/CodeGenCXX/sanitize-dtor-derived-class.cpp +++ /dev/null @@ -1,62 +0,0 @@ -// RUN: %clang_cc1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s -// RUN: %clang_cc1 -O1 -fsanitize=memory -fsanitize-memory-use-after-dtor -disable-llvm-optzns -std=c++11 -triple=x86_64-pc-linux -emit-llvm -o - %s | FileCheck %s - -class Base { - public: - int x; - Base() { - x = 5; - } - virtual ~Base() { - x += 1; - } -}; - -class Derived : public Base { - public: - int y; - Derived() { - y = 10; - } - ~Derived() { - y += 1; - } -}; - -Derived d; - -// CHECK-LABEL: define {{.*}}DerivedD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}DerivedD2Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void - -// CHECK-LABEL: define {{.*}}DerivedD0Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}DerivedD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void - -// CHECK-LABEL: define {{.*}}BaseD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}BaseD2Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void - -// CHECK-LABEL: define {{.*}}BaseD0Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}BaseD1Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void - -// CHECK-LABEL: define {{.*}}BaseD2Ev -// CHECK: call void @__sanitizer_dtor_callback -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void - -// CHECK-LABEL: define {{.*}}DerivedD2Ev -// CHECK: call void @__sanitizer_dtor_callback -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: call void {{.*}}BaseD2Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback -// CHECK: ret void diff --git a/test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp b/test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp index 8d190e09f3..8a9e477cf1 100644 --- a/test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp +++ b/test/CodeGenCXX/sanitize-dtor-fn-attribute.cpp @@ -26,27 +26,22 @@ int main() { // 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: call void {{.*}}No_SanD2Ev -// CHECK-NOT: call void @__sanitizer_dtor_callback +// CHECK: call void @__sanitizer_dtor_callback // CHECK: ret void // CHECK-ATTR: define {{.*}}No_SanD1Ev{{.*}} [[ATTRIBUTE:#[0-9]+]] -// CHECK-ATTR-NOT: call void @__sanitizer_dtor_callback // 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 @__sanitizer_dtor_callback -// CHECK-NOT: call void @__sanitizer_dtor_callback // CHECK: call void {{.*}}Vector -// CHECK-NOT: call void @__sanitizer_dtor_callback +// CHECK: call void @__sanitizer_dtor_callback // CHECK: ret void // CHECK-ATTR: define {{.*}}No_SanD2Ev{{.*}} [[ATTRIBUTE:#[0-9]+]] -// CHECK-ATTR-NOT: call void @__sanitizer_dtor_callback // CHECK-ATTR: call void {{.*}}Vector // CHECK-ATTR-NOT: call void @__sanitizer_dtor_callback // CHECK-ATTR: ret void -- 2.40.0