Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiler SIGSEGV When Compiling hartex-discord-worker #115156

Closed
HTGAzureX1212 opened this issue Aug 24, 2023 · 10 comments · Fixed by #115232
Closed

Compiler SIGSEGV When Compiling hartex-discord-worker #115156

HTGAzureX1212 opened this issue Aug 24, 2023 · 10 comments · Fixed by #115232
Labels
A-codegen Area: Code generation A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@HTGAzureX1212
Copy link
Contributor

My current attempts to compile my project, discord-frontend, fails with the hartex-discord-worker crate (the following output comes from GitHub Actions CI):

/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x3130563)[0x7f5c1fdad563]
/lib/x86_64-linux-gnu/libc.so.6( 0x42520)[0x7f5c1c8df520]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so( 0x695253b)[0x7f5c1995253b]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so( 0x6974d85)[0x7f5c19974d85]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit24constructVariableDIEImplERKNS_11DbgVariableEb 0x1e5f)[0x7f5c1920a61f]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x174)[0x7f5c192042b4]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit25createAndAddScopeChildrenEPNS_12LexicalScopeERNS_3DIEE 0x7c7)[0x7f5c19204907]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DwarfCompileUnit27constructSubprogramScopeDIEEPKNS_12DISubprogramEPNS_12LexicalScopeE 0xe9)[0x7f5c1920793f]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm10DwarfDebug15endFunctionImplEPKNS_15MachineFunctionE 0x246)[0x7f5c19202386]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm16DebugHandlerBase11endFunctionEPKNS_15MachineFunctionE 0x5e)[0x7f5c194c7ede]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm10AsmPrinter16emitFunctionBodyEv 0x29e9)[0x7f5c19169629]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so( 0x6166bf2)[0x7f5c19166bf2]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE 0xb1c)[0x7f5c18f6b3dc]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM-17-rust-1.74.0-nightly.so(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE 0x266)[0x7f5c1939a06e]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26e46e6)[0x7f5c1f3616e6]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26e3598)[0x7f5c1f360598]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26e0b8b)[0x7f5c1f35db8b]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26dd984)[0x7f5c1f35a984]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26db3e9)[0x7f5c1f3583e9]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-00c03654e9ecf095.so( 0x26673f6)[0x7f5c1f2e43f6]
/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libstd-19964a87984cce8a.so(rust_metadata_std_3de2780fbf87294b 0x10c425)[0x7f5c1cbee425]
/lib/x86_64-linux-gnu/libc.so.6( 0x94b43)[0x7f5c1c931b43]
/lib/x86_64-linux-gnu/libc.so.6( 0x126a00)[0x7f5c1c9c3a00]
error: could not compile `hartex_discord_worker` (bin "hartex_discord_worker")

Caused by:
  process didn't exit successfully: `/home/runner/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/bin/rustc --crate-name hartex_discord_worker --edition=2021 hartex-discord-worker/src/main.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat --crate-type bin --emit=dep-info,link -C opt-level=3 -C lto -C debuginfo=2 -C metadata=f59fa0bdd95c617d -C extra-filename=-f59fa0bdd95c617d --out-dir /home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps -L dependency=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps --extern chrono=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libchrono-648d11e3fa899d27.rlib --extern futures_util=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libfutures_util-e999fdc95fe7a99c.rlib --extern hartex_discord_commands=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_commands-cc51a29af88b6a75.rlib --extern hartex_discord_commands_core=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_commands_core-f3856b2dd71d1097.rlib --extern hartex_discord_core=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_core-bf2515b7ba4e43e0.rlib --extern hartex_discord_entitycache_cacheupdaters=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_entitycache_cacheupdaters-fb74303614849e6b.rlib --extern hartex_discord_entitycache_core=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_entitycache_core-83f72849f9449b9c.rlib --extern hartex_discord_utils=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_discord_utils-955e6f9c3a31a5ca.rlib --extern hartex_kafka_utils=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_kafka_utils-b7063b620b04f3be.rlib --extern hartex_log=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libhartex_log-ac1beba8b3cd4dfc.rlib --extern miette=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libmiette-a8f89bdfd704a7bf.rlib --extern once_cell=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libonce_cell-1e999b721ef15030.rlib --extern rdkafka=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/librdkafka-31b874f6c5386916.rlib --extern serde=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libserde-1a78f3c499e50d58.rlib --extern serde_json=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libserde_json-9847bb4128882422.rlib --extern serde_scan=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libserde_scan-59766ed54e814829.rlib --extern sqlx=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libsqlx-6e42040f5f9ae6a5.rlib --extern time=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libtime-0e6513f6e4d5781a.rlib --extern tracing=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/deps/libtracing-2627174e285ac941.rlib -C target-cpu=native -L native=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/build/ring-514d3ae34146361b/out -L native=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/build/rdkafka-sys-47d50d168ca65131/out/lib -L native=/home/runner/work/HarTex/HarTex/discord-frontend/target/release/build/lz4-sys-f2deb4eb4f71f0b8/out` (signal: 11, SIGSEGV: invalid memory reference)
warning: build failed, waiting for other jobs to finish...

I expected to see this happen: project to be compiled successfully

Instead, this happened: the compiler exited with SIGSEGV, as shown from output above.

Meta

rustc --version --verbose:

rustc 1.74.0-nightly (249595b75 2023-08-23)
binary: rustc
commit-hash: 249595b7523fc07a99c1adee90b1947739ca0e5b
commit-date: 2023-08-23
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

P.S. I have tested this on my local Windows machine, with the following version information, in which the compilation works fine:

rustc 1.74.0-nightly (249595b75 2023-08-23)
binary: rustc
commit-hash: 249595b7523fc07a99c1adee90b1947739ca0e5b
commit-date: 2023-08-23
host: x86_64-pc-windows-msvc
release: 1.74.0-nightly
LLVM version: 17.0.0

It seems like the segfault is only reproducible on Linux, but not Windows (I have personally not tested this on macOS, as I don't have an Apple machine at my disposal).

@HTGAzureX1212 HTGAzureX1212 added the C-bug Category: This is a bug. label Aug 24, 2023
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Aug 24, 2023
@HTGAzureX1212
Copy link
Contributor Author

Shower thought: could this have happened during LLVM code generaiton? There are a lot of libLLVM frames in the segfault "backtrace" thing,

@saethlin
Copy link
Member

Duplicate of #115113 (probably)

@tmiasko
Copy link
Contributor

tmiasko commented Aug 24, 2023

I bisected what appears to be the same issue to #114643 (I can reproduce it without MIR SROA, and the issue disappears with #114643 reverted).

cc @dpaoliello, @wesleywiser

@tmiasko tmiasko added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-codegen Area: Code generation E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Aug 24, 2023
@tmiasko
Copy link
Contributor

tmiasko commented Aug 24, 2023

Not a reproducer for LLVM crash, but demonstrates dubious debuginfo codegen:

#![feature(decl_macro)]
macro a() {{{ let _x = [0u64; 4]; }}}
macro b() {{{ a!(); a!(); a!(); }}}
pub fn main() {
    b!();
}

With MIR:

fn main() -> () {
    let mut _0: ();
    let _1: [u64; 4];
    let _2: [u64; 4];
    let _3: [u64; 4];
    scope 1 {
        debug _x => _1;
    }
    scope 2 {
        debug _x => _2;
    }
    scope 3 {
        debug _x => _3;
    }

    bb0: {
        _1 = [const 0_u64; 4];
        _2 = [const 0_u64; 4];
        _3 = [const 0_u64; 4];
        return;
    }
}

Compiled with rustc a.rs --crate-type=lib -Cno-prepopulate-passes -g --emit llvm-ir, emits following LLVM IR where all three lexical blocks and variables within are merged together:

; a::main
; Function Attrs: nonlazybind uwtable
define void @_ZN1a4main17hf6d320809b93b618E() unnamed_addr #0 !dbg !7 {
start:
  %_x2 = alloca [4 x i64], align 8
  %_x1 = alloca [4 x i64], align 8
  %_x = alloca [4 x i64], align 8
  call void @llvm.dbg.declare(metadata ptr %_x, metadata !13, metadata !DIExpression()), !dbg !20
  call void @llvm.dbg.declare(metadata ptr %_x1, metadata !13, metadata !DIExpression()), !dbg !20
  call void @llvm.dbg.declare(metadata ptr %_x2, metadata !13, metadata !DIExpression()), !dbg !20

@apiraino

This comment was marked as off-topic.

@rustbot rustbot removed the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Aug 25, 2023
@tmiasko
Copy link
Contributor

tmiasko commented Aug 25, 2023

@apiraino as indicated in #115156 (comment), this is a distinct issue that will be fixed by neither #115139 nor #115140.

@apiraino
Copy link
Contributor

@tmiasko sorry for my confusing comment and thanks for the correction. By reading your comment I didn't clearly understand it was contradicting the previous one.

@HTGAzureX1212
Copy link
Contributor Author

HTGAzureX1212 commented Aug 26, 2023

The fix PR has not been merged, but for some reason rustc did not segfault on CI as of today.

Metadata:

rustc 1.74.0-nightly (734a0d0aa 2023-08-25)
binary: rustc
commit-hash: 734a0d0aa0d5cab60f94f6d0c6a014dae12915f1
commit-date: 2023-08-25
host: x86_64-unknown-linux-gnu
release: 1.74.0-nightly
LLVM version: 17.0.0

@bors bors closed this as completed in 42857db Aug 26, 2023
@tmiasko
Copy link
Contributor

tmiasko commented Aug 26, 2023

Ah, in that case I would also add that building helix editor with debuginfo=2 quite reliably reproduced the crash for me:

$ git clone https://github.com/helix-editor/helix
$ cd helix
$ git reset --hard c9694f680f97823ac9b893239a78bf45bfee0403
$ env RUSTFLAGS='-g' cargo  nightly build --release

As far change itself is concerned, my impression is that implementing this would require an additional scope identifiers that would be preserved after MIR inlining.

@dpaoliello
Copy link
Contributor

When I repro this bug, what I'm seeing in the IR is:

  %self27.i.i.sroa.19.i.i.sroa.6.sroa.7 = alloca [32 x i8], align 1
  call void @llvm.dbg.declare(metadata ptr %self27.i.i.sroa.19.i.i.sroa.6.sroa.7, metadata !1082139, metadata !DIExpression(DW_OP_LLVM_fragment, 256, 256)), !dbg !1082162

Then, later (in the frame setup of the same function):

  %self10.sroa.18.i.i.i.i.sroa.6.sroa.7 = alloca [32 x i8], align 1
  call void @llvm.dbg.declare(metadata ptr %self10.sroa.18.i.i.i.i.sroa.6.sroa.7, metadata !1082139, metadata !DIExpression(DW_OP_LLVM_fragment, 256, 256)), !dbg !1082162

So LLVM is complaining about having two DW_OP_LLVM_fragment expressions for the same debug variable (metadata !1082139) that are overlapping.

As far change itself is concerned, my impression is that implementing this would require an additional scope identifiers that would be preserved after MIR inlining.

I think this would be a reasonable workaround, as it would allow separate debug variable declarations instead of trying to de-dupe those as well. However, I don't know enough about LLVM to know if that is a hacky workaround or the correct way to generate this code (from my experiments with Clang, it seems to de-dupe debug variable declarations).

bors added a commit to rust-lang-ci/rust that referenced this issue Sep 8, 2023
Use the same DISubprogram for each instance of the same inlined function within a caller

# Issue Details:
The call to `panic` within a function like `Option::unwrap` is translated to LLVM as a `tail call` (as it will never return), when multiple calls to the same function like this are inlined LLVM will notice the common `tail call` block (i.e., loading the same panic string   location info and then calling `panic`) and merge them together.

When merging these instructions together, LLVM will also attempt to merge the debug locations as well, but this fails (i.e., debug info is dropped) as Rust emits a new `DISubprogram` at each inline site thus LLVM doesn't recognize that these are actually the same function and so thinks that there isn't a common debug location.

As an example of this, consider the following program:
```rust
#[no_mangle]
fn add_numbers(x: &Option<i32>, y: &Option<i32>) -> i32 {
    let x1 = x.unwrap();
    let y1 = y.unwrap();

    x1   y1
}
```

 When building for x86_64 Windows using 1.72 it generates (note the lack of `.cv_loc` before the call to `panic`, thus it will be attributed to the same line at the `addq` instruction):

```llvm
	.cv_loc	0 1 3 0                        # src\lib.rs:3:0
	addq	$40, %rsp
	retq
	leaq	.Lalloc_f570dea0a53168780ce9a91e67646421(%rip), %rcx
	leaq	.Lalloc_629ace53b7e5b76aaa810d549cc84ea3(%rip), %r8
	movl	$43, �x
	callq	_ZN4core9panicking5panic17h12e60b9063f6dee8E
	int3
```

# Fix Details:
Cache the `DISubprogram` emitted for each inlined function instance within a caller so that this can be reused if that instance is encountered again.

Ideally, we would also deduplicate child scopes and variables, however my attempt to do that with rust-lang#114643 resulted in asserts when building for Linux (rust-lang#115156) which would require some deep changes to Rust to fix (rust-lang#115455).

Instead, when using an inlined function as a debug scope, we will also create a new child scope such that subsequent child scopes and variables do not collide (from LLVM's perspective).

After this change the above assembly now (with <https://reviews.llvm.org/D159226> as well) shows the `panic!` was inlined from `unwrap` in `option.rs` at line 935 into the current function in `lib.rs` at line 0 (line 0 is emitted since it is ambiguous which line to use as there were two inline sites that lead to this same code):

```llvm
	.cv_loc	0 1 3 0                        # src\lib.rs:3:0
	addq	$40, %rsp
	retq
	.cv_inline_site_id 6 within 0 inlined_at 1 0 0
	.cv_loc	6 2 935 0                       # library\core\src\option.rs:935:0
	leaq	.Lalloc_5f55955de67e57c79064b537689facea(%rip), %rcx
	leaq	.Lalloc_e741d4de8cb5801e1fd7a6c6795c1559(%rip), %r8
	movl	$43, �x
	callq	_ZN4core9panicking5panic17hde1558f32d5b1c04E
	int3
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-codegen Area: Code generation A-debuginfo Area: Debugging information in compiled programs (DWARF, PDB, etc.) A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. E-needs-mcve Call for participation: This issue has a repro, but needs a Minimal Complete and Verifiable Example I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
6 participants