HomePhabricator

[DebugInfo] Recover debug intrinsics when killing duplicated/empty basic blocks

Authored by StephenTozer on Dec 4 2019, 1:44 AM.

Description

[DebugInfo] Recover debug intrinsics when killing duplicated/empty basic blocks

When basic blocks are killed, either due to being empty or to being an if.then
or if.else block whose complement contains identical instructions, some of the
debug intrinsics in that block are lost. This patch sinks those intrinsics
into the single successor block, setting them Undef if necessary to
prevent debug info from falling out-of-date.

Differential Revision: https://reviews.llvm.org/D70318

Event Timeline

saugustine added a subscriber: saugustine.EditedDec 4 2019, 12:56 PM

This change is causing clang to crash on some internal tests we have.

I'm working on a public reproducer, but the stack is:

  1. <eof> parser at end of file
  2. Code generation
  3. Running pass 'Function Pass Manager' on module '[redacted].
  4. Running pass 'Linux PPC Assembly Printer' on function '@access_reg'

0 0x00005566d8221f88 SignalHandler(int)
1 0x00007f52d14ec9a0 restore_rt
2 0x00005566d897e0f1 llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*)
3 0x00005566d89bd881 llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*)
4 0x00005566d88898af llvm::AsmPrinter::EmitFunctionBody()
5 0x00005566d838ca65 (anonymous namespace)::PPCAsmPrinter::runOnMachineFunction(llvm::MachineFunction&)
6 0x00005566d8871563 llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
7 0x00005566d853863c llvm::FPPassManager::runOnFunction(llvm::Function&)
8 0x00005566d85382c1 llvm::FPPassManager::runOnModule(llvm::Module&)
9 0x00005566d5f53e38 llvm::legacy::PassManagerImpl::run(llvm::Module&)
10 0x00005566d5c5b90a (anonymous namespace)::EmitAssemblyHelper::EmitAssemblyWithNewPassManager(clang::BackendAction, std::
u::unique_ptr<llvm::raw_pwrite_stream, std::u::default_delete<llvm::raw_pwrite_stream> >)
11 0x00005566d6268525 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::
u::unique_ptr<llvm::raw_pwrite_stream, std::__u::default_delete<llvm::raw_pwrite_stream> >)
12 0x00005566d626736c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&)
13 0x00005566d5e1e3dc clang::ParseAST(clang::Sema&, bool, bool)
14 0x00005566d621b091 clang::FrontendAction::Execute()
15 0x00005566d621a8a0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&)
16 0x00005566d6219c8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*)
17 0x00005566d62172cd cc1_main(llvm::ArrayRef<char const*>, char const*, void*)
18 0x00005566d5cd181d main

Not entirely sure it is relevant, but when I try to read the .ll file with llc, I get:

invalid llvm.dbg.label intrinsic variable

call void @llvm.dbg.label(metadata i1 undef), !dbg !2070

i1 undef
warning: ignoring invalid debug info in test.pic.ll

We may want to revert for now.

Here is the very reduced test case:

echo "a; b() { while (a) c:; }" | bin/clang -cc1 -emit-obj -debug-info-kind=limited -O3 -x c

which produces this output: [The warnings weren't present in the original code.]

<stdin>:1:1: warning: type specifier missing, defaults to 'int'
a; b() { while (a) c:; }
^
<stdin>:1:4: warning: type specifier missing, defaults to 'int'
a; b() { while (a) c:; }

^

<stdin>:1:24: warning: non-void function does not return a value
a; b() { while (a) c:; }

^

invalid llvm.dbg.label intrinsic variable

call void @llvm.dbg.label(metadata i1 undef), !dbg !15

i1 undef
invalid llvm.dbg.label intrinsic variable

call void @llvm.dbg.label(metadata i1 undef), !dbg !15

i1 undef
Stack dump:
0. Program arguments: /google/src/cloud/saugustine/llvm-integrate/google3/third_party/crosstool/v18/llvm_unstable/toolchain/bin/clang -cc1 -emit-obj -debug-info-kind=limited -O3 -x c

  1. <eof> parser at end of file
  2. Code generation
  3. Running pass 'Function Pass Manager' on module '-'.
  4. Running pass 'X86 Assembly Printer' on function '@b' #0 0x0000558f079a7f88 SignalHandler(int) (bin/clang+0x43e4f88) #1 0x00007f9da48599a0 __restore_rt (/usr/grte/v4/lib64/libpthread.so.0+0xf9a0) #2 0x0000558f081040f1 llvm::DwarfDebug::endFunctionImpl(llvm::MachineFunction const*) (bin/clang+0x4b410f1) #3 0x0000558f08143881 llvm::DebugHandlerBase::endFunction(llvm::MachineFunction const*) (bin/clang+0x4b80881) #4 0x0000558f0800f8af llvm::AsmPrinter::EmitFunctionBody() (bin/clang+0x4a4c8af) #5 0x0000558f0800d3ce llvm::X86AsmPrinter::runOnMachineFunction(llvm::MachineFunction&) (bin/clang+0x4a4a3ce) #6 0x0000558f07ff7563 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (bin/clang+0x4a34563) #7 0x0000558f07cbe63c llvm::FPPassManager::runOnFunction(llvm::Function&) (bin/clang+0x46fb63c) #8 0x0000558f07cbe2c1 llvm::FPPassManager::runOnModule(llvm::Module&) (bin/clang+0x46fb2c1) #9 0x0000558f056d9e38 llvm::legacy::PassManagerImpl::run(llvm::Module&) (bin/clang+0x2116e38)

#10 0x0000558f059ef293 clang::EmitBackendOutput(clang::DiagnosticsEngine&, clang::HeaderSearchOptions const&, clang::CodeGenOptions const&, clang::TargetOptions const&, clang::LangOptions const&, llvm::DataLayout const&, llvm::Module*, clang::BackendAction, std::u::unique_ptr<llvm::raw_pwrite_stream, std::u::default_delete<llvm::raw_pwrite_stream> >) (bin/clang+0x242c293)
#11 0x0000558f059ed36c clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (bin/clang+0x242a36c)
#12 0x0000558f055a43dc clang::ParseAST(clang::Sema&, bool, bool) (bin/clang+0x1fe13dc)
#13 0x0000558f059a1091 clang::FrontendAction::Execute() (bin/clang+0x23de091)
#14 0x0000558f059a08a0 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (bin/clang+0x23dd8a0)
#15 0x0000558f0599fc8e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (bin/clang+0x23dcc8e)
#16 0x0000558f0599d2cd cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (bin/clang+0x23da2cd)
#17 0x0000558f0545781d main (bin/clang+0x1e9481d)
#18 0x00007f9da46c7bbd __libc_start_main (lib64/libc.so.6+0x38bbd)
#19 0x0000558f057c94d9 _start (bin/clang+0x22064d9)