Skip to content

Commit c07797a

Browse files
committed
Add file and line metadata for coroutines
1 parent f3da828 commit c07797a

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/cpp_like.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
263263
unique_type_id: UniqueTypeId<'tcx>,
264264
) -> DINodeCreationResult<'ll> {
265265
let coroutine_type = unique_type_id.expect_ty();
266+
let &ty::Coroutine(coroutine_def_id, _, _) = coroutine_type.kind() else {
267+
bug!("build_coroutine_di_node() called with non-coroutine type: `{:?}`", coroutine_type)
268+
};
266269
let coroutine_type_and_layout = cx.layout_of(coroutine_type);
267270
let coroutine_type_name = compute_debuginfo_type_name(cx.tcx, coroutine_type, false);
268271

@@ -275,7 +278,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
275278
type_map::Stub::Union,
276279
unique_type_id,
277280
&coroutine_type_name,
278-
None,
281+
Some(coroutine_def_id),
279282
size_and_align_of(coroutine_type_and_layout),
280283
NO_SCOPE_METADATA,
281284
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/enums/native.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
142142
Stub::Struct,
143143
unique_type_id,
144144
&coroutine_type_name,
145-
None,
145+
Some(coroutine_def_id),
146146
size_and_align_of(coroutine_type_and_layout),
147147
Some(containing_scope),
148148
DIFlags::FlagZero,

tests/codegen/issue-98678.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
//
33
// compile-flags: -C debuginfo=2
44
#![crate_type = "lib"]
5+
#![feature(generators, stmt_expr_attributes)]
56

67
// The use of CHECK-DAG here is because the C++-like enum is emitted before the `DIFile` node
78

@@ -31,4 +32,8 @@ pub fn foo(_: MyType, _: MyUnion, _: MyNativeEnum, _: MyCppLikeEnum) {
3132
// CHECK: !DICompositeType({{.*"[{]}}closure_env#0{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
3233
let closure = |x| x;
3334
closure(0);
35+
36+
// CHECK: !DICompositeType({{.*"[{]}}generator_env#1{{[}]".*}}file: ![[#FILE]]{{.*}}line: [[# @LINE + 1]],
37+
let generator = #[coroutine]
38+
|| yield 1;
3439
}

0 commit comments

Comments
 (0)