From b3067494e8a53f0d4151357b00a4ebc42f043121 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Tue, 18 Apr 2023 04:01:09 +0300 Subject: [PATCH] decorations: limit zombie `SerializedSpan`s to an `OpLine` equivalent. --- crates/rustc_codegen_spirv/src/decorations.rs | 20 +++++++------------ tests/ui/dis/ptr_copy.normal.stderr | 2 +- .../consts/nested-ref-in-composite.stderr | 4 ++-- 3 files changed, 10 insertions(+), 16 deletions(-) diff --git a/crates/rustc_codegen_spirv/src/decorations.rs b/crates/rustc_codegen_spirv/src/decorations.rs index 2a317ecc7a..322d3067dc 100644 --- a/crates/rustc_codegen_spirv/src/decorations.rs +++ b/crates/rustc_codegen_spirv/src/decorations.rs @@ -139,8 +139,9 @@ impl CustomDecoration for ZombieDecoration { #[derive(Deserialize, Serialize)] pub struct SerializedSpan { file_name: String, + // NOTE(eddyb) by keeping `lo` but not `hi`, we mimick `OpLine` limitations + // (which could be lifted in the future using custom SPIR-T debuginfo). lo: u32, - hi: u32, } impl SerializedSpan { @@ -151,14 +152,10 @@ impl SerializedSpan { return None; } - let (lo, hi) = (span.lo(), span.hi()); - if lo > hi { - // FIXME(eddyb) broken `Span` - potentially turn this into an assert? - return None; - } + let lo = span.lo(); let file = builder.source_map.lookup_source_file(lo); - if !(file.start_pos <= lo && hi <= file.end_pos) { + if !(file.start_pos..=file.end_pos).contains(&lo) { // FIXME(eddyb) broken `Span` - potentially turn this into an assert? return None; } @@ -169,7 +166,6 @@ impl SerializedSpan { Some(Self { file_name: file.name.prefer_remapped().to_string(), lo: (lo - file.start_pos).to_u32(), - hi: (hi - file.start_pos).to_u32(), }) } } @@ -296,11 +292,9 @@ impl<'a> SpanRegenerator<'a> { // Sanity check - assuming `SerializedSpan` isn't corrupted, this assert // could only ever fail because of the file name being ambiguous. - assert!(span.lo <= span.hi && span.hi <= (file.end_pos.0 - file.start_pos.0)); + assert!(span.lo <= (file.end_pos.0 - file.start_pos.0)); - Some(Span::with_root_ctxt( - file.start_pos + Pos::from_u32(span.lo), - file.start_pos + Pos::from_u32(span.hi), - )) + let lo = file.start_pos + Pos::from_u32(span.lo); + Some(Span::with_root_ctxt(lo, lo)) } } diff --git a/tests/ui/dis/ptr_copy.normal.stderr b/tests/ui/dis/ptr_copy.normal.stderr index c9f66e2d67..2e27465411 100644 --- a/tests/ui/dis/ptr_copy.normal.stderr +++ b/tests/ui/dis/ptr_copy.normal.stderr @@ -2,7 +2,7 @@ error: Cannot memcpy dynamically sized data --> $CORE_SRC/intrinsics.rs:2460:9 | 2460 | copy(src, dst, count) - | ^^^^^^^^^^^^^^^^^^^^^ + | ^ | = note: Stack: core::intrinsics::copy:: diff --git a/tests/ui/lang/consts/nested-ref-in-composite.stderr b/tests/ui/lang/consts/nested-ref-in-composite.stderr index 0844de7a6b..9f5c2a7aba 100644 --- a/tests/ui/lang/consts/nested-ref-in-composite.stderr +++ b/tests/ui/lang/consts/nested-ref-in-composite.stderr @@ -2,7 +2,7 @@ error: constant arrays/structs cannot contain pointers to other constants --> $DIR/nested-ref-in-composite.rs:20:17 | 20 | *pair_out = pair_deep_load(&(&123, &3.14)); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ | = note: Stack: nested_ref_in_composite::main_pair @@ -12,7 +12,7 @@ error: constant arrays/structs cannot contain pointers to other constants --> $DIR/nested-ref-in-composite.rs:25:19 | 25 | *array3_out = array3_deep_load(&[&0, &1, &2]); - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ^ | = note: Stack: nested_ref_in_composite::main_array3