From: David Blaikie Date: Tue, 14 Oct 2014 16:43:46 +0000 (+0000) Subject: DebugInfo: Don't leak location information from one function into the prologue of... X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=89fe0a613086e1adcffc6d0bacac40ec671aae90;p=clang DebugInfo: Don't leak location information from one function into the prologue of the next function. CodeGenFunction objects aren't really designed to be reused for more than one function, and doing so can leak debug info location information from one function into the prologue of the next. Add an assertion in to catch reuses of CodeGenFunction, which surprisingly only caught the ObjC atomic getter/setter cases. Fix those and add a test to demonstrate the issue. The test is a bit slim, because we're just testing for the absence of a debug location on the prologue instructions, which by itself probably wouldn't be the end of the world - but the particular debug location that was ending up there was for the previous function's last instruction. This produced debug info for another function within this function, which is something I'm trying to remove all cases of as its a substantial source of bugs, especially around inlining (see r219215). git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@219690 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/CodeGen/CGObjC.cpp b/lib/CodeGen/CGObjC.cpp index b0c7cc9c7e..164df93e31 100644 --- a/lib/CodeGen/CGObjC.cpp +++ b/lib/CodeGen/CGObjC.cpp @@ -756,8 +756,8 @@ PropertyImplStrategy::PropertyImplStrategy(CodeGenModule &CGM, /// is illegal within a category. void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID) { - llvm::Constant *AtomicHelperFn = - GenerateObjCAtomicGetterCopyHelperFunction(PID); + llvm::Constant *AtomicHelperFn = + CodeGenFunction(CGM).GenerateObjCAtomicGetterCopyHelperFunction(PID); const ObjCPropertyDecl *PD = PID->getPropertyDecl(); ObjCMethodDecl *OMD = PD->getGetterMethodDecl(); assert(OMD && "Invalid call to generate getter (empty method)"); @@ -1285,8 +1285,8 @@ CodeGenFunction::generateObjCSetterBody(const ObjCImplementationDecl *classImpl, /// is illegal within a category. void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyImplDecl *PID) { - llvm::Constant *AtomicHelperFn = - GenerateObjCAtomicSetterCopyHelperFunction(PID); + llvm::Constant *AtomicHelperFn = + CodeGenFunction(CGM).GenerateObjCAtomicSetterCopyHelperFunction(PID); const ObjCPropertyDecl *PD = PID->getPropertyDecl(); ObjCMethodDecl *OMD = PD->getSetterMethodDecl(); assert(OMD && "Invalid call to generate setter (empty method)"); diff --git a/lib/CodeGen/CodeGenFunction.cpp b/lib/CodeGen/CodeGenFunction.cpp index 9f35918538..354939a23e 100644 --- a/lib/CodeGen/CodeGenFunction.cpp +++ b/lib/CodeGen/CodeGenFunction.cpp @@ -36,7 +36,7 @@ using namespace CodeGen; CodeGenFunction::CodeGenFunction(CodeGenModule &cgm, bool suppressNewContext) : CodeGenTypeCache(cgm), CGM(cgm), Target(cgm.getTarget()), Builder(cgm.getModule().getContext(), llvm::ConstantFolder(), - CGBuilderInserterTy(this)), + CGBuilderInserterTy(this)), CurFn(nullptr), CapturedStmtInfo(nullptr), SanOpts(&CGM.getLangOpts().Sanitize), IsSanitizerScope(false), CurFuncIsThunk(false), AutoreleaseResult(false), SawAsmBlock(false), BlockInfo(nullptr), BlockPointer(nullptr), @@ -565,6 +565,9 @@ void CodeGenFunction::StartFunction(GlobalDecl GD, const FunctionArgList &Args, SourceLocation Loc, SourceLocation StartLoc) { + assert(!CurFn && + "Do not use a CodeGenFunction object for more than one function"); + const Decl *D = GD.getDecl(); DidCallStackSave = false; diff --git a/test/CodeGenObjCXX/property-objects.mm b/test/CodeGenObjCXX/property-objects.mm index c79c280edd..73ed21dcb7 100644 --- a/test/CodeGenObjCXX/property-objects.mm +++ b/test/CodeGenObjCXX/property-objects.mm @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -o - | FileCheck %s +// RUN: %clang_cc1 %s -triple=x86_64-apple-darwin10 -emit-llvm -g -o - | FileCheck %s class S { public: @@ -35,6 +35,11 @@ struct CGRect { // CHECK: call dereferenceable({{[0-9]+}}) %class.S* @_ZN1SaSERKS_ // CHECK-NEXT: ret void +// Don't attach debug locations to the prologue instructions. These were +// leaking over from the previous function emission by accident. +// CHECK: define internal void @"\01-[I setBounds:]" +// CHECK-NOT: !dbg +// CHECK: call void @llvm.dbg.declare - (void)setFrame:(CGRect)frameRect {} - (CGRect)frame {return bounds;}