llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
29.11k stars 12.01k forks source link

LiveDebugValues crashes in (anonymous namespace)::LiveDebugValues::accumulateFragmentMap( #45431

Closed llvmbot closed 4 years ago

llvmbot commented 4 years ago
Bugzilla Link 46086
Resolution FIXED
Resolved on Jun 17, 2020 13:06
Version trunk
OS All
Attachments MIR before LiveDebugValues
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@JDevlieghere,@jmorse,@walkerkd,@pogo59

Extended Description

$ ./llc -run-pass=livedebugvalues foo.mir

PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace. Stack dump:

  1. Program arguments: ./llc -run-pass=livedebugvalues foo.mir
  2. Running pass 'Function Pass Manager' on module 'foo.mir'.
  3. Running pass 'Live DEBUG_VALUE analysis' on function '@_Z3barii' 0 llc 0x000000010e83a23a llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 58 1 llc 0x000000010e83a779 PrintStackTraceSignalHandler(void) + 25 2 llc 0x000000010e83869b llvm::sys::RunSignalHandlers() + 123 3 llc 0x000000010e83c4e9 SignalHandler(int) + 249 4 libsystem_platform.dylib 0x00007fff7223355d _sigtramp + 29 5 llc 0x000000010d1c1475 llvm::SmallPtrSet<llvm::MachineBasicBlock const, 8u>::~SmallPtrSet() + 21 6 llc 0x000000010da82aaf llvm::DILocation::getRawInlinedAt() const + 31 7 llc 0x000000010da8f765 llvm::DILocation::getInlinedAt() const + 21 8 llc 0x000000010cfe5934 (anonymous namespace)::LiveDebugValues::accumulateFragmentMap(llvm::MachineInstr&, llvm::DenseMap<llvm::DILocalVariable const, llvm::SmallSet<llvm::DIExpression::FragmentInfo, 4u, std::__1::less >, llvm::DenseMapInfo<llvm::DILocalVariable const>, llvm::detail::DenseMapPair<llvm::DILocalVariable const, llvm::SmallSet<llvm::DIExpression::FragmentInfo, 4u, std::1::less > > >&, llvm::DenseMap<std::1::pair<llvm::DILocalVariable const, llvm::DIExpression::FragmentInfo>, llvm::SmallVector<llvm::DIExpression::FragmentInfo, 1u>, llvm::DenseMapInfo<std::1::pair<llvm::DILocalVariable const*, llvm::DIExpression::FragmentInfo> >, llvm::detail::DenseMapPair<std::1::pair<llvm::DILocalVariable const*, llvm::DIExpression::FragmentInfo>, llvm::SmallVector<llvm::DIExpression::FragmentInfo, 1u> > >&) + 84 9 llc 0x000000010cfe4655 (anonymous namespace)::LiveDebugValues::ExtendRanges(llvm::MachineFunction&) + 965 10 llc 0x000000010cfe2359 (anonymous namespace)::LiveDebugValues::runOnMachineFunction(llvm::MachineFunction&) + 265 11 llc 0x000000010d18df6d llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 541 12 llc 0x000000010d95fe4c llvm::FPPassManager::runOnFunction(llvm::Function&) + 700 13 llc 0x000000010d960445 llvm::FPPassManager::runOnModule(llvm::Module&) + 117 14 llc 0x000000010d960bc4 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) + 772 15 llc 0x000000010d9606e8 llvm::legacy::PassManagerImpl::run(llvm::Module&) + 296 16 llc 0x000000010d9611f1 llvm::legacy::PassManager::run(llvm::Module&) + 33 17 llc 0x000000010a6954ee compileModule(char**, llvm::LLVMContext&) + 6670 18 llc 0x000000010a693227 main + 1447 19 libdyld.dylib 0x00007fff72026259 start + 1 zsh: segmentation fault ./llc -run-pass=livedebugvalues foo.mir
llvmbot commented 4 years ago

Vedant wrote a verifier check, this is invalid MIR (but we didn't catch it before)

llvmbot commented 4 years ago

FWIW, I wrote this patch (https://reviews.llvm.org/D80602), to fix this bug (#46009 ) and that caused one of the tests in the suite to fail. I wonder if me setting the debug location to an empty one before splicing is wrong somehow.

jmorse commented 4 years ago

Hmmm, in the bb.4.if.else block:

DBG_VALUE $rdx, $noreg, !​69, !DIExpression()

As you say, there's no DebugLoc attachment on this DBG_VALUE. IMO, the DBG_VALUE there is illegal, as we can't get any inlining information out of it. A dbg.value intrinsic without a !dbg attachment is an IR verifier error. Whatever's producing this DBG_VALUE is wrong.

Just running llc from e2b134b01a6 over the embedded IR doesn't produce the same MIR for me though, I get the same block 4, but both instructions have DebugLocs.

llvmbot commented 4 years ago

Looks like the DebugLoc here is nullptr

frame #&#8203;3: 0x0000000102958934 llc`(anonymous namespace)::LiveDebugValues::accumulateFragmentMap(this=0x000000011432d110, MI=0x0000000115071280, SeenFragments=0x00007ffeefbfe008, OverlappingFragments=0x00007ffeefbfe078) at LiveDebugValues.cpp:1416:41
   1413                                             VarToFragments &SeenFragments,
   1414                                             OverlapMap &OverlappingFragments) {
   1415   DebugVariable MIVar(MI.getDebugVariable(), MI.getDebugExpression(),
-> 1416                       MI.getDebugLoc()->getInlinedAt());
   1417   FragmentInfo ThisFragment = MIVar.getFragmentOrDefault();
   1418 
   1419   // If this is the first sighting of this variable, then we are guaranteed
(lldb) p MI.getDebugLoc()
(const llvm::DebugLoc) $1 = {
  Loc = {
    Ref = {
      MD = 0x0000000000000000
    }
  }
}