]> granicus.if.org Git - clang/commitdiff
ObjC Debug Info: Emit the names of accessors whenever they diverge from
authorAdrian Prantl <aprantl@apple.com>
Fri, 7 Jun 2013 01:10:45 +0000 (01:10 +0000)
committerAdrian Prantl <aprantl@apple.com>
Fri, 7 Jun 2013 01:10:45 +0000 (01:10 +0000)
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
test/CodeGenObjC/debug-info-property-accessors.m [new file with mode: 0644]

index 86b5075ac22d2d8be8009356b0a9ba95cc77abd8..f51831ca2bcf4953490108be7e7e3caa0d4d98cc 100644 (file)
@@ -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 (file)
index 0000000..4c7b984
--- /dev/null
@@ -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 <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;
+}