Skip to content

Commit f4c06bc

Browse files
committed
[CodeGen] Don't create fake FunctionDecls when generating block/byref
copy/dispose helper functions We found out that these fake functions would cause clang to crash if the changes proposed in https://reviews.llvm.org/D98799 were made. Differential Revision: https://reviews.llvm.org/D104082
1 parent ca1560d commit f4c06bc

File tree

4 files changed

+9
-44
lines changed

4 files changed

+9
-44
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,21 +1948,13 @@ CodeGenFunction::GenerateCopyHelperFunction(const CGBlockInfo &blockInfo) {
19481948
if (CGM.supportsCOMDAT())
19491949
Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
19501950

1951-
IdentifierInfo *II = &C.Idents.get(FuncName);
1952-
19531951
SmallVector<QualType, 2> ArgTys;
19541952
ArgTys.push_back(C.VoidPtrTy);
19551953
ArgTys.push_back(C.VoidPtrTy);
1956-
QualType FunctionTy = C.getFunctionType(ReturnTy, ArgTys, {});
19571954

1958-
FunctionDecl *FD = FunctionDecl::Create(
1959-
C, C.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
1960-
FunctionTy, nullptr, SC_Static, false, false);
19611955
setBlockHelperAttributesVisibility(blockInfo.CapturesNonExternalType, Fn, FI,
19621956
CGM);
1963-
// This is necessary to avoid inheriting the previous line number.
1964-
FD->setImplicit();
1965-
StartFunction(FD, ReturnTy, Fn, FI, args);
1957+
StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
19661958
auto AL = ApplyDebugLocation::CreateArtificial(*this);
19671959

19681960
llvm::Type *structPtrTy = blockInfo.StructureType->getPointerTo();
@@ -2143,21 +2135,12 @@ CodeGenFunction::GenerateDestroyHelperFunction(const CGBlockInfo &blockInfo) {
21432135
if (CGM.supportsCOMDAT())
21442136
Fn->setComdat(CGM.getModule().getOrInsertComdat(FuncName));
21452137

2146-
IdentifierInfo *II = &C.Idents.get(FuncName);
2147-
21482138
SmallVector<QualType, 1> ArgTys;
21492139
ArgTys.push_back(C.VoidPtrTy);
2150-
QualType FunctionTy = C.getFunctionType(ReturnTy, ArgTys, {});
2151-
2152-
FunctionDecl *FD = FunctionDecl::Create(
2153-
C, C.getTranslationUnitDecl(), SourceLocation(), SourceLocation(), II,
2154-
FunctionTy, nullptr, SC_Static, false, false);
21552140

21562141
setBlockHelperAttributesVisibility(blockInfo.CapturesNonExternalType, Fn, FI,
21572142
CGM);
2158-
// This is necessary to avoid inheriting the previous line number.
2159-
FD->setImplicit();
2160-
StartFunction(FD, ReturnTy, Fn, FI, args);
2143+
StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
21612144
markAsIgnoreThreadCheckingAtRuntime(Fn);
21622145

21632146
auto AL = ApplyDebugLocation::CreateArtificial(*this);
@@ -2395,21 +2378,13 @@ generateByrefCopyHelper(CodeGenFunction &CGF, const BlockByrefInfo &byrefInfo,
23952378
llvm::Function::Create(LTy, llvm::GlobalValue::InternalLinkage,
23962379
"__Block_byref_object_copy_", &CGF.CGM.getModule());
23972380

2398-
IdentifierInfo *II
2399-
= &Context.Idents.get("__Block_byref_object_copy_");
2400-
24012381
SmallVector<QualType, 2> ArgTys;
24022382
ArgTys.push_back(Context.VoidPtrTy);
24032383
ArgTys.push_back(Context.VoidPtrTy);
2404-
QualType FunctionTy = Context.getFunctionType(ReturnTy, ArgTys, {});
2405-
2406-
FunctionDecl *FD = FunctionDecl::Create(
2407-
Context, Context.getTranslationUnitDecl(), SourceLocation(),
2408-
SourceLocation(), II, FunctionTy, nullptr, SC_Static, false, false);
24092384

24102385
CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
24112386

2412-
CGF.StartFunction(FD, ReturnTy, Fn, FI, args);
2387+
CGF.StartFunction(GlobalDecl(), ReturnTy, Fn, FI, args);
24132388

24142389
if (generator.needsCopy()) {
24152390
llvm::Type *byrefPtrType = byrefInfo.Type->getPointerTo(0);
@@ -2471,20 +2446,12 @@ generateByrefDisposeHelper(CodeGenFunction &CGF,
24712446
"__Block_byref_object_dispose_",
24722447
&CGF.CGM.getModule());
24732448

2474-
IdentifierInfo *II
2475-
= &Context.Idents.get("__Block_byref_object_dispose_");
2476-
24772449
SmallVector<QualType, 1> ArgTys;
24782450
ArgTys.push_back(Context.VoidPtrTy);
2479-
QualType FunctionTy = Context.getFunctionType(R, ArgTys, {});
2480-
2481-
FunctionDecl *FD = FunctionDecl::Create(
2482-
Context, Context.getTranslationUnitDecl(), SourceLocation(),
2483-
SourceLocation(), II, FunctionTy, nullptr, SC_Static, false, false);
24842451

24852452
CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
24862453

2487-
CGF.StartFunction(FD, R, Fn, FI, args);
2454+
CGF.StartFunction(GlobalDecl(), R, Fn, FI, args);
24882455

24892456
if (generator.needsDispose()) {
24902457
Address addr = CGF.GetAddrOfLocalVar(&Src);

clang/test/CodeGenCXX/debug-info-blocks.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@ void test() {
1212
^{ (void)a; };
1313
}
1414

15-
// CHECK: !DISubprogram(name: "__Block_byref_object_copy_",
16-
// CHECK-SAME: line: 11,
15+
// CHECK: !DISubprogram(linkageName: "__Block_byref_object_copy_",
1716
// CHECK-SAME: DISPFlagLocalToUnit | DISPFlagDefinition
18-
// CHECK: !DISubprogram(name: "__Block_byref_object_dispose_",
19-
// CHECK-SAME: line: 11,
17+
// CHECK: !DISubprogram(linkageName: "__Block_byref_object_dispose_",
2018
// CHECK-SAME: DISPFlagLocalToUnit | DISPFlagDefinition

clang/test/CodeGenObjC/debug-info-block-helper.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// 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
33
extern void foo(void(^)(void));
44

5-
// CHECK: !DISubprogram(name: "__destroy_helper_block_8_32o40r48r"
5+
// CHECK: !DISubprogram(linkageName: "__destroy_helper_block_8_32o40r48r"
66

77
@interface NSObject {
88
struct objc_object *isa;

clang/test/CodeGenObjC/debug-info-blocks.m

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
// CHECK: ret {{.*}}, !dbg ![[DESTROY_LINE]]
2626

2727
// CHECK-DAG: [[DBG_LINE]] = !DILocation(line: 0, scope: ![[COPY_SP:[0-9]+]])
28-
// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_
28+
// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(linkageName: "__copy_helper_block_
2929
// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
30-
// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_
30+
// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(linkageName: "__destroy_helper_block_
3131
typedef unsigned int NSUInteger;
3232

3333
@protocol NSObject

0 commit comments

Comments
 (0)