From 5ae17a17709acaf005e0c22839ef83c5e21f7db5 Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Fri, 7 Jun 2013 01:10:45 +0000 Subject: [PATCH] ObjC Debug Info: Emit the names of accessors whenever they diverge from the default names, not just when the isImplicit flag is set. rdar://problem/14035789 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@183474 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/CGDebugInfo.cpp | 38 +++++++++++-- .../debug-info-property-accessors.m | 56 +++++++++++++++++++ 2 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 test/CodeGenObjC/debug-info-property-accessors.m diff --git a/lib/CodeGen/CGDebugInfo.cpp b/lib/CodeGen/CGDebugInfo.cpp index 86b5075ac2..f51831ca2b 100644 --- a/lib/CodeGen/CGDebugInfo.cpp +++ b/lib/CodeGen/CGDebugInfo.cpp @@ -1451,6 +1451,36 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCObjectType *Ty, return getOrCreateType(Ty->getBaseType(), Unit); } + +/// \return true if Getter has the default name for the property PD. +static bool hasDefaultGetterName(const ObjCPropertyDecl *PD, + const ObjCMethodDecl *Getter) { + assert(PD); + if (!Getter) + return true; + + assert(Getter->getDeclName().isObjCZeroArgSelector()); + return PD->getName() == + Getter->getDeclName().getObjCSelector().getNameForSlot(0); +} + +/// \return true if Setter has the default name for the property PD. +static bool hasDefaultSetterName(const ObjCPropertyDecl *PD, + const ObjCMethodDecl *Setter) { + assert(PD); + if (!Setter) + return true; + + assert(Setter->getDeclName().isObjCOneArgSelector()); + // Construct a setter name like SelectorTable::constructSetterName() + // does, but without entering it into the table. + SmallString<100> DefaultName("set"); + DefaultName += PD->getName(); + DefaultName[3] = toUppercase(DefaultName[3]); + return DefaultName == + Setter->getDeclName().getObjCSelector().getNameForSlot(0); +} + /// CreateType - get objective-c interface type. llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, llvm::DIFile Unit) { @@ -1524,9 +1554,9 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, llvm::MDNode *PropertyNode = DBuilder.createObjCProperty(PD->getName(), PUnit, PLine, - (Getter && Getter->isImplicit()) ? "" : + hasDefaultGetterName(PD, Getter) ? "" : getSelectorName(PD->getGetterName()), - (Setter && Setter->isImplicit()) ? "" : + hasDefaultSetterName(PD, Setter) ? "" : getSelectorName(PD->getSetterName()), PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit)); @@ -1598,9 +1628,9 @@ llvm::DIType CGDebugInfo::CreateType(const ObjCInterfaceType *Ty, PropertyNode = DBuilder.createObjCProperty(PD->getName(), PUnit, PLine, - (Getter && Getter->isImplicit()) ? "" : + hasDefaultGetterName(PD, Getter) ? "" : getSelectorName(PD->getGetterName()), - (Setter && Setter->isImplicit()) ? "" : + hasDefaultSetterName(PD, Setter) ? "" : getSelectorName(PD->getSetterName()), PD->getPropertyAttributes(), getOrCreateType(PD->getType(), PUnit)); diff --git a/test/CodeGenObjC/debug-info-property-accessors.m b/test/CodeGenObjC/debug-info-property-accessors.m new file mode 100644 index 0000000000..4c7b98466a --- /dev/null +++ b/test/CodeGenObjC/debug-info-property-accessors.m @@ -0,0 +1,56 @@ +// RUN: %clang_cc1 -emit-llvm -x objective-c -g -triple x86_64-apple-macosx10.8.0 %s -o - | FileCheck %s +// +// rdar://problem/14035789 +// +// Ensure we emit the names of explicit/renamed accessors even if they +// are defined later in the implementation section. +// +// CHECK: metadata !{i32 {{.*}}, metadata !"blah", {{.*}} metadata !"isBlah", metadata !"", {{.*}}} ; [ DW_TAG_APPLE_property ] [blah] + +@class NSString; +extern void NSLog(NSString *format, ...); +typedef signed char BOOL; + +#define YES ((BOOL)1) +#define NO ((BOOL)0) + +typedef unsigned int NSUInteger; + +@protocol NSObject +@end + +@interface NSObject +- (id)init; ++ (id)alloc; +@end + +@interface Bar : NSObject +@property int normal_property; +@property (getter=isBlah, setter=setBlah:) BOOL blah; +@end + +@implementation Bar +@synthesize normal_property; + +- (BOOL) isBlah +{ + return YES; +} +- (void) setBlah: (BOOL) newBlah +{ + NSLog (@"Speak up, I didn't catch that."); +} +@end + +int +main () +{ + Bar *my_bar = [[Bar alloc] init]; + + if (my_bar.blah) + NSLog (@"It was true!!!"); + + my_bar.blah = NO; + + return 0; +} -- 2.40.0