Skip to content

[Regression] LLVM asserts "conflicting locations for variable" since 1.82 #131944

Closed

Description

@cuviper

Code

I tried this code: cargo itself, building release + debug=2
(multiple versions, but at the time of this report I have cargo cf53cc54bb593b5ec3dc2be4b1702f50c36d24d5)

I expected to see this happen: successful compilation

Instead, this happened:

In Fedora 39 builds (with its LLVM 17), rustc hits a libstdc++ assertion via LLVM:

/usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/optional:479: _Tp &std::_Optional_base_impl<llvm::DIExpression::FragmentInfo, std::_Optional_base<llvm::DIExpression::FragmentInfo>>::_M_get() [_Tp = llvm::DIExpression::FragmentInfo, _Dp = std::_Optional_base<llvm::DIExpression::FragmentInfo>]: Assertion 'this->_M_is_engaged()' failed.
rustc exited with signal: 6 (SIGABRT) (core dumped)

While investigating, I found that llc also crashes with the extracted IR:
https://bugzilla.redhat.com/show_bug.cgi?id=2226564#c10

In local builds with rust's LLVM 19 and assertions enabled, and also with CI "alt" builds, LLVM asserts "conflicting locations for variable":

.../cargo$ CARGO_PROFILE_RELEASE_DEBUG=2 cargo +e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt build --release
[...]
rustc: /checkout/src/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp:303: void llvm::Loc::MMI::addFrameIndexExpr(const DIExpression *, int): Assertion `(FrameIndexExprs.size() == 1 || llvm::all_of(FrameIndexExprs, [](const FrameIndexExpr &FIE) { return FIE.Expr && FIE.Expr->isFragment(); })) && "conflicting locations for variable"' failed.
error: could not compile `cargo` (lib)

Version it worked on

It most recently worked on: Rust 1.81.0

Version with regression

Rust 1.82.0, but at first it only crashed in my Fedora 39 build with LLVM 17. However, using the bundled rust-llvm with assertions enabled does trigger a debuginfo assertion.

Current nightly (e92993d) in alt mode reproduces this as well.

i.e. rustup-toolchain-install-master --alt e92993dbb43f0a5d17fe56e2d82f90435d6521c8

$ rustc +e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt -Vv
rustc 1.84.0-nightly (e92993dbb 2024-10-18)
binary: rustc
commit-hash: e92993dbb43f0a5d17fe56e2d82f90435d6521c8
commit-date: 2024-10-18
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1

Backtrace

(gdb) backtrace

#0  __pthread_kill_implementation (threadid=<optimized out>, signo=signo@entry=6, no_tid=no_tid@entry=0) at pthread_kill.c:44
#1  0x00007f70eb682793 in __pthread_kill_internal (threadid=<optimized out>, signo=6) at pthread_kill.c:78
#2  0x00007f70eb629d0e in __GI_raise (sig=sig@entry=6) at ../sysdeps/posix/raise.c:26
#3  0x00007f70eb611942 in __GI_abort () at abort.c:79
#4  0x00007f70eb61185e in __assert_fail_base (fmt=0x7f70eb7c5cb0 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n",
    assertion=assertion@entry=0x7f70db9545d4 <.L.str.70> "(FrameIndexExprs.size() == 1 || llvm::all_of(FrameIndexExprs, [](const FrameIndexExpr &FIE) { return FIE.Expr && FIE.Expr->isFragment(); })) && \"conflicting locations for variable\"",
    file=file@entry=0x7f70db8eb1f8 <str.67.llvm> "/checkout/src/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp", line=line@entry=303,
    function=function@entry=0x7f70db233d86 <.L__PRETTY_FUNCTION__._ZN4llvm3Loc3MMI17addFrameIndexExprEPKNS_12DIExpressionEi> "void llvm::Loc::MMI::addFrameIndexExpr(const DIExpression *, int)") at assert.c:94
#5  0x00007f70eb621e47 in __assert_fail (
    assertion=0x7f70db9545d4 <.L.str.70> "(FrameIndexExprs.size() == 1 || llvm::all_of(FrameIndexExprs, [](const FrameIndexExpr &FIE) { return FIE.Expr && FIE.Expr->isFragment(); })) && \"conflicting locations for variable\"",
    file=0x7f70db8eb1f8 <str.67.llvm> "/checkout/src/llvm-project/llvm/lib/CodeGen/AsmPrinter/DwarfDebug.cpp", line=303,
    function=0x7f70db233d86 <.L__PRETTY_FUNCTION__._ZN4llvm3Loc3MMI17addFrameIndexExprEPKNS_12DIExpressionEi> "void llvm::Loc::MMI::addFrameIndexExpr(const DIExpression *, int)") at assert.c:103
#6  0x00007f70e3710e95 in llvm::Loc::MMI::addFrameIndexExpr(llvm::DIExpression const*, int) [clone .cold] () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#7  0x00007f70e22f2086 in llvm::DwarfDebug::collectVariableInfoFromMFTable(llvm::DwarfCompileUnit&, llvm::DenseSet<std::pair<llvm::DINode const*, llvm::DILocation const*>, llvm::DenseMapInfo<std::pair<llvm::DINode const*, llvm::DILocation const*>, void> >&) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#8  0x00007f70e25914ab in llvm::DwarfDebug::collectEntityInfo(llvm::DwarfCompileUnit&, llvm::DISubprogram const*, llvm::DenseSet<std::pair<llvm::DINode const*, llvm::DILocation const*>, llvm::DenseMapInfo<std::pair<llvm::DINode const*, llvm::DILocation const*>, void> >&) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#9  0x00007f70e2592fe8 in llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#10 0x00007f70e267f0a4 in llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#11 0x00007f70e2bb6059 in llvm::AsmPrinter::emitFunctionBody() () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#12 0x00007f70e223d646 in llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#13 0x00007f70e2d7ac94 in llvm::FPPassManager::runOnFunction(llvm::Function&) [clone .warm] () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#14 0x00007f70e22d6376 in llvm::FPPassManager::runOnModule(llvm::Module&) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#15 0x00007f70e299f210 in llvm::legacy::PassManagerImpl::run(llvm::Module&) () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/libLLVM.so.19.1-rust-1.84.0-nightly
#16 0x00007f70e9f2aab2 in LLVMRustWriteOutputFile () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#17 0x00007f70e9f2a767 in rustc_codegen_llvm::back::write::write_output_file () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#18 0x00007f70e9ef1d5c in rustc_codegen_llvm::back::write::codegen () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#19 0x00007f70e9ef19e2 in rustc_codegen_ssa::back::write::finish_intra_module_work::<rustc_codegen_llvm::LlvmCodegenBackend> () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#20 0x00007f70ea003a36 in std::sys::backtrace::__rust_begin_short_backtrace::<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()> () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#21 0x00007f70ea000b28 in <<std::thread::Builder>::spawn_unchecked_<<rustc_codegen_llvm::LlvmCodegenBackend as rustc_codegen_ssa::traits::backend::ExtraBackendMethods>::spawn_named_thread<rustc_codegen_ssa::back::write::spawn_work<rustc_codegen_llvm::LlvmCodegenBackend>::{closure#0}, ()>::{closure#0}, ()>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} ()
   from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#22 0x00007f70ea000eeb in std::sys::pal::unix::thread::Thread::new::thread_start () from /home/jistone/.rustup/toolchains/e92993dbb43f0a5d17fe56e2d82f90435d6521c8-alt/lib/librustc_driver-a4eb0db55e024726.so
#23 0x00007f70eb680797 in start_thread (arg=<optimized out>) at pthread_create.c:447
#24 0x00007f70eb70478c in __GI___clone3 () at ../sysdeps/unix/sysv/linux/x86_64/clone3.S:78

I bisected this to #128861 (cc @khuey)

  • The assertion fails with 3139ff09e9d07f7700f8d15ed25a231e29c43627-alt (3139ff0)
  • Compilation succeeds with 026e9ed3f0c5b3ee6233fd23b5e497cb94cf6434-alt (its parent 026e9ed)

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged

Activity

  1. added
    C-bugCategory: This is a bug.
    I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.
    regression-untriagedUntriaged performance or correctness regression.
    on Oct 19, 2024
  2. added
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.
    and removed
    regression-untriagedUntriaged performance or correctness regression.
    on Oct 19, 2024
  3. added
    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.
    on Oct 19, 2024
  4. cuviper commented on Oct 19, 2024

    @cuviper
    MemberAuthor
  5. added
    T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.
    and removed
    needs-triageThis issue may need triage. Remove when done. See docs forge.rust-lang.org/release/issue-triaging
    on Oct 20, 2024
  6. khuey commented on Oct 21, 2024

    @khuey
    Contributor

    I can reproduce this. I haven't gotten to the bottom of it yet but I think it's an interaction between MIR inlining and an LLVM optimization (not clear to me yet whether it's SROA, inlining, or both). The final bitcode is obviously garbage. Seeing how the LLVM IR evolves through the passes would be helpful, if you can easily isolate that.

  7. apiraino commented on Oct 21, 2024

    @apiraino
    Contributor

    WG-prioritization assigning priority (Zulip discussion).

    @rustbot label -I-prioritize +P-critical

  8. added and removed
    I-prioritizeIssue needs a team member to assess the impact. Will be replaced by P-{low,medium,high,critical}
    on Oct 21, 2024
  9. 11 remaining items

  10. khuey commented on Nov 4, 2024

    @khuey
    Contributor

    @rustbot claim

  11. added a commit that references this issue on Nov 4, 2024
    4179b50
  12. added 5 commits that reference this issue on Nov 5, 2024
    6bc6e20
    9517283
    225656d
    49e1343
    02fd52b
  13. added a commit that references this issue on Nov 9, 2024
    1dc1061
  14. added a commit that references this issue on Nov 12, 2024
    5ec78ce
  15. added a commit that references this issue on Nov 20, 2024
  16. yuri-sevatz commented on Mar 6, 2025

    @yuri-sevatz

    @khuey The "conflicting locations for variable" bug might still be around in rust-1.84 and rust-1.85. A bunch of us on Gentoo are consistently hitting this same SIGABORT when compiling firefox with newer rust installs. It's always seemingly when running the exact same build step too, so it appears to be 100% reproducible.

    I managed to get a stacktrace here, not sure if this might explain what we're seeing more:

    https://bugs.gentoo.org/949280#c13

    Rust is a bit outside of my realm of expertise, but if you'd like us to try running anything else on the workdir right after it fails, we'll try and offer any evidence that we can.

  17. cuviper commented on Mar 7, 2025

    @cuviper
    MemberAuthor

    The way I reduced my original issue was to add -Csave-temps to the flags, and then look for the newest *.bc and *.o files in the build directory. There's often an empty file for the one that crashed, but before that there should be variations like *.no-opt.bc for the same name. If you capture all of those with the same prefix, that will hopefully be enough to reproduce the issue.

  18. jieyouxu commented on Mar 8, 2025

    @jieyouxu
    Member

    @khuey The "conflicting locations for variable" bug might still be around in rust-1.84 and rust-1.85. A bunch of us on Gentoo are consistently hitting this same SIGABORT when compiling firefox with newer rust installs. It's always seemingly when running the exact same build step too, so it appears to be 100% reproducible.

    I managed to get a stacktrace here, not sure if this might explain what we're seeing more:

    bugs.gentoo.org/949280#c13

    Rust is a bit outside of my realm of expertise, but if you'd like us to try running anything else on the workdir right after it fails, we'll try and offer any evidence that we can.

    Please use the new issue (#138198) for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.P-criticalCritical priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions