From e7ce54074f618cc4b38fae2a05c7a28c7bf94c46 Mon Sep 17 00:00:00 2001 From: Devang Patel Date: Thu, 19 May 2011 23:37:41 +0000 Subject: [PATCH] Fix location of setter/getter synthesized for a property. llvm-svn: 131701 --- clang/lib/CodeGen/CGObjC.cpp | 15 ++++++++------- clang/lib/CodeGen/CodeGenFunction.h | 3 ++- clang/test/CodeGenObjC/debug-property-synth.m | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 clang/test/CodeGenObjC/debug-property-synth.m diff --git a/clang/lib/CodeGen/CGObjC.cpp b/clang/lib/CodeGen/CGObjC.cpp index ee0ee7b94109..28e7e4288578 100644 --- a/clang/lib/CodeGen/CGObjC.cpp +++ b/clang/lib/CodeGen/CGObjC.cpp @@ -118,7 +118,8 @@ RValue CodeGenFunction::EmitObjCMessageExpr(const ObjCMessageExpr *E, /// the LLVM function and sets the other context used by /// CodeGenFunction. void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, - const ObjCContainerDecl *CD) { + const ObjCContainerDecl *CD, + SourceLocation StartLoc) { FunctionArgList args; // Check if we should generate debug info for this method. if (CGM.getModuleDebugInfo() && !OMD->hasAttr()) @@ -138,7 +139,7 @@ void CodeGenFunction::StartObjCMethod(const ObjCMethodDecl *OMD, CurGD = OMD; - StartFunction(OMD, OMD->getResultType(), Fn, FI, args, OMD->getLocStart()); + StartFunction(OMD, OMD->getResultType(), Fn, FI, args, StartLoc); } void CodeGenFunction::GenerateObjCGetterBody(ObjCIvarDecl *Ivar, @@ -177,7 +178,7 @@ void CodeGenFunction::GenerateObjCGetterBody(ObjCIvarDecl *Ivar, /// Generate an Objective-C method. An Objective-C method is a C function with /// its pointer, name, and types registered in the class struture. void CodeGenFunction::GenerateObjCMethod(const ObjCMethodDecl *OMD) { - StartObjCMethod(OMD, OMD->getClassInterface()); + StartObjCMethod(OMD, OMD->getClassInterface(), OMD->getLocStart()); EmitStmt(OMD->getBody()); FinishFunction(OMD->getBodyRBrace()); } @@ -197,7 +198,7 @@ void CodeGenFunction::GenerateObjCGetter(ObjCImplementationDecl *IMP, !(PD->getPropertyAttributes() & ObjCPropertyDecl::OBJC_PR_nonatomic); ObjCMethodDecl *OMD = PD->getGetterMethodDecl(); assert(OMD && "Invalid call to generate getter (empty method)"); - StartObjCMethod(OMD, IMP->getClassInterface()); + StartObjCMethod(OMD, IMP->getClassInterface(), PID->getLocStart()); // Determine if we should use an objc_getProperty call for // this. Non-atomic properties are directly evaluated. @@ -396,7 +397,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP, const ObjCPropertyDecl *PD = PID->getPropertyDecl(); ObjCMethodDecl *OMD = PD->getSetterMethodDecl(); assert(OMD && "Invalid call to generate setter (empty method)"); - StartObjCMethod(OMD, IMP->getClassInterface()); + StartObjCMethod(OMD, IMP->getClassInterface(), PID->getLocStart()); const llvm::Triple &Triple = getContext().Target.getTriple(); QualType IVART = Ivar->getType(); bool IsCopy = PD->getSetterKind() == ObjCPropertyDecl::Copy; @@ -494,7 +495,7 @@ void CodeGenFunction::GenerateObjCSetter(ObjCImplementationDecl *IMP, } else { // FIXME: Find a clean way to avoid AST node creation. - SourceLocation Loc = PD->getLocation(); + SourceLocation Loc = PID->getLocStart(); ValueDecl *Self = OMD->getSelfDecl(); ObjCIvarDecl *Ivar = PID->getPropertyIvarDecl(); DeclRefExpr Base(Self, Self->getType(), VK_RValue, Loc); @@ -616,7 +617,7 @@ void CodeGenFunction::GenerateObjCCtorDtorMethod(ObjCImplementationDecl *IMP, ObjCMethodDecl *MD, bool ctor) { MD->createImplicitParams(CGM.getContext(), IMP->getClassInterface()); - StartObjCMethod(MD, IMP->getClassInterface()); + StartObjCMethod(MD, IMP->getClassInterface(), MD->getLocStart()); // Emit .cxx_construct. if (ctor) { diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h index 28f5629554dd..9aa7903ab79c 100644 --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -1076,7 +1076,8 @@ public: void GenerateObjCMethod(const ObjCMethodDecl *OMD); void StartObjCMethod(const ObjCMethodDecl *MD, - const ObjCContainerDecl *CD); + const ObjCContainerDecl *CD, + SourceLocation StartLoc); /// GenerateObjCGetter - Synthesize an Objective-C property getter function. void GenerateObjCGetter(ObjCImplementationDecl *IMP, diff --git a/clang/test/CodeGenObjC/debug-property-synth.m b/clang/test/CodeGenObjC/debug-property-synth.m new file mode 100644 index 000000000000..05852b7e2925 --- /dev/null +++ b/clang/test/CodeGenObjC/debug-property-synth.m @@ -0,0 +1,19 @@ +// RUN: %clang_cc1 -masm-verbose -S -g %s -o - | FileCheck %s +// Radar 9468526 +@interface I { + int _p1; +} +@property int p1; +@end + +@implementation I +@synthesize p1 = _p1; +@end + +int main() { + I *myi; + myi.p1 = 2; + return 0; +} + +// CHECK: .loc 2 10 0