Debug info: Emit the correct type for the __FuncPtr field in a block
authorAdrian Prantl <aprantl@apple.com>
Wed, 5 Nov 2014 01:01:30 +0000 (01:01 +0000)
committerAdrian Prantl <aprantl@apple.com>
Wed, 5 Nov 2014 01:01:30 +0000 (01:01 +0000)
descriptor.

rdar://problem/15984431

llvm-svn: 221326

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

index 05df170..ea8002a 100644 (file)
@@ -714,7 +714,7 @@ llvm::DIType CGDebugInfo::CreateType(const BlockPointerType *Ty,
   FType = CGM.getContext().IntTy;
   EltTys.push_back(CreateMemberType(Unit, FType, "__flags", &FieldOffset));
   EltTys.push_back(CreateMemberType(Unit, FType, "__reserved", &FieldOffset));
-  FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
+  FType = CGM.getContext().getPointerType(Ty->getPointeeType());
   EltTys.push_back(CreateMemberType(Unit, FType, "__FuncPtr", &FieldOffset));
 
   FType = CGM.getContext().getPointerType(CGM.getContext().VoidTy);
@@ -2953,7 +2953,9 @@ void CGDebugInfo::EmitDeclareOfBlockLiteralArgVariable(const CGBlockInfo &block,
   fields.push_back(createFieldType("__reserved", C.IntTy, 0, loc, AS_public,
                                    blockLayout->getElementOffsetInBits(2),
                                    tunit, tunit));
-  fields.push_back(createFieldType("__FuncPtr", C.VoidPtrTy, 0, loc, AS_public,
+  auto *FnTy = block.getBlockExpr()->getFunctionType();
+  auto FnPtrType = CGM.getContext().getPointerType(FnTy->desugar());
+  fields.push_back(createFieldType("__FuncPtr", FnPtrType, 0, loc, AS_public,
                                    blockLayout->getElementOffsetInBits(3),
                                    tunit, tunit));
   fields.push_back(createFieldType(
diff --git a/clang/test/CodeGenObjC/debug-info-block-type.m b/clang/test/CodeGenObjC/debug-info-block-type.m
new file mode 100644 (file)
index 0000000..e50163e
--- /dev/null
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -fblocks -g  -triple x86_64-apple-darwin14 -x objective-c < %s -o - | FileCheck %s
+#define nil ((void*) 0)
+typedef signed char BOOL;
+// CHECK: ![[BOOL:[0-9]+]] = {{.*}} [ DW_TAG_typedef ] [BOOL] [line [[@LINE-1]]
+// CHECK: ![[ID:[0-9]+]] = {{.*}} [ DW_TAG_typedef ] [id]
+
+typedef BOOL (^SomeKindOfPredicate)(id obj);
+// CHECK: metadata ![[PTR:[0-9]+]]} ; [ DW_TAG_member ] [__FuncPtr]
+// CHECK: ![[PTR]] = {{.*}}, metadata ![[FNTYPE:[0-9]+]]} ; [ DW_TAG_pointer_type ]
+// CHECK: ![[FNTYPE]] = {{.*}} metadata ![[ARGS:[0-9]+]]{{.*}} ; [ DW_TAG_subroutine_type ]
+// CHECK: ![[ARGS]] = metadata !{metadata ![[BOOL]], metadata ![[ID]]}
+
+int main()
+{
+  SomeKindOfPredicate p = ^BOOL(id obj) { return obj != nil; };
+  // CHECK: metadata ![[PTR]]} ; [ DW_TAG_member ] [__FuncPtr] [line [[@LINE-1]], size 64, align 64, offset 128]
+  return p(nil);
+}