about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-02-08 21:28:05 +0000
committerbors <bors@rust-lang.org>2020-02-08 21:28:05 +0000
commita19edd6b161521a4f66716b3b45b8cf4d3f03f3a (patch)
tree703b6fe5ddb3c85e5b21279a0c82ca8e098668a8 /src
parent07a34df18b437319a7ff510077bbab95cf7ec6bc (diff)
parent80515f7528efd2921e474d932755b823eee6f53b (diff)
downloadrust-a19edd6b161521a4f66716b3b45b8cf4d3f03f3a.tar.gz
rust-a19edd6b161521a4f66716b3b45b8cf4d3f03f3a.zip
Auto merge of #68802 - eddyb:debuginfo-there-can-only-be-one-arg, r=nagisa
rustc_codegen_ssa: don't treat inlined variables as debuginfo arguments.

Fixes #67586 by limiting `ArgumentVariable` special-casing to `VarDebugInfo` entries that are in `OUTERMOST_SOURCE_SCOPE`, i.e. the function's own argument scope.
That excludes `VarDebugInfo` from inlined callees, which can also point to the caller's argument locals.

This is a snippet from the optimized MIR (including inlining) of the testcase:
```rust
fn  foo(_1: usize) -> usize {
    debug bar => _1;                     // in scope 0 at ./example.rs:2:12: 2:15
    let mut _0: usize;                   // return place in scope 0 at ./example.rs:2:27: 2:32
    scope 1 {
        debug x => _1;                   // in scope 1 at /rustc/9ed29b6ff6aa2e048b09c27af8f62ee3040bdb37/src/libcore/convert/mod.rs:106:26: 106:27
    }
```
`scope 1` is from inlining the `identity` call, and `debug x => _1;` comes from the body of `core::convert::identity`, so they are now ignored for the purposes of determining the `ArgumentVariable` debuginfo associated to `_1`.
Diffstat (limited to 'src')
-rw-r--r--src/librustc_codegen_ssa/mir/debuginfo.rs5
-rw-r--r--src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs11
2 files changed, 12 insertions, 4 deletions
diff --git a/src/librustc_codegen_ssa/mir/debuginfo.rs b/src/librustc_codegen_ssa/mir/debuginfo.rs
index f66496d10fb..9cba77b7298 100644
--- a/src/librustc_codegen_ssa/mir/debuginfo.rs
+++ b/src/librustc_codegen_ssa/mir/debuginfo.rs
@@ -307,11 +307,8 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
                 let var_ty = self.monomorphized_place_ty(place.as_ref());
                 let var_kind = if self.mir.local_kind(place.local) == mir::LocalKind::Arg
                     && place.projection.is_empty()
+                    && var.source_info.scope == mir::OUTERMOST_SOURCE_SCOPE
                 {
-                    // FIXME(eddyb, #67586) take `var.source_info.scope` into
-                    // account to avoid using `ArgumentVariable` more than once
-                    // per argument local.
-
                     let arg_index = place.local.index() - 1;
 
                     // FIXME(eddyb) shouldn't `ArgumentVariable` indices be
diff --git a/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs b/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs
new file mode 100644
index 00000000000..23cc114880c
--- /dev/null
+++ b/src/test/ui/mir/mir-inlining/var-debuginfo-issue-67586.rs
@@ -0,0 +1,11 @@
+// run-pass
+// compile-flags: -Z mir-opt-level=2 -C opt-level=0 -C debuginfo=2
+
+#[inline(never)]
+pub fn foo(bar: usize) -> usize {
+    std::convert::identity(bar)
+}
+
+fn main() {
+    foo(0);
+}