]> granicus.if.org Git - clang/commitdiff
ObjC debug info: Substitute the class type for methods that return
authorAdrian Prantl <aprantl@apple.com>
Fri, 10 May 2013 21:08:31 +0000 (21:08 +0000)
committerAdrian Prantl <aprantl@apple.com>
Fri, 10 May 2013 21:08:31 +0000 (21:08 +0000)
a related type (e.g., if they use the instancetype keyword).

rdar://problem/13359718

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

lib/CodeGen/CGDebugInfo.cpp
test/CodeGenObjC/debug-info-instancetype.m [new file with mode: 0644]

index 6678aa7198b121c41d4a9844be9211543fce3d6a..d9ab0902e3551e653dc7179c7e1d5dc52d4f3226 100644 (file)
@@ -2154,7 +2154,10 @@ llvm::DIType CGDebugInfo::getOrCreateFunctionType(const Decl *D,
     SmallVector<llvm::Value *, 16> Elts;
 
     // First element is always return type. For 'void' functions it is NULL.
-    Elts.push_back(getOrCreateType(OMethod->getResultType(), F));
+    QualType ResultTy = OMethod->hasRelatedResultType()
+      ? QualType(OMethod->getClassInterface()->getTypeForDecl(), 0)
+      : OMethod->getResultType();
+    Elts.push_back(getOrCreateType(ResultTy, F));
     // "self" pointer is always first argument.
     QualType SelfDeclTy = OMethod->getSelfDecl()->getType();
     llvm::DIType SelfTy = getOrCreateType(SelfDeclTy, F);
diff --git a/test/CodeGenObjC/debug-info-instancetype.m b/test/CodeGenObjC/debug-info-instancetype.m
new file mode 100644 (file)
index 0000000..7275b63
--- /dev/null
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -emit-llvm -g -triple x86_64-apple-darwin10 %s -o - | FileCheck %s
+// rdar://problem/13359718
+// Substitute the actual type for a method returning instancetype.
+@interface NSObject
++ (id)alloc;
+- (id)init;
+- (id)retain;
+@end
+
+@interface Foo : NSObject
++ (instancetype)defaultFoo;
+@end
+
+@implementation Foo
++(instancetype)defaultFoo {return 0;}
+// CHECK: ![[FOO:[0-9]+]] = metadata {{.*}}; [ DW_TAG_structure_type ] [Foo]
+// CHECK: metadata !"+[Foo defaultFoo]", metadata !"", i32 [[@LINE-2]], metadata ![[TYPE:[0-9]+]]
+// CHECK: ![[TYPE]] = {{.*}} metadata ![[RESULT:[0-9]+]], i32 {{.*}}, i32 {{.*}}} ; [ DW_TAG_subroutine_type ]
+// CHECK: ![[RESULT]] = metadata !{metadata ![[FOO]],
+@end
+
+
+int main (int argc, const char *argv[])
+{
+  Foo *foo = [Foo defaultFoo];
+  return 0;
+}