Skip to content

Commit 8ee8d79

Browse files
committed
Require type_map::stub callers to supply file information
This change attaches file information (`DIFile` reference and line number) to struct debug info nodes. Before: ``` ; foo.ll ... !5 = !DIFile(filename: "<unknown>", directory: "") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !5, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "4cb373851db92e732c4cb5651b886dd0") ... ``` After: ``` ; foo.ll ... !3 = !DIFile(filename: "foo.rs", directory: "/home/matt/src/rust98678", checksumkind: CSK_SHA1, checksum: "bcb9f08512c8f3b8181ef4726012bc6807bc9be4") ... !16 = !DICompositeType(tag: DW_TAG_structure_type, name: "MyType", scope: !2, file: !3, line: 3, size: 32, align: 32, elements: !17, templateParams: !19, identifier: "9e5968c7af39c148acb253912b7f409f") ... ``` Fixes rust-lang#98678
1 parent eaee1e9 commit 8ee8d79

File tree

5 files changed

+52
-7
lines changed

5 files changed

+52
-7
lines changed

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+25
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ fn build_pointer_or_reference_di_node<'ll, 'tcx>(
210210
Stub::Struct,
211211
unique_type_id,
212212
&ptr_type_debuginfo_name,
213+
unknown_file_metadata(cx),
214+
UNKNOWN_LINE_NUMBER,
213215
cx.size_and_align_of(ptr_type),
214216
NO_SCOPE_METADATA,
215217
DIFlags::FlagZero,
@@ -375,6 +377,8 @@ fn build_dyn_type_di_node<'ll, 'tcx>(
375377
Stub::Struct,
376378
unique_type_id,
377379
&type_name,
380+
unknown_file_metadata(cx),
381+
UNKNOWN_LINE_NUMBER,
378382
cx.size_and_align_of(dyn_type),
379383
NO_SCOPE_METADATA,
380384
DIFlags::FlagZero,
@@ -793,6 +797,8 @@ fn build_foreign_type_di_node<'ll, 'tcx>(
793797
Stub::Struct,
794798
unique_type_id,
795799
&compute_debuginfo_type_name(cx.tcx, t, false),
800+
unknown_file_metadata(cx),
801+
UNKNOWN_LINE_NUMBER,
796802
cx.size_and_align_of(t),
797803
Some(get_namespace_for_item(cx, def_id)),
798804
DIFlags::FlagZero,
@@ -1017,13 +1023,24 @@ fn build_struct_type_di_node<'ll, 'tcx>(
10171023
let struct_type_and_layout = cx.layout_of(struct_type);
10181024
let variant_def = adt_def.non_enum_variant();
10191025

1026+
let tcx = cx.tcx;
1027+
let struct_span = tcx.def_span(adt_def.did());
1028+
let (file_metadata, line_number) = if !struct_span.is_dummy() {
1029+
let loc = cx.lookup_debug_loc(struct_span.lo());
1030+
(file_metadata(cx, &loc.file), loc.line)
1031+
} else {
1032+
(unknown_file_metadata(cx), UNKNOWN_LINE_NUMBER)
1033+
};
1034+
10201035
type_map::build_type_with_children(
10211036
cx,
10221037
type_map::stub(
10231038
cx,
10241039
Stub::Struct,
10251040
unique_type_id,
10261041
&compute_debuginfo_type_name(cx.tcx, struct_type, false),
1042+
file_metadata,
1043+
line_number,
10271044
size_and_align_of(struct_type_and_layout),
10281045
Some(containing_scope),
10291046
visibility_di_flags(cx, adt_def.did(), adt_def.did()),
@@ -1127,6 +1144,8 @@ fn build_tuple_type_di_node<'ll, 'tcx>(
11271144
Stub::Struct,
11281145
unique_type_id,
11291146
&type_name,
1147+
unknown_file_metadata(cx),
1148+
UNKNOWN_LINE_NUMBER,
11301149
size_and_align_of(tuple_type_and_layout),
11311150
NO_SCOPE_METADATA,
11321151
DIFlags::FlagZero,
@@ -1173,6 +1192,8 @@ fn build_closure_env_di_node<'ll, 'tcx>(
11731192
Stub::Struct,
11741193
unique_type_id,
11751194
&type_name,
1195+
unknown_file_metadata(cx),
1196+
UNKNOWN_LINE_NUMBER,
11761197
cx.size_and_align_of(closure_env_type),
11771198
Some(containing_scope),
11781199
DIFlags::FlagZero,
@@ -1204,6 +1225,8 @@ fn build_union_type_di_node<'ll, 'tcx>(
12041225
Stub::Union,
12051226
unique_type_id,
12061227
&type_name,
1228+
unknown_file_metadata(cx),
1229+
UNKNOWN_LINE_NUMBER,
12071230
size_and_align_of(union_ty_and_layout),
12081231
Some(containing_scope),
12091232
DIFlags::FlagZero,
@@ -1387,6 +1410,8 @@ fn build_vtable_type_di_node<'ll, 'tcx>(
13871410
Stub::VTableTy { vtable_holder },
13881411
unique_type_id,
13891412
&vtable_type_name,
1413+
unknown_file_metadata(cx),
1414+
UNKNOWN_LINE_NUMBER,
13901415
(size, pointer_align),
13911416
NO_SCOPE_METADATA,
13921417
DIFlags::FlagArtificial,

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

+6
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
213213
type_map::Stub::Union,
214214
unique_type_id,
215215
&enum_type_name,
216+
unknown_file_metadata(cx),
217+
UNKNOWN_LINE_NUMBER,
216218
cx.size_and_align_of(enum_type),
217219
NO_SCOPE_METADATA,
218220
visibility_di_flags(cx, enum_adt_def.did(), enum_adt_def.did()),
@@ -288,6 +290,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
288290
type_map::Stub::Union,
289291
unique_type_id,
290292
&coroutine_type_name,
293+
unknown_file_metadata(cx),
294+
UNKNOWN_LINE_NUMBER,
291295
size_and_align_of(coroutine_type_and_layout),
292296
NO_SCOPE_METADATA,
293297
DIFlags::FlagZero,
@@ -495,6 +499,8 @@ fn build_variant_struct_wrapper_type_di_node<'ll, 'tcx>(
495499
variant_index,
496500
),
497501
&variant_struct_wrapper_type_name(variant_index),
502+
unknown_file_metadata(cx),
503+
UNKNOWN_LINE_NUMBER,
498504
// NOTE: We use size and align of enum_type, not from variant_layout:
499505
size_and_align_of(enum_or_coroutine_type_and_layout),
500506
Some(enum_or_coroutine_type_di_node),

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

+9-1
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,8 @@ fn build_enum_variant_struct_type_di_node<'ll, 'tcx>(
267267
variant_index,
268268
),
269269
variant_def.name.as_str(),
270+
unknown_file_metadata(cx),
271+
UNKNOWN_LINE_NUMBER,
270272
// NOTE: We use size and align of enum_type, not from variant_layout:
271273
size_and_align_of(enum_type_and_layout),
272274
Some(enum_type_di_node),
@@ -349,6 +351,8 @@ pub fn build_coroutine_variant_struct_type_di_node<'ll, 'tcx>(
349351
Stub::Struct,
350352
unique_type_id,
351353
&variant_name,
354+
unknown_file_metadata(cx),
355+
UNKNOWN_LINE_NUMBER,
352356
size_and_align_of(coroutine_type_and_layout),
353357
Some(coroutine_type_di_node),
354358
DIFlags::FlagZero,
@@ -414,7 +418,11 @@ enum DiscrResult {
414418

415419
impl DiscrResult {
416420
fn opt_single_val(&self) -> Option<u128> {
417-
if let Self::Value(d) = *self { Some(d) } else { None }
421+
if let Self::Value(d) = *self {
422+
Some(d)
423+
} else {
424+
None
425+
}
418426
}
419427
}
420428

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

+4
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
7474
Stub::Struct,
7575
unique_type_id,
7676
&enum_type_name,
77+
unknown_file_metadata(cx),
78+
UNKNOWN_LINE_NUMBER,
7779
size_and_align_of(enum_type_and_layout),
7880
Some(containing_scope),
7981
visibility_flags,
@@ -153,6 +155,8 @@ pub(super) fn build_coroutine_di_node<'ll, 'tcx>(
153155
Stub::Struct,
154156
unique_type_id,
155157
&coroutine_type_name,
158+
unknown_file_metadata(cx),
159+
UNKNOWN_LINE_NUMBER,
156160
size_and_align_of(coroutine_type_and_layout),
157161
Some(containing_scope),
158162
DIFlags::FlagZero,

compiler/rustc_codegen_llvm/src/debuginfo/metadata/type_map.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ use crate::{
1616
debuginfo::utils::{create_DIArray, debug_context, DIB},
1717
llvm::{
1818
self,
19-
debuginfo::{DIFlags, DIScope, DIType},
19+
debuginfo::{DIFile, DIFlags, DIScope, DIType},
2020
},
2121
};
2222

23-
use super::{unknown_file_metadata, SmallVec, UNKNOWN_LINE_NUMBER};
23+
use super::SmallVec;
2424

2525
mod private {
2626
// This type cannot be constructed outside of this module because
@@ -183,6 +183,8 @@ pub(super) fn stub<'ll, 'tcx>(
183183
kind: Stub<'ll>,
184184
unique_type_id: UniqueTypeId<'tcx>,
185185
name: &str,
186+
file_metadata: &'ll DIFile,
187+
line_number: u32,
186188
(size, align): (Size, Align),
187189
containing_scope: Option<&'ll DIScope>,
188190
flags: DIFlags,
@@ -202,8 +204,8 @@ pub(super) fn stub<'ll, 'tcx>(
202204
containing_scope,
203205
name.as_ptr().cast(),
204206
name.len(),
205-
unknown_file_metadata(cx),
206-
UNKNOWN_LINE_NUMBER,
207+
file_metadata,
208+
line_number,
207209
size.bits(),
208210
align.bits() as u32,
209211
flags,
@@ -222,8 +224,8 @@ pub(super) fn stub<'ll, 'tcx>(
222224
containing_scope,
223225
name.as_ptr().cast(),
224226
name.len(),
225-
unknown_file_metadata(cx),
226-
UNKNOWN_LINE_NUMBER,
227+
file_metadata,
228+
line_number,
227229
size.bits(),
228230
align.bits() as u32,
229231
flags,

0 commit comments

Comments
 (0)