Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 65a846a

Browse files
Rollup merge of #145967 - Enselic:big-enum-debuginfo-span, r=wesleywiser
compiler: Include span of too huge enum with `-Cdebuginfo=2` We have the ui test `tests/ui/limits/huge-enum.rs` to ensure we emit an error if we encounter too big enums. Before this fix, compiling the test with `-Cdebuginfo=2` would not include the span of the instantiation site, because the error is then emitted from a different code path that does not include the span. Propagate the span to the error also in the debuginfo case, so the test passes regardless of debuginfo level. I'm sure we can propagate spans in more places, but let's start small. ## Test failure without the fix Here is what the failure looks like if you run the test without the fix: ``` [ui] tests/ui/limits/huge-enum.rs#full-debuginfo ... F . failures: ---- [ui] tests/ui/limits/huge-enum.rs#full-debuginfo stdout ---- Saved the actual stderr to `/home/martin/src/rust/build/x86_64-unknown-linux-gnu/test/ui/limits/huge-enum.full-debuginfo/huge-enum.full-debuginfo.stderr` diff of stderr: 1 error: values of the type `Option<TYPE>` are too big for the target architecture - --> $DIR/huge-enum.rs:17:9 - | - LL | let big: BIG = None; - | ^^^ 6 7 error: aborting due to 1 previous error 8 The actual stderr differed from the expected stderr To update references, rerun the tests and pass the `--bless` flag To only update this specific test, also pass `--test-args limits/huge-enum.rs` ``` as can be seen, the `span` used to be missing with `debuginfo=2`. ## See also This is one small step towards resolving #61117. cc #144499 which began running UI tests with `rust.debuginfo-level-tests=1`. This PR is part of preparing for increasing that to debuglevel 2.
2 parents 751a9ad + 4edfeb2 commit 65a846a

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ use rustc_middle::ty::{
1919
self, AdtKind, CoroutineArgsExt, ExistentialTraitRef, Instance, Ty, TyCtxt, Visibility,
2020
};
2121
use rustc_session::config::{self, DebugInfo, Lto};
22-
use rustc_span::{DUMMY_SP, FileName, FileNameDisplayPreference, SourceFile, Symbol, hygiene};
22+
use rustc_span::{
23+
DUMMY_SP, FileName, FileNameDisplayPreference, SourceFile, Span, Symbol, hygiene,
24+
};
2325
use rustc_symbol_mangling::typeid_for_trait_ref;
2426
use rustc_target::spec::DebuginfoKind;
2527
use smallvec::smallvec;
@@ -423,6 +425,14 @@ fn build_slice_type_di_node<'ll, 'tcx>(
423425
/// This function will look up the debuginfo node in the TypeMap. If it can't find it, it
424426
/// will create the node by dispatching to the corresponding `build_*_di_node()` function.
425427
pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll DIType {
428+
spanned_type_di_node(cx, t, DUMMY_SP)
429+
}
430+
431+
pub(crate) fn spanned_type_di_node<'ll, 'tcx>(
432+
cx: &CodegenCx<'ll, 'tcx>,
433+
t: Ty<'tcx>,
434+
span: Span,
435+
) -> &'ll DIType {
426436
let unique_type_id = UniqueTypeId::for_ty(cx.tcx, t);
427437

428438
if let Some(existing_di_node) = debug_context(cx).type_map.di_node_for_unique_id(unique_type_id)
@@ -460,7 +470,7 @@ pub(crate) fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) ->
460470
ty::Adt(def, ..) => match def.adt_kind() {
461471
AdtKind::Struct => build_struct_type_di_node(cx, unique_type_id),
462472
AdtKind::Union => build_union_type_di_node(cx, unique_type_id),
463-
AdtKind::Enum => enums::build_enum_type_di_node(cx, unique_type_id),
473+
AdtKind::Enum => enums::build_enum_type_di_node(cx, unique_type_id, span),
464474
},
465475
ty::Tuple(_) => build_tuple_type_di_node(cx, unique_type_id),
466476
_ => bug!("debuginfo: unexpected type in type_di_node(): {:?}", t),

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::bug;
1010
use rustc_middle::mir::CoroutineLayout;
1111
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
1212
use rustc_middle::ty::{self, AdtDef, CoroutineArgs, CoroutineArgsExt, Ty, VariantDef};
13-
use rustc_span::Symbol;
13+
use rustc_span::{Span,Symbol};
1414

1515
use super::type_map::{DINodeCreationResult, UniqueTypeId};
1616
use super::{SmallVec, size_and_align_of};
@@ -30,13 +30,14 @@ mod native;
3030
pub(super) fn build_enum_type_di_node<'ll, 'tcx>(
3131
cx: &CodegenCx<'ll, 'tcx>,
3232
unique_type_id: UniqueTypeId<'tcx>,
33+
span: Span,
3334
) -> DINodeCreationResult<'ll> {
3435
let enum_type = unique_type_id.expect_ty();
3536
let &ty::Adt(enum_adt_def, _) = enum_type.kind() else {
3637
bug!("build_enum_type_di_node() called with non-enum type: `{:?}`", enum_type)
3738
};
3839

39-
let enum_type_and_layout = cx.layout_of(enum_type);
40+
let enum_type_and_layout = cx.spanned_layout_of(enum_type, span);
4041

4142
if wants_c_like_enum_debuginfo(cx.tcx, enum_type_and_layout) {
4243
return build_c_style_enum_di_node(cx, enum_adt_def, enum_type_and_layout);

‎compiler/rustc_codegen_llvm/src/debuginfo/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ use rustc_target::spec::DebuginfoKind;
2828
use smallvec::SmallVec;
2929
use tracing::debug;
3030

31-
use self::metadata::{UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, type_di_node};
31+
use self::metadata::{
32+
UNKNOWN_COLUMN_NUMBER, UNKNOWN_LINE_NUMBER, file_metadata, spanned_type_di_node, type_di_node,
33+
};
3234
use self::namespace::mangled_name_of_instance;
3335
use self::utils::{DIB, create_DIArray, is_node_local_to_unit};
3436
use crate::builder::Builder;
@@ -626,7 +628,7 @@ impl<'ll, 'tcx> DebugInfoCodegenMethods<'tcx> for CodegenCx<'ll, 'tcx> {
626628
let loc = self.lookup_debug_loc(span.lo());
627629
let file_metadata = file_metadata(self, &loc.file);
628630

629-
let type_metadata = type_di_node(self, variable_type);
631+
let type_metadata = spanned_type_di_node(self, variable_type, span);
630632

631633
let (argument_index, dwarf_tag) = match variable_kind {
632634
ArgumentVariable(index) => (index as c_uint, DW_TAG_arg_variable),

‎tests/ui/limits/huge-enum.stderr renamed to ‎tests/ui/limits/huge-enum.full-debuginfo.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: values of the type `Option<TYPE>` are too big for the target architecture
2-
--> $DIR/huge-enum.rs:15:9
2+
--> $DIR/huge-enum.rs:17:9
33
|
44
LL | let big: BIG = None;
55
| ^^^
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: values of the type `Option<TYPE>` are too big for the target architecture
2+
--> $DIR/huge-enum.rs:17:9
3+
|
4+
LL | let big: BIG = None;
5+
| ^^^
6+
7+
error: aborting due to 1 previous error
8+

‎tests/ui/limits/huge-enum.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
// FIXME(#61117): Remove revisions once x86_64-gnu-debug CI job sets rust.debuginfo-level-tests=2
2+
// NOTE: The .stderr for both revisions shall be identical.
3+
//@ revisions: no-debuginfo full-debuginfo
14
//@ build-fail
25
//@ normalize-stderr: "std::option::Option<\[u32; \d+\]>" -> "TYPE"
36
//@ normalize-stderr: "\[u32; \d+\]" -> "TYPE"
4-
5-
// FIXME(#61117): Respect debuginfo-level-tests, do not force debuginfo-level=0
6-
//@ compile-flags: -Cdebuginfo=0
7+
//@[no-debuginfo] compile-flags: -Cdebuginfo=0
8+
//@[full-debuginfo] compile-flags: -Cdebuginfo=2
79

810
#[cfg(target_pointer_width = "32")]
911
type BIG = Option<[u32; (1<<29)-1]>;

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /