ahatanak created this revision.
ahatanak added reviewers: rjmccall, aprantl, vsk.
ahatanak added a project: clang.
ahatanak requested review of this revision.

These fake functions were causing clang to crash when 
https://reviews.llvm.org/D98799 made some changes.

The line number information is no longer emitted for the `__Block_byref_object` 
helper functions (see clang/test/CodeGenCXX/debug-info-blocks.cpp), but I think 
that's okay since the line numbers were incorrect when the helper functions 
were shared among multiple `__block` variables. For example, the line number 
for `__Block_byref_object_copy_` and `__Block_byref_object_dispose_` was the 
line number for `__block id b` in `func0`, which was incorrect if the helper 
functions were called when `func1` was called.

  void (^gb)();
  
  int func0() {
    __block id b;
    gb = ^{ (void)b; };
    return 0;
  }
  
  int func1() {
    __block id b;
    gb = ^{ (void)b; };
    return 0;
  }


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104082

Files:
  clang/lib/CodeGen/CGBlocks.cpp
  clang/test/CodeGenCXX/debug-info-blocks.cpp
  clang/test/CodeGenObjC/debug-info-block-helper.m
  clang/test/CodeGenObjC/debug-info-blocks.m

Index: clang/test/CodeGenObjC/debug-info-blocks.m
===================================================================
--- clang/test/CodeGenObjC/debug-info-blocks.m
+++ clang/test/CodeGenObjC/debug-info-blocks.m
@@ -25,9 +25,9 @@
 // CHECK: ret {{.*}}, !dbg ![[DESTROY_LINE]]
 
 // CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
-// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_
+// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(linkageName: "__copy_helper_block_
 // CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
-// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_
+// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(linkageName: "__destroy_helper_block_
 typedef unsigned int NSUInteger;
 
 @protocol NSObject
Index: clang/test/CodeGenObjC/debug-info-block-helper.m
===================================================================
--- clang/test/CodeGenObjC/debug-info-block-helper.m
+++ clang/test/CodeGenObjC/debug-info-block-helper.m
@@ -2,7 +2,7 @@
 // RUN: %clang_cc1 -emit-llvm -fblocks -debug-info-kind=limited -triple x86_64-apple-darwin10 -fobjc-runtime=macosx-fragile-10.5 %s -o - | FileCheck %s
 extern void foo(void(^)(void));
 
-// CHECK: !DISubprogram(name: "__destroy_helper_block_8_32o40r48r"
+// CHECK: !DISubprogram(linkageName: "__destroy_helper_block_8_32o40r48r"
 
 @interface NSObject {
   struct objc_object *isa;
Index: clang/test/CodeGenCXX/debug-info-blocks.cpp
===================================================================
--- clang/test/CodeGenCXX/debug-info-blocks.cpp
+++ clang/test/CodeGenCXX/debug-info-blocks.cpp
@@ -12,9 +12,7 @@
   ^{ (void)a; };
 }
 
-// CHECK: !DISubprogram(name: "__Block_byref_object_copy_",
-// CHECK-SAME:          line: 11,
+// CHECK: !DISubprogram(linkageName: "__Block_byref_object_copy_",
 // CHECK-SAME:          DISPFlagLocalToUnit | DISPFlagDefinition
-// CHECK: !DISubprogram(name: "__Block_byref_object_dispose_",
-// CHECK-SAME:          line: 11,
+// CHECK: !DISubprogram(linkageName: "__Block_byref_object_dispose_",
 // CHECK-SAME:          DISPFlagLocalToUnit | DISPFlagDefinition
Index: clang/lib/CodeGen/CGBlocks.cpp
===================================================================
--- clang/lib/CodeGen/CGBlocks.cpp
+++ clang/lib/CodeGen/CGBlocks.cpp
@@ -1948,21 +1948,14 @@
   if (CGM.supportsCOMDAT())
     Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = &C.Idents.get(FuncName);
-
   SmallVector<QualType, 2> ArgTys;
   ArgTys.push_back(C.VoidPtrTy);
   ArgTys.push_back(C.VoidPtrTy);
-  QualType FunctionTy = C.getFunctionType(ReturnTy, ArgTys, {});
 
-  FunctionDecl *FD = FunctionDecl::Create(
-      C, C.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
-      FunctionTy, nullptr, SC_Static, false, false);
   setBlockHelperAttributesVisibility(blockInfo.CapturesNonExternalType, Fn, FI,
                                      CGM);
   // This is necessary to avoid inheriting the previous line number.
-  FD->setImplicit();
-  StartFunction(FD, ReturnTy, Fn, FI, args);
+  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
 
   llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
@@ -2143,21 +2136,13 @@
   if (CGM.supportsCOMDAT())
     Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = &C.Idents.get(FuncName);
-
   SmallVector<QualType, 1> ArgTys;
   ArgTys.push_back(C.VoidPtrTy);
-  QualType FunctionTy = C.getFunctionType(ReturnTy, ArgTys, {});
-
-  FunctionDecl *FD = FunctionDecl::Create(
-      C, C.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
-      FunctionTy, nullptr, SC_Static, false, false);
 
   setBlockHelperAttributesVisibility(blockInfo.CapturesNonExternalType, Fn, FI,
                                      CGM);
   // This is necessary to avoid inheriting the previous line number.
-  FD->setImplicit();
-  StartFunction(FD, ReturnTy, Fn, FI, args);
+  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
   markAsIgnoreThreadCheckingAtRuntime(Fn);
 
   auto AL = ApplyDebugLocation::CreateArtificial(*this);
@@ -2395,21 +2380,13 @@
     llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
                            "__Block_byref_object_copy_", &CGF.CGM.getModule());
 
-  IdentifierInfo *II
-    = &Context.Idents.get("__Block_byref_object_copy_");
-
   SmallVector<QualType, 2> ArgTys;
   ArgTys.push_back(Context.VoidPtrTy);
   ArgTys.push_back(Context.VoidPtrTy);
-  QualType FunctionTy = Context.getFunctionType(ReturnTy, ArgTys, {});
-
-  FunctionDecl *FD = FunctionDecl::Create(
-      Context, Context.getTranslationUnitDecl(), SourceLocation(),
-      SourceLocation(), II, FunctionTy, nullptr, SC_Static, false, false);
 
   CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
 
-  CGF.StartFunction(FD, ReturnTy, Fn, FI, args);
+  CGF.StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
 
   if (generator.needsCopy()) {
     llvm::Type *byrefPtrType = byrefInfo.Type->getPointerTo(0);
@@ -2471,20 +2448,12 @@
                            "__Block_byref_object_dispose_",
                            &CGF.CGM.getModule());
 
-  IdentifierInfo *II
-    = &Context.Idents.get("__Block_byref_object_dispose_");
-
   SmallVector<QualType, 1> ArgTys;
   ArgTys.push_back(Context.VoidPtrTy);
-  QualType FunctionTy = Context.getFunctionType(R, ArgTys, {});
-
-  FunctionDecl *FD = FunctionDecl::Create(
-      Context, Context.getTranslationUnitDecl(), SourceLocation(),
-      SourceLocation(), II, FunctionTy, nullptr, SC_Static, false, false);
 
   CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
 
-  CGF.StartFunction(FD, R, Fn, FI, args);
+  CGF.StartFunction(GlobalDecl(), R, Fn, FI, args);
 
   if (generator.needsDispose()) {
     Address addr = CGF.GetAddrOfLocalVar(&Src);
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to