forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#135643 - khuey:135332, r=jieyouxu
When LLVM's location discriminator value limit is exceeded, emit locations with dummy spans instead of dropping them entirely Dropping them fails `-Zverify-llvm-ir`. Fixes rust-lang#135332. r? `@jieyouxu`
- Loading branch information
Showing
8 changed files
with
111 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
tests/run-make/llvm-location-discriminator-limit-dummy-span/main.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
fn main() { | ||
other::big_function(); | ||
} |
1 change: 1 addition & 0 deletions
1
tests/run-make/llvm-location-discriminator-limit-dummy-span/other.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
proc::declare_big_function!(); |
7 changes: 7 additions & 0 deletions
7
tests/run-make/llvm-location-discriminator-limit-dummy-span/proc.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
extern crate proc_macro; | ||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro] | ||
pub fn declare_big_function(_input: TokenStream) -> TokenStream { | ||
include_str!("./generated.rs").parse().unwrap() | ||
} |
65 changes: 65 additions & 0 deletions
65
tests/run-make/llvm-location-discriminator-limit-dummy-span/rmake.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//! Regression test for </~https://github.com/rust-lang/rust/issues/135332>. | ||
//! | ||
//! We can't simply drop debuginfo location spans when LLVM's location discriminator value limit is | ||
//! reached. Otherwise, with `-Z verify-llvm-ir` and fat LTO, LLVM will report a broken module for | ||
//! | ||
//! ```text | ||
//! inlinable function call in a function with debug info must have a !dbg location | ||
//! ``` | ||
//@ ignore-cross-compile | ||
//@ needs-dynamic-linking | ||
//@ only-nightly (requires unstable rustc flag) | ||
|
||
#![deny(warnings)] | ||
|
||
use run_make_support::{dynamic_lib_name, rfs, rust_lib_name, rustc}; | ||
|
||
// Synthesize a function that will have a large (`n`) number of functions | ||
// MIR-inlined into it. When combined with a proc-macro, all of these inline | ||
// callsites will have the same span, forcing rustc to use the DWARF | ||
// discriminator to distinguish between them. LLVM's capacity to store that | ||
// discriminator is not infinite (currently it allocates 12 bits for a | ||
// maximum value of 4096) so if this function gets big enough rustc's error | ||
// handling path will be exercised. | ||
fn generate_program(n: u32) -> String { | ||
let mut program = String::from("pub type BigType = Vec<Vec<String>>;\n\n"); | ||
program.push_str("pub fn big_function() -> BigType {\n"); | ||
program.push_str(" vec![\n"); | ||
for i in 1..=n { | ||
program.push_str(&format!("vec![\"string{}\".to_owned()],\n", i)); | ||
} | ||
program.push_str(" ]\n"); | ||
program.push_str("}\n"); | ||
program | ||
} | ||
|
||
fn main() { | ||
// The reported threshold is around 1366 (4096/3), but let's bump it to | ||
// around 1500 to be less sensitive. | ||
rfs::write("generated.rs", generate_program(1500)); | ||
|
||
rustc() | ||
.input("proc.rs") | ||
.crate_type("proc-macro") | ||
.edition("2021") | ||
.arg("-Cdebuginfo=line-tables-only") | ||
.run(); | ||
rustc() | ||
.extern_("proc", dynamic_lib_name("proc")) | ||
.input("other.rs") | ||
.crate_type("rlib") | ||
.edition("2021") | ||
.opt_level("3") | ||
.arg("-Cdebuginfo=line-tables-only") | ||
.run(); | ||
rustc() | ||
.extern_("other", rust_lib_name("other")) | ||
.input("main.rs") | ||
.edition("2021") | ||
.opt_level("3") | ||
.arg("-Cdebuginfo=line-tables-only") | ||
.arg("-Clto=fat") | ||
.arg("-Zverify-llvm-ir") | ||
.run(); | ||
} |