Skip to content

Commit f681fd9

Browse files
committed
Revert "[CodeGen] Don't create fake FunctionDecls when generating block/byref"
That commit causes crash with error "!dbg attachment points at wrong subprogram for function" on iOS platforms. This reverts commit f4c06bc.
1 parent 976926e commit f681fd9

File tree

4 files changed

+44
-9
lines changed

4 files changed

+44
-9
lines changed

clang/lib/CodeGen/CGBlocks.cpp

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1948,13 +1948,21 @@ 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+
19511953
SmallVector<QualType, 2> ArgTys;
19521954
ArgTys.push_back(C.VoidPtrTy);
19531955
ArgTys.push_back(C.VoidPtrTy);
1956+
QualType FunctionTy = C.getFunctionType(ReturnTy, ArgTys, {});
19541957

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

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

2146+
IdentifierInfo *II = &C.Idents.get(FuncName);
2147+
21382148
SmallVector<QualType, 1> ArgTys;
21392149
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);
21402155

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

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

2398+
IdentifierInfo *II
2399+
= &Context.Idents.get("__Block_byref_object_copy_");
2400+
23812401
SmallVector<QualType, 2> ArgTys;
23822402
ArgTys.push_back(Context.VoidPtrTy);
23832403
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);
23842409

23852410
CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
23862411

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

23892414
if (generator.needsCopy()) {
23902415
llvm::Type *byrefPtrType = byrefInfo.Type->getPointerTo(0);
@@ -2446,12 +2471,20 @@ generateByrefDisposeHelper(CodeGenFunction &CGF,
24462471
"__Block_byref_object_dispose_",
24472472
&CGF.CGM.getModule());
24482473

2474+
IdentifierInfo *II
2475+
= &Context.Idents.get("__Block_byref_object_dispose_");
2476+
24492477
SmallVector<QualType, 1> ArgTys;
24502478
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);
24512484

24522485
CGF.CGM.SetInternalFunctionAttributes(GlobalDecl(), Fn, FI);
24532486

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

24562489
if (generator.needsDispose()) {
24572490
Address addr = CGF.GetAddrOfLocalVar(&Src);

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

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

15-
// CHECK: !DISubprogram(linkageName: "__Block_byref_object_copy_",
15+
// CHECK: !DISubprogram(name: "__Block_byref_object_copy_",
16+
// CHECK-SAME: line: 11,
1617
// CHECK-SAME: DISPFlagLocalToUnit | DISPFlagDefinition
17-
// CHECK: !DISubprogram(linkageName: "__Block_byref_object_dispose_",
18+
// CHECK: !DISubprogram(name: "__Block_byref_object_dispose_",
19+
// CHECK-SAME: line: 11,
1820
// 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(linkageName: "__destroy_helper_block_8_32o40r48r"
5+
// CHECK: !DISubprogram(name: "__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(linkageName: "__copy_helper_block_
28+
// CHECK-DAG: [[COPY_SP]] = distinct !DISubprogram(name: "__copy_helper_block_
2929
// CHECK-DAG: [[DESTROY_LINE]] = !DILocation(line: 0, scope: ![[DESTROY_SP:[0-9]+]])
30-
// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(linkageName: "__destroy_helper_block_
30+
// CHECK-DAG: [[DESTROY_SP]] = distinct !DISubprogram(name: "__destroy_helper_block_
3131
typedef unsigned int NSUInteger;
3232

3333
@protocol NSObject

0 commit comments

Comments
 (0)