[llvm-bugs] [Bug 37958] New: PatchableFunction crashes on empty function

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Jun 27 07:09:03 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=37958

            Bug ID: 37958
           Summary: PatchableFunction crashes on empty function
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: All
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Backend: X86
          Assignee: unassignedbugs at nondot.org
          Reporter: apilipenko at azulsystems.com
                CC: llvm-bugs at lists.llvm.org

I don't think that this is a problem for real world code, but it confuses
bugpoint and makes it reduce crashes down to empty method.  

foo.ll:

define void @foo() "patchable-function"="prologue-short-redirect" {
  unreachable
}

llc foo.ll 

Stack dump:
0.      Program arguments: /local/apilipenko/orca-2/build/buildR/bin/llc foo.ll 
1.      Running pass 'Function Pass Manager' on module 'foo.ll'.
2.      Running pass 'Implement the 'patchable-function' attribute' on function
'@foo'
#0 0x00007f34f54eff9a llvm::sys::PrintStackTrace(llvm::raw_ostream&)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x603f9a)
#1 0x00007f34f54ee8da llvm::sys::RunSignalHandlers()
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x6028da)
#2 0x00007f34f54eea09 SignalHandler(int)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x602a09)
#3 0x00007f34f4cdf130 __restore_rt (/lib64/libpthread.so.0+0xf130)
#4 0x00007f34f57aad44 llvm::MachineInstr::getMF() const
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x8bed44)
#5 0x00007f34f575cd4c
llvm::ilist_traits<llvm::MachineInstr>::removeNodeFromList(llvm::MachineInstr*)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x870d4c)
#6 0x00007f34f57ab03f llvm::MachineInstr::eraseFromParent()
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x8bf03f)
#7 0x00007f34f584b53f (anonymous
namespace)::PatchableFunction::runOnMachineFunction(llvm::MachineFunction&)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x95f53f)
#8 0x00007f34f57a6ff9 llvm::MachineFunctionPass::runOnFunction(llvm::Function&)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x8baff9)
#9 0x00007f34f55d0dba llvm::FPPassManager::runOnFunction(llvm::Function&)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x6e4dba)
#10 0x00007f34f55d1614 llvm::legacy::PassManagerImpl::run(llvm::Module&)
(/local/apilipenko/orca-2/build/buildR/bin/../lib/liborca.so.0.dev+0x6e5614)
#11 0x00000000004123d4 main
(/local/apilipenko/orca-2/build/buildR/bin/llc+0x4123d4)
#12 0x00007f34f4100af5 __libc_start_main (/lib64/libc.so.6+0x21af5)
#13 0x00000000004128fd _start
(/local/apilipenko/orca-2/build/buildR/bin/llc+0x4128fd)
Segmentation fault (core dumped)

PatchableFunction finds the first instruction which is code generated (skipping
DBG_LABEL, DBG_VALUE, KILL, etc.) and replaces it with PATCHABLE_OP <minsize>,
<opcode>, <operands>, where <opcode> and <operands> are the first instruction
it found. If the function is empty it can't do this trick. 
  MachineBasicBlock::iterator FirstActualI = FirstMBB.begin();
  for (; doesNotGeneratecode(*FirstActualI); ++FirstActualI)
    assert(FirstActualI != FirstMBB.end());
  ... uses FirstActualI ... 

Locally for my bugpoint run I fixed it by ignoring such functions but it seem
to violate the contract of "patchable-function".

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180627/677c26ed/attachment.html>


More information about the llvm-bugs mailing list