diff --git a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp --- a/llvm/lib/Transforms/Coroutines/CoroFrame.cpp +++ b/llvm/lib/Transforms/Coroutines/CoroFrame.cpp @@ -997,7 +997,7 @@ DenseMap NameCache; NameCache.insert({ResumeIndex, "__resume_fn"}); NameCache.insert({DestroyIndex, "__destroy_fn"}); - NameCache.insert({IndexIndex, "__coro_index"}); + NameCache.insert({IndexIndex, "__suspension_point"}); Type *ResumeFnTy = FrameTy->getElementType(ResumeIndex), *DestroyFnTy = FrameTy->getElementType(DestroyIndex), @@ -1011,14 +1011,37 @@ {DestroyIndex, DBuilder.createPointerType( nullptr, Layout.getTypeSizeInBits(DestroyFnTy))}); - /// FIXME: If we fill the field `SizeInBits` with the actual size of - /// __coro_index in bits, then __coro_index wouldn't show in the debugger. - TyCache.insert({IndexIndex, DBuilder.createBasicType( - "__coro_index", - (Layout.getTypeSizeInBits(IndexTy) < 8) - ? 8 - : Layout.getTypeSizeInBits(IndexTy), - dwarf::DW_ATE_unsigned_char)}); + /// Declare the suspension point index as an enum, where the names of + /// the enum values indicate the line numbers of the suspension point. + SmallVector IndexEnumerators; + for (uint64_t Idx = 0; Idx < Shape.CoroSuspends.size(); ++Idx) { + std::string Name; + // ABI final suspend + if (Shape.ABI == coro::ABI::Switch && + Shape.SwitchLowering.HasFinalSuspend && + Idx == Shape.CoroSuspends.size() - 1) { + Name = "final_suspend"; + } else if (auto DebugLoc = Shape.CoroSuspends[Idx]->getDebugLoc()) { + Name = "line_"; + Name += std::to_string(DebugLoc.getLine()); + Name += "_column_"; + Name += std::to_string(DebugLoc.getCol()); + } + if (!Name.empty()) { + IndexEnumerators.push_back(DBuilder.createEnumerator(Name, Idx)); + } + } + DIBasicType *IndexIntType = + DBuilder.createBasicType("__suspension_point_idx", + (Layout.getTypeSizeInBits(IndexTy) < 8) + ? 8 + : Layout.getTypeSizeInBits(IndexTy), + dwarf::DW_ATE_unsigned); + DICompositeType *IndexEnumType = DBuilder.createEnumerationType( + PromiseDIScope, "__suspension_point", DFile, LineNum, /*Size*/ 0, /*Align*/ 0, + DBuilder.getOrCreateArray(IndexEnumerators), IndexIntType, + /*Identifier*/ "", /*isScoped*/ true); + TyCache.insert({IndexIndex, IndexEnumType}); for (auto *V : FrameData.getAllDefs()) { if (DIVarCache.find(V) == DIVarCache.end())