Skip to content

Commit 992ae7f

Browse files
committed
Add file and line metadata for generators
1 parent e77625a commit 992ae7f

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-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
@@ -277,6 +277,9 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
277277
unique_type_id: UniqueTypeId<'tcx>,
278278
) -> DINodeCreationResult<'ll> {
279279
let generator_type = unique_type_id.expect_ty();
280+
let &ty::Generator(generator_def_id, _, _ ) = generator_type.kind() else {
281+
bug!("build_generator_di_node() called with non-generator type: `{:?}`", generator_type)
282+
};
280283
let generator_type_and_layout = cx.layout_of(generator_type);
281284
let generator_type_name = compute_debuginfo_type_name(cx.tcx, generator_type, false);
282285

@@ -289,7 +292,7 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
289292
type_map::Stub::Union,
290293
unique_type_id,
291294
&generator_type_name,
292-
None,
295+
Some(generator_def_id),
293296
size_and_align_of(generator_type_and_layout),
294297
NO_SCOPE_METADATA,
295298
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
@@ -151,7 +151,7 @@ pub(super) fn build_generator_di_node<'ll, 'tcx>(
151151
Stub::Struct,
152152
unique_type_id,
153153
&generator_type_name,
154-
None,
154+
Some(generator_def_id),
155155
size_and_align_of(generator_type_and_layout),
156156
Some(containing_scope),
157157
DIFlags::FlagZero,

tests/codegen/issue-98678.rs

Lines changed: 4 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)]
56

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

@@ -31,4 +32,7 @@ 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 = || yield 1;
3438
}

0 commit comments

Comments
 (0)