forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
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#132613 - khuey:master, r=<try>
Add discriminators to DILocations when multiple functions are inlined into a single point. LLVM does not expect to ever see multiple dbg_declares for the same variable at the same location with different values. proc-macros make it possible for arbitrary code, including multiple calls that get inlined, to happen at any given location in the source code. Add discriminators when that happens so these locations are different to LLVM. This may interfere with the AddDiscriminators pass in LLVM, which is added by the unstable flag -Zdebug-info-for-profiling. Fixes rust-lang#131944
- Loading branch information
Showing
6 changed files
with
130 additions
and
4 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
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,10 @@ | ||
//@ no-prefer-dynamic | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
use proc_macro::*; | ||
|
||
#[proc_macro] | ||
pub fn square_twice(_item: TokenStream) -> TokenStream { | ||
"(square(env::vars().count() as i32), square(env::vars().count() as i32))".parse().unwrap() | ||
} |
51 changes: 51 additions & 0 deletions
51
tests/codegen/debuginfo-proc-macro/mir_inlined_twice_var_locs.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,51 @@ | ||
//@ min-llvm-version: 19 | ||
//@ compile-flags: -Cdebuginfo=2 -Copt-level=0 -Zmir-enable-passes=+Inline | ||
|
||
//@ aux-build:macro_def.rs | ||
|
||
// Find the variable. | ||
// CHECK-DAG: ![[#var_dbg:]] = !DILocalVariable(name: "n",{{( arg: 1,)?}} scope: ![[#var_scope:]] | ||
|
||
// Find both dbg_declares. These will proceed the variable metadata, of course, so we're looking | ||
// backwards. | ||
// CHECK-DAG: dbg_declare(ptr %n.dbg.spill3, ![[#var_dbg]], !DIExpression(), ![[#var_loc2:]]) | ||
// CHECK-DAG: dbg_declare(ptr %n.dbg.spill, ![[#var_dbg]], !DIExpression(), ![[#var_loc1:]]) | ||
|
||
// Find the first location definition, looking forwards again. | ||
// CHECK: ![[#var_loc1]] = !DILocation | ||
// CHECK-SAME: scope: ![[#var_scope:]], inlinedAt: ![[#var_inlinedAt1:]] | ||
|
||
// Find the first location's inlinedAt | ||
// NB: If we fail here it's *probably* because we failed to produce two | ||
// different locations and ended up reusing an earlier one. | ||
// CHECK: ![[#var_inlinedAt1]] = !DILocation | ||
// CHECK-SAME: scope: ![[var_inlinedAt1_scope:]] | ||
|
||
// Find the second location definition, still looking forwards. | ||
// NB: If we failed to produce two different locations, the test will | ||
// definitely fail by this point (if it hasn't already) because we won't | ||
// be able to find the same line again. | ||
// CHECK: ![[#var_loc2]] = !DILocation | ||
// CHECK-SAME: scope: ![[#var_scope]], inlinedAt: ![[#var_inlinedAt2:]] | ||
|
||
// Find the second location's inlinedAt. | ||
// CHECK: ![[#var_inlinedAt2]] = !DILocation | ||
// CHECK-SAME: scope: ![[#var_inlinedAt2_scope:]] | ||
|
||
// Finally, check that a discriminator was emitted for the second scope. | ||
// FIXMEkhuey ideally we would check that *either* scope has a discriminator | ||
// but I don't know that it's possible to check that with FileCheck. | ||
// CHECK: ![[#var_inlinedAt2_scope]] = !DILexicalBlockFile | ||
// CHECK-SAME: discriminator: [[#]] | ||
extern crate macro_def; | ||
|
||
use std::env; | ||
|
||
fn square(n: i32) -> i32 { | ||
n * n | ||
} | ||
|
||
fn main() { | ||
let (z1, z2) = macro_def::square_twice!(); | ||
println!("{z1} == {z2}"); | ||
} |