Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2426,14 +2426,12 @@ impl SourceFile {
/// normalized one. Hence we need to convert those offsets to the normalized
/// form when constructing spans.
pub fn normalized_byte_pos(&self, offset: u32) -> BytePos {
let diff = match self
.normalized_pos
.binary_search_by(|np| (np.pos.0 + np.diff).cmp(&(self.start_pos.0 + offset)))
{
Ok(i) => self.normalized_pos[i].diff,
Err(0) => 0,
Err(i) => self.normalized_pos[i - 1].diff,
};
let diff =
match self.normalized_pos.binary_search_by(|np| (np.pos.0 + np.diff).cmp(&offset)) {
Ok(i) => self.normalized_pos[i].diff,
Err(0) => 0,
Err(i) => self.normalized_pos[i - 1].diff,
};

BytePos::from_u32(self.start_pos.0 + offset - diff)
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/compiletest/src/directives/needs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ pub(super) fn handle_needs(
}

// Handled elsewhere.
if name == "needs-llvm-components" {
if name == "needs-llvm-components" || name == "needs-backends" {
return IgnoreDecision::Continue;
}

Expand Down
1 change: 1 addition & 0 deletions src/tools/tidy/src/ui_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ fn check_unexpected_extension(check: &mut RunningCheck, file_path: &Path, ext: &

const EXTENSION_EXCEPTION_PATHS: &[&str] = &[
"tests/ui/asm/named-asm-labels.s", // loading an external asm file to test named labels lint
"tests/ui/asm/normalize-offsets-for-crlf.s", // loading an external asm file to test CRLF normalization
"tests/ui/codegen/mismatched-data-layout.json", // testing mismatched data layout w/ custom targets
"tests/ui/check-cfg/my-awesome-platform.json", // testing custom targets with cfgs
"tests/ui/argfile/commandline-argfile-badutf8.args", // passing args via a file
Expand Down
2 changes: 2 additions & 0 deletions tests/ui/asm/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Disable EOL normalization, as it is deliberately denormalized
normalize-offsets-for-crlf.s -text
14 changes: 14 additions & 0 deletions tests/ui/asm/normalize-offsets-for-crlf.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Byte positions into inline assembly reported by codegen errors require normalization or else
// they may not identify the appropriate span. Worse still, an ICE can occur if the erroneous
// span begins or ends part-way through a multibyte character.
//
// Regression test for https://github.com/rust-lang/rust/issues/110885

// This test is tied to assembler syntax and errors, which can vary by backend and architecture.
//@only-x86_64
//@needs-backends: llvm
//@build-fail

//~? ERROR instruction mnemonic
std::arch::global_asm!(include_str!("normalize-offsets-for-crlf.s"));
fn main() {}
13 changes: 13 additions & 0 deletions tests/ui/asm/normalize-offsets-for-crlf.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// This file contains (some) CRLF line endings. When codegen reports an error, the byte
// offsets into this file that it identifies require normalization or else they will not
// identify the appropriate span. Worse still, an ICE can result if the erroneous span
// begins or ends part-way through a multibyte character such as £.
non_existent_mnemonic

// Without normalization, the three CRLF line endings below cause the diagnostic on the
// `non_existent_mnemonic` above to be spanned three bytes backward, and thus begin
// part-way inside the multibyte character in the preceding comment.
//
// NOTE: The lines of this note DELIBERATELY end with CRLF - DO NOT strip/convert them!
// It may not be obvious if you accidentally do, eg `git diff` may appear to show
// that the lines have been updated to the exact same content.
10 changes: 10 additions & 0 deletions tests/ui/asm/normalize-offsets-for-crlf.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
error: invalid instruction mnemonic 'non_existent_mnemonic'
|
note: instantiated into assembly here
--> <inline asm>:6:1
|
LL | non_existent_mnemonic
| ^^^^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

Loading