]> granicus.if.org Git - clang/commitdiff
Module Debugging: Emit the canonical debug info for Objective-C classes
authorAdrian Prantl <aprantl@apple.com>
Wed, 20 Apr 2016 23:59:32 +0000 (23:59 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 20 Apr 2016 23:59:32 +0000 (23:59 +0000)
in the compile unit that contains their implementation even if their
interface is declared in a module.

The private @implementation of an @interface may have additional
hidden ivars so we should not defer to the public version of the
type that is found in the module.

<rdar://problem/25541798>

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@266937 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGDebugInfo.cpp
test/Modules/ExtDebugInfo.m
test/Modules/Inputs/DebugObjC.h
test/Modules/ModuleDebugInfo.m

index 0c61496162a5320cedbcdcb3a6acc64b05405724..9e8abdc2f5c3aca7452eb66908ac1c3659c546f2 100644 (file)
@@ -1664,8 +1664,11 @@ llvm::DIType *CGDebugInfo::CreateType(const ObjCInterfaceType *Ty,
   if (!ID)
     return nullptr;
 
-  // Return a forward declaration if this type was imported from a clang module.
-  if (DebugTypeExtRefs && ID->isFromASTFile() && ID->getDefinition())
+  // Return a forward declaration if this type was imported from a clang module,
+  // and this is not the compile unit with the implementation of the type (which
+  // may contain hidden ivars).
+  if (DebugTypeExtRefs && ID->isFromASTFile() && ID->getDefinition() &&
+      !ID->getImplementation())
     return DBuilder.createForwardDecl(llvm::dwarf::DW_TAG_structure_type,
                                       ID->getName(),
                                       getDeclContextDescriptor(ID), Unit, 0);
index 3b907ac729ad947d808066420a3afedf668d9f77..71ca853fb7d95089499177b93530b8a83aa76df9 100644 (file)
 @import DebugObjC;
 #endif
 
+@implementation ObjCClassWithPrivateIVars {
+  int hidden_ivar;
+}
+@end
+
 TypedefUnion tdu;
 TypedefEnum tde;
 TypedefStruct tds;
@@ -29,9 +34,16 @@ int foo(ObjCClass *c) {
   return [c property];
 }
 
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClassWithPrivateIVars",
+// CHECK-SAME:             flags: DIFlagObjcClassComplete
+
+// CHECK: ![[MOD:.*]] = !DIModule(scope: null, name: "DebugObjC
+
+// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "hidden_ivar",
+// CHECK-SAME:           flags: DIFlagPrivate)
+
 // CHECK: !DIGlobalVariable(name: "GlobalUnion",
 // CHECK-SAME:              type: ![[GLOBAL_UNION:[0-9]+]]
-// CHECK: ![[MOD:.*]] = !DIModule(scope: null, name: "DebugObjC
 // CHECK: ![[GLOBAL_UNION]] = distinct !DICompositeType(tag: DW_TAG_union_type,
 // CHECK-SAME:                elements: !{{[0-9]+}})
 
index eb7a9f9da9fe12dfd9a98eedca59637540d418b7..af1cd981ce1c2594da258adfab2c92ebe98e32e5 100644 (file)
@@ -1,3 +1,4 @@
+// -*- ObjC -*-
 @class FwdDecl;
 
 @interface ObjCClass {
@@ -9,6 +10,11 @@
 @property int property;
 @end
 
+@interface ObjCClassWithPrivateIVars {
+  int public_ivar;
+}
+@end
+
 @interface ObjCClass (Category)
 - categoryMethod;
 @end
index 360db919ab9cb36b8bda55f888d46989415960d5..ce35c7c8361ffa19b53a25298e3d330210a52ab6 100644 (file)
 // CHECK: ![[TD_ENUM:.*]] = !DICompositeType(tag: DW_TAG_enumeration_type,
 // CHECK-NOT:              name:
 // CHECK-SAME:             elements:
-// CHECK-SAME:             )
 
 // CHECK: !DISubprogram(name: "+[ObjCClass classMethod]",
 // CHECK-SAME:          scope: ![[MODULE]],
 
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClass",
 // CHECK-SAME:             scope: ![[MODULE]],
+// CHECK-SAME:             elements
 
 // The forward declaration should not be in the module scope.
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "OpaqueData", file
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDecl",
 // CHECK-SAME:             scope: ![[MODULE]],
 
+// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "ObjCClassWithPrivateIVars",
+// CHECK-SAME:             scope: ![[MODULE]],
+// CHECK-SAME:             elements
+
 // CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "FwdDeclared"
 // CHECK-SAME:             elements:
 
 // CHECK: ![[TD_UNION:.*]] = distinct !DICompositeType(tag: DW_TAG_union_type,
 // CHECK-NOT:              name:
 // CHECK-SAME:             elements:
-// CHECK-SAME:             )
 
 // CHECK: !DIDerivedType(tag: DW_TAG_typedef, name: "TypedefUnion",
 // CHECK-SAME:           baseType: ![[TD_UNION]])