[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-24 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Thank you for the repro. I added calls to 
`ApplyDebugLocation::CreateArtificial` and reapplied the patch in 
https://github.com/llvm/llvm-project/commit/8db0dbbe2c0544c38f33cf64b4cdd5135d524b23.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-23 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

In D104082#2835496 , @fhahn wrote:

> In D104082#2835080 , @zequanwu 
> wrote:
>
>> Hi, this caused compiler crash with error "Assertion 
>> `cast(Scope)->describes(>getFunction())' failed." on iOS 
>> platforms.  So, I reverted it.
>> I'm working on a reduced repro.
>
> FYI this also caused a failure on GreenDragon, with `-verify-machineinstrs`: 
> https://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-aarch64-O0-g/9663/consoleFull#-134330334249ba4694-19c4-4d7e-bec5-911270d8a58c
>
> The failure should be re-producible by building the following C++ file from 
> llvm-test-suite:
>
>   bin/clang++  -DNDEBUG  -B 
> /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
> -Wno-unused-command-line-argument -mllvm -verify-machineinstrs -O0 -g 
> -arch arm64 -isysroot 
> /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk
>-w -Werror=date-time -MD -MT 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
>  -MF 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o.d
>  -o 
> SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
>  -c 
> /Users/buildslave/jenkins/workspace/test-suite-verify-machineinstrs-aarch64-O0-g/test-suite/SingleSource/UnitTests/block-byref-cxxobj-test.cpp

Thanks.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-23 Thread Florian Hahn via Phabricator via cfe-commits
fhahn added a comment.

In D104082#2835080 , @zequanwu wrote:

> Hi, this caused compiler crash with error "Assertion 
> `cast(Scope)->describes(>getFunction())' failed." on iOS 
> platforms.  So, I reverted it.
> I'm working on a reduced repro.

FYI this also caused a failure on GreenDragon, with `-verify-machineinstrs`: 
https://green.lab.llvm.org/green/job/test-suite-verify-machineinstrs-aarch64-O0-g/9663/consoleFull#-134330334249ba4694-19c4-4d7e-bec5-911270d8a58c

The failure should be re-producible by building the following C++ file from 
llvm-test-suite:

  bin/clang++  -DNDEBUG  -B 
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin
-Wno-unused-command-line-argument -mllvm -verify-machineinstrs -O0 -g -arch 
arm64 -isysroot 
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.5.sdk
   -w -Werror=date-time -MD -MT 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
 -MF 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o.d
 -o 
SingleSource/UnitTests/CMakeFiles/block-byref-cxxobj-test.dir/block-byref-cxxobj-test.cpp.o
 -c 
/Users/buildslave/jenkins/workspace/test-suite-verify-machineinstrs-aarch64-O0-g/test-suite/SingleSource/UnitTests/block-byref-cxxobj-test.cpp


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-22 Thread Zequan Wu via Phabricator via cfe-commits
zequanwu added a comment.

Hi, this caused compiler crash on error "!dbg attachment points at wrong 
subprogram for function".  So, I reverted it.
I'm working on a reduced repro.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-22 Thread Akira Hatanaka via Phabricator via cfe-commits
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rGf4c06bcb67a1: [CodeGen] Dont create fake FunctionDecls 
when generating block/byref (authored by ahatanak).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

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,13 @@
   if (CGM.supportsCOMDAT())
 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = (FuncName);
-
   SmallVector 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 +2135,12 @@
   if (CGM.supportsCOMDAT())
 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = (FuncName);
-
   SmallVector 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 +2378,13 @@
 llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
"__Block_byref_object_copy_", ());
 
-  IdentifierInfo *II
-= ("__Block_byref_object_copy_");

[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-22 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak updated this revision to Diff 353729.
ahatanak marked 2 inline comments as done.
ahatanak added a comment.

Delete comments.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

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,13 @@
   if (CGM.supportsCOMDAT())
 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = (FuncName);
-
   SmallVector 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 +2135,12 @@
   if (CGM.supportsCOMDAT())
 Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
 
-  IdentifierInfo *II = (FuncName);
-
   SmallVector 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 +2378,13 @@
 llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
"__Block_byref_object_copy_", ());
 
-  IdentifierInfo *II
-= ("__Block_byref_object_copy_");
-
   SmallVector ArgTys;
   ArgTys.push_back(Context.VoidPtrTy);
   ArgTys.push_back(Context.VoidPtrTy);
-  QualType 

[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl added inline comments.



Comment at: clang/lib/CodeGen/CGBlocks.cpp:2144
  CGM);
   // This is necessary to avoid inheriting the previous line number.
+  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);

Same here — the comment should be removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-22 Thread Adrian Prantl via Phabricator via cfe-commits
aprantl accepted this revision.
aprantl added a comment.

Block copy helpers don't have any source code associated with them, so as long 
as they are described by a DISubprogram, the exact format of it most likely 
does not matter.




Comment at: clang/lib/CodeGen/CGBlocks.cpp:1957
  CGM);
   // This is necessary to avoid inheriting the previous line number.
+  StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);

This comment refers to the `FD->setImplicit();` that was removed.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-15 Thread David Blaikie via Phabricator via cfe-commits
dblaikie accepted this revision.
dblaikie added a comment.
This revision is now accepted and ready to land.

In D104082#2818281 , @ahatanak wrote:

> C++ non-virtual thunks and global initialization functions 
> (`_GLOBAL__sub_I_*`) have only linkage names.

Works for me - and the debug info codegen looks like it does handle this 
situation intentionally: 
https://github.com/llvm/llvm-project/blob/a11880468e556d20ad9b0d43a1ff43daf62d49b2/clang/lib/CodeGen/CGDebugInfo.cpp#L3896.

Maybe give it a few days (or directly ask) to see if @aprantl has further 
thoughts, since I'm not especially familiar with Objective C things, but it 
looks pretty right/good enough for me.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-14 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

C++ non-virtual thunks and global initialization functions (`_GLOBAL__sub_I_*`) 
have only linkage names.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-11 Thread David Blaikie via Phabricator via cfe-commits
dblaikie added a comment.

In D104082#2812088 , @ahatanak wrote:

> Also, is it okay to emit the `linkageName`, but not the `name` for the helper 
> functions? It seems okay to me, but I'm not sure.

Not 100% sure - perhaps @aprantl can weigh in on this. If you can find some 
precedent/existing cases where we do that, might help provide some confidence 
(one way I'd do that would be to put an assertion in the CGDebugInfo code that 
makes the choice about which names to add - asserting if only a linkage name is 
added and no non-linkage name - then run check-clang and see what, if any, 
tests fail - that'll identify cases that have this property)


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-10 Thread Akira Hatanaka via Phabricator via cfe-commits
ahatanak added a comment.

Also, is it okay to emit the `linkageName`, but not the `name` for the helper 
functions? It seems okay to me, but I'm not sure.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D104082/new/

https://reviews.llvm.org/D104082

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D104082: [CodeGen] Don't create a fake FunctionDecl when generating block/block_byref copy/dispose helper functions

2021-06-10 Thread Akira Hatanaka via Phabricator via cfe-commits
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 = (FuncName);
-
   SmallVector 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 = (FuncName);
-
   SmallVector 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);