Skip to content

Commit e7be09e

Browse files
gribozavrcjdb
authored andcommitted
Revert "[Coroutines] [NFCI] Don't search the DILocalVariable for __promise when constructing the debug varaible for __coro_frame"
This reverts commit 08a0dec. This series of commits causes Clang crashes. The reproducer is posted on llvm@08a0dec.
1 parent 4361911 commit e7be09e

File tree

4 files changed

+40
-28
lines changed

4 files changed

+40
-28
lines changed

llvm/lib/Transforms/Coroutines/CoroFrame.cpp

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,8 +1125,26 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
11251125
assert(PromiseAlloca &&
11261126
"Coroutine with switch ABI should own Promise alloca");
11271127

1128-
DIFile *DFile = DIS->getFile();
1129-
unsigned LineNum = DIS->getLine();
1128+
TinyPtrVector<DbgDeclareInst *> DIs = findDbgDeclares(PromiseAlloca);
1129+
TinyPtrVector<DbgVariableRecord *> DVRs = findDVRDeclares(PromiseAlloca);
1130+
1131+
DILocalVariable *PromiseDIVariable = nullptr;
1132+
DILocation *DILoc = nullptr;
1133+
if (!DIs.empty()) {
1134+
DbgDeclareInst *PromiseDDI = DIs.front();
1135+
PromiseDIVariable = PromiseDDI->getVariable();
1136+
DILoc = PromiseDDI->getDebugLoc().get();
1137+
} else if (!DVRs.empty()) {
1138+
DbgVariableRecord *PromiseDVR = DVRs.front();
1139+
PromiseDIVariable = PromiseDVR->getVariable();
1140+
DILoc = PromiseDVR->getDebugLoc().get();
1141+
} else {
1142+
return;
1143+
}
1144+
1145+
DILocalScope *PromiseDIScope = PromiseDIVariable->getScope();
1146+
DIFile *DFile = PromiseDIScope->getFile();
1147+
unsigned LineNum = PromiseDIVariable->getLine();
11301148

11311149
DICompositeType *FrameDITy = DBuilder.createStructType(
11321150
DIS->getUnit(), Twine(F.getName() + ".coro_frame_ty").str(),
@@ -1236,9 +1254,10 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
12361254

12371255
DBuilder.replaceArrays(FrameDITy, DBuilder.getOrCreateArray(Elements));
12381256

1239-
auto *FrameDIVar =
1240-
DBuilder.createAutoVariable(DIS, "__coro_frame", DFile, LineNum,
1241-
FrameDITy, true, DINode::FlagArtificial);
1257+
auto *FrameDIVar = DBuilder.createAutoVariable(PromiseDIScope, "__coro_frame",
1258+
DFile, LineNum, FrameDITy,
1259+
true, DINode::FlagArtificial);
1260+
assert(FrameDIVar->isValidLocationForIntrinsic(DILoc));
12421261

12431262
// Subprogram would have ContainedNodes field which records the debug
12441263
// variables it contained. So we need to add __coro_frame to the
@@ -1247,17 +1266,14 @@ static void buildFrameDebugInfo(Function &F, coro::Shape &Shape,
12471266
// If we don't add __coro_frame to the RetainedNodes, user may get
12481267
// `no symbol __coro_frame in context` rather than `__coro_frame`
12491268
// is optimized out, which is more precise.
1250-
auto RetainedNodes = DIS->getRetainedNodes();
1251-
SmallVector<Metadata *, 32> RetainedNodesVec(RetainedNodes.begin(),
1252-
RetainedNodes.end());
1253-
RetainedNodesVec.push_back(FrameDIVar);
1254-
DIS->replaceOperandWith(7, (MDTuple::get(F.getContext(), RetainedNodesVec)));
1255-
1256-
// Construct the location for the frame debug variable. The column number
1257-
// is fake but it should be fine.
1258-
DILocation *DILoc =
1259-
DILocation::get(DIS->getContext(), LineNum, /*Column=*/1, DIS);
1260-
assert(FrameDIVar->isValidLocationForIntrinsic(DILoc));
1269+
if (auto *SubProgram = dyn_cast<DISubprogram>(PromiseDIScope)) {
1270+
auto RetainedNodes = SubProgram->getRetainedNodes();
1271+
SmallVector<Metadata *, 32> RetainedNodesVec(RetainedNodes.begin(),
1272+
RetainedNodes.end());
1273+
RetainedNodesVec.push_back(FrameDIVar);
1274+
SubProgram->replaceOperandWith(
1275+
7, (MDTuple::get(F.getContext(), RetainedNodesVec)));
1276+
}
12611277

12621278
if (UseNewDbgInfoFormat) {
12631279
DbgVariableRecord *NewDVR =

llvm/test/Transforms/Coroutines/coro-debug-coro-frame.ll

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
;
1616
; CHECK-DAG: ![[FILE:[0-9]+]] = !DIFile(filename: "coro-debug.cpp"
1717
; CHECK-DAG: ![[RAMP:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov",
18-
; CHECK-DAG: ![[CORO_FRAME]] = !DILocalVariable(name: "__coro_frame", scope: ![[RAMP]], file: ![[FILE]], line: [[CORO_FRAME_LINE:[0-9]+]], type: ![[FRAME_TYPE:[0-9]+]], flags: DIFlagArtificial)
18+
; CHECK-DAG: ![[RAMP_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[RAMP]], file: ![[FILE]], line: 23
19+
; CHECK-DAG: ![[CORO_FRAME]] = !DILocalVariable(name: "__coro_frame", scope: ![[RAMP_SCOPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE:[0-9]+]], type: ![[FRAME_TYPE:[0-9]+]], flags: DIFlagArtificial)
1920
; CHECK-DAG: ![[FRAME_TYPE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "f.coro_frame_ty", {{.*}}elements: ![[ELEMENTS:[0-9]+]]
2021
; CHECK-DAG: ![[ELEMENTS]] = !{![[RESUME_FN:[0-9]+]], ![[DESTROY_FN:[0-9]+]], ![[PROMISE:[0-9]+]], ![[VECTOR_TYPE:[0-9]+]], ![[INT64_0:[0-9]+]], ![[DOUBLE_1:[0-9]+]], ![[INT64_PTR:[0-9]+]], ![[INT32_2:[0-9]+]], ![[INT32_3:[0-9]+]], ![[UNALIGNED_UNKNOWN:[0-9]+]], ![[STRUCT:[0-9]+]], ![[CORO_INDEX:[0-9]+]], ![[SMALL_UNKNOWN:[0-9]+]]
2122
; CHECK-DAG: ![[RESUME_FN]] = !DIDerivedType(tag: DW_TAG_member, name: "__resume_fn"{{.*}}, baseType: ![[RESUME_FN_TYPE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
@@ -28,26 +29,25 @@
2829
; CHECK-DAG: ![[UNKNOWN_TYPE_BASE]] = !DIBasicType(name: "UnknownType", size: 8, encoding: DW_ATE_unsigned_char, flags: DIFlagArtificial)
2930
; CHECK-DAG: ![[VECTOR_TYPE_BASE_ELEMENTS]] = !{![[VECTOR_TYPE_BASE_SUBRANGE:[0-9]+]]}
3031
; CHECK-DAG: ![[VECTOR_TYPE_BASE_SUBRANGE]] = !DISubrange(count: 16, lowerBound: 0)
31-
; CHECK-DAG: ![[INT64_0]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_64_1", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[CORO_FRAME_LINE]], baseType: ![[I64_BASE:[0-9]+]],{{.*}}, flags: DIFlagArtificial
32+
; CHECK-DAG: ![[INT64_0]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_64_1", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I64_BASE:[0-9]+]],{{.*}}, flags: DIFlagArtificial
3233
; CHECK-DAG: ![[I64_BASE]] = !DIBasicType(name: "__int_64", size: 64, encoding: DW_ATE_signed, flags: DIFlagArtificial)
33-
; CHECK-DAG: ![[DOUBLE_1]] = !DIDerivedType(tag: DW_TAG_member, name: "__double__2", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[CORO_FRAME_LINE]], baseType: ![[DOUBLE_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
34+
; CHECK-DAG: ![[DOUBLE_1]] = !DIDerivedType(tag: DW_TAG_member, name: "__double__2", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[DOUBLE_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
3435
; CHECK-DAG: ![[DOUBLE_BASE]] = !DIBasicType(name: "__double_", size: 64, encoding: DW_ATE_float, flags: DIFlagArtificial)
35-
; CHECK-DAG: ![[INT32_2]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_4", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[CORO_FRAME_LINE]], baseType: ![[I32_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
36+
; CHECK-DAG: ![[INT32_2]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_4", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I32_BASE:[0-9]+]]{{.*}}, flags: DIFlagArtificial
3637
; CHECK-DAG: ![[I32_BASE]] = !DIBasicType(name: "__int_32", size: 32, encoding: DW_ATE_signed, flags: DIFlagArtificial)
37-
; CHECK-DAG: ![[INT32_3]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_5", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[CORO_FRAME_LINE]], baseType: ![[I32_BASE]]
38+
; CHECK-DAG: ![[INT32_3]] = !DIDerivedType(tag: DW_TAG_member, name: "__int_32_5", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[I32_BASE]]
3839
; CHECK-DAG: ![[UNALIGNED_UNKNOWN]] = !DIDerivedType(tag: DW_TAG_member, name: "_6",{{.*}}baseType: ![[UNALIGNED_UNKNOWN_BASE:[0-9]+]], size: 9
3940
; CHECK-DAG: ![[UNALIGNED_UNKNOWN_BASE]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[UNKNOWN_TYPE_BASE]], size: 16,{{.*}} elements: ![[UNALIGNED_UNKNOWN_ELEMENTS:[0-9]+]])
4041
; CHECK-DAG: ![[UNALIGNED_UNKNOWN_ELEMENTS]] = !{![[UNALIGNED_UNKNOWN_SUBRANGE:[0-9]+]]}
4142
; CHECk-DAG: ![[UNALIGNED_UNKNOWN_SUBRANGE]] = !DISubrange(count: 2, lowerBound: 0)
42-
; CHECK-DAG: ![[STRUCT]] = !DIDerivedType(tag: DW_TAG_member, name: "struct_big_structure_7", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[CORO_FRAME_LINE]], baseType: ![[STRUCT_BASE:[0-9]+]]
43+
; CHECK-DAG: ![[STRUCT]] = !DIDerivedType(tag: DW_TAG_member, name: "struct_big_structure_7", scope: ![[FRAME_TYPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]], baseType: ![[STRUCT_BASE:[0-9]+]]
4344
; CHECK-DAG: ![[STRUCT_BASE]] = !DICompositeType(tag: DW_TAG_structure_type, name: "struct_big_structure"{{.*}}, align: 64, flags: DIFlagArtificial, elements: ![[STRUCT_ELEMENTS:[0-9]+]]
4445
; CHECK-DAG: ![[STRUCT_ELEMENTS]] = !{![[MEM_TYPE:[0-9]+]]}
4546
; CHECK-DAG: ![[MEM_TYPE]] = !DIDerivedType(tag: DW_TAG_member,{{.*}} baseType: ![[MEM_TYPE_BASE:[0-9]+]], size: 4000
4647
; CHECK-DAG: ![[MEM_TYPE_BASE]] = !DICompositeType(tag: DW_TAG_array_type, baseType: ![[UNKNOWN_TYPE_BASE]], size: 4000,
4748
; CHECK-DAG: ![[CORO_INDEX]] = !DIDerivedType(tag: DW_TAG_member, name: "__coro_index"
4849
; CHECK-DAG: ![[SMALL_UNKNOWN]] = !DIDerivedType(tag: DW_TAG_member, name: "UnknownType_8",{{.*}} baseType: ![[UNKNOWN_TYPE_BASE]], size: 5
49-
; CHECK-DAG: ![[PROMISE_VAR:[0-9]+]] = !DILocalVariable(name: "__promise", scope: ![[RAMP_SCOPE:[0-9]+]], file: ![[FILE]]
50-
; CHECK-DAG: ![[RAMP_SCOPE]] = distinct !DILexicalBlock(scope: ![[RAMP]], file: ![[FILE]], line: 23
50+
; CHECK-DAG: ![[PROMISE_VAR:[0-9]+]] = !DILocalVariable(name: "__promise", scope: ![[RAMP_SCOPE]], file: ![[FILE]], line: [[PROMISE_VAR_LINE]]
5151
; CHECK-DAG: ![[BAR_FUNC:[0-9]+]] = distinct !DISubprogram(name: "bar", linkageName: "_Z3barv",
5252
; CHECK-DAG: ![[BAR_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[BAR_FUNC]], file: !1
5353
; CHECK-DAG: ![[FRAME_TYPE_IN_BAR:[0-9]+]] = !DICompositeType(tag: DW_TAG_structure_type, name: "bar.coro_frame_ty", file: ![[FILE]], line: [[BAR_LINE:[0-9]+]]{{.*}}elements: ![[ELEMENTS_IN_BAR:[0-9]+]]

llvm/test/Transforms/Coroutines/coro-debug-dbg.values.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
; CHECK-SAME: ptr {{.*}} %[[frame:.*]])
2626
; CHECK-SAME: !dbg ![[RESUME_FN_DBG_NUM:[0-9]+]]
2727
; CHECK: %[[frame_alloca:.*]] = alloca ptr
28-
; CHECK-NEXT: #dbg_declare(ptr %begin.debug, ![[FRAME_DI_NUM:[0-9]+]],
2928
; CHECK-NEXT: store ptr %[[frame]], ptr %[[frame_alloca]]
3029
; CHECK: init.ready:
3130
; CHECK: #dbg_value(ptr %[[frame_alloca]], ![[XVAR_RESUME:[0-9]+]],
@@ -39,7 +38,6 @@
3938
; CHECK-SAME: !DIExpression(DW_OP_deref, DW_OP_plus_uconst, [[OffsetJ]], DW_OP_deref)
4039
;
4140
; CHECK: ![[RESUME_FN_DBG_NUM]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
42-
; CHECK: ![[FRAME_DI_NUM]] = !DILocalVariable(name: "__coro_frame"
4341
; CHECK: ![[IVAR_RESUME]] = !DILocalVariable(name: "i"
4442
; CHECK: ![[XVAR_RESUME]] = !DILocalVariable(name: "x"
4543
; CHECK: ![[JVAR_RESUME]] = !DILocalVariable(name: "j"

llvm/test/Transforms/Coroutines/coro-debug-frame-variable.ll

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,14 +42,12 @@
4242
; CHECK-NEXT: %[[DBG_PTR:.*]] = alloca ptr
4343
; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[XVAR_RESUME:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 32),
4444
; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[IVAR_RESUME:[0-9]+]], !DIExpression(DW_OP_deref, DW_OP_plus_uconst, 20), ![[IDBGLOC_RESUME:[0-9]+]]
45-
; CHECK-NEXT: #dbg_declare(ptr %[[DBG_PTR]], ![[FRAME_RESUME:[0-9]+]], !DIExpression(DW_OP_deref),
4645
; CHECK-NEXT: store ptr {{.*}}, ptr %[[DBG_PTR]]
4746
; CHECK: %[[J:.*]] = alloca i32, align 4
4847
; CHECK-NEXT: #dbg_declare(ptr %[[J]], ![[JVAR_RESUME:[0-9]+]], !DIExpression(), ![[JDBGLOC_RESUME:[0-9]+]]
4948
; CHECK: init.ready:
5049
; CHECK: await.ready:
5150
;
52-
; CHECK-DAG: ![[FRAME_RESUME]] = !DILocalVariable(name: "__coro_frame"
5351
; CHECK-DAG: ![[IVAR]] = !DILocalVariable(name: "i"
5452
; CHECK-DAG: ![[PROG_SCOPE:[0-9]+]] = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov"
5553
; CHECK-DAG: ![[BLK_SCOPE:[0-9]+]] = distinct !DILexicalBlock(scope: ![[PROG_SCOPE]], file: !1, line: 23, column: 12)

0 commit comments

Comments
 (0)