jacobly0 / llvm-z80

(e)Z80 backend for llvm - Moved to https://github.com/jacobly0/llvm-project
Other
48 stars 3 forks source link

Crash with -O1 and above on llvm::InstrEmitter::EmitRegSequence (InstrEmitter.cpp) #4

Closed adriweb closed 7 years ago

adriweb commented 7 years ago

Crash with -O1 and above with this code:

#include <stdint.h>

extern char* foo(void**);
void test(uint16_t num)
{
    uint16_t bar = (num <= 0xFF) ? num : num+1;
    void* ptr = &bar;
    foo(&ptr);
}

Note 1: it crashes only with the value 0xFF in the num <= 0xFF comparison. Any other number, lower or higher, works fine. Note 2: it doesn't crash at all if num is a uint24_t.

Assertion failed:

../../lib/CodeGen/SelectionDAG/InstrEmitter.cpp:642: void llvm::InstrEmitter::EmitRegSequence(llvm::SDNode*, llvm::DenseMap<llvm::SDValue, unsigned int>&, bool, bool):
Assertion `(NumOps & 1) == 1 && "REG_SEQUENCE must have an odd number of operands!"' failed.

Backtrace:

<libc things>
#8 0x00000381d963fdeb llvm::InstrEmitter::EmitRegSequence(llvm::SDNode*, llvm::DenseMap<llvm::SDValue, unsigned int, llvm::DenseMapInfo<llvm::SDValue>, llvm::detail::DenseMapPair<llvm::SDValue, unsigned int> >&, bool, bool) (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0xbcdeb)
#9 0x00000381d9640ed0 llvm::InstrEmitter::EmitMachineNode(llvm::SDNode*, bool, bool, llvm::DenseMap<llvm::SDValue, unsigned int, llvm::DenseMapInfo<llvm::SDValue>, llvm::detail::DenseMapPair<llvm::SDValue, unsigned int> >&) (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0xbded0)
#10 0x00000381d96e8445 llvm::ScheduleDAGSDNodes::EmitSchedule(llvm::MachineInstrBundleIterator<llvm::MachineInstr, false>&) (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0x165445)
#11 0x00000381d976ec7b llvm::SelectionDAGISel::CodeGenAndEmitDAG() (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0x1ebc7b)
#12 0x00000381d976f503 llvm::SelectionDAGISel::SelectBasicBlock(llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, llvm::ilist_iterator<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void>, false, true>, bool&) (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0x1ec503)
#13 0x00000381d9777dbe llvm::SelectionDAGISel::SelectAllBasicBlocks(llvm::Function const&) (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0x1f4dbe)
#14 0x00000381d9779d91 llvm::SelectionDAGISel::runOnMachineFunction(llvm::MachineFunction&) [clone .part.986] (/usr/lib/../lib/libLLVMSelectionDAG.so.5+0x1f6d91)
#15 0x00000381dea6c347 llvm::MachineFunctionPass::runOnFunction(llvm::Function&) (/usr/lib/libLLVMCodeGen.so.5+0x1f1347)
#16 0x00000381de4772b3 llvm::FPPassManager::runOnFunction(llvm::Function&) (/usr/lib/libLLVMCore.so.5+0x16f2b3)
#17 0x00000381de47735c llvm::FPPassManager::runOnModule(llvm::Module&) (/usr/lib/libLLVMCore.so.5+0x16f35c)
#18 0x00000381de477b8a llvm::legacy::PassManagerImpl::run(llvm::Module&) (/usr/lib/libLLVMCore.so.5+0x16fb8a)
#19 0x00000381db2ff5ca (anonymous namespace)::EmitAssemblyHelper::EmitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream> >) (/usr/lib/libclangCodeGen.so.5+0xbd5ca)
<...>

Steps:

0.  Program arguments: /opt/llvm/build/Debug/bin/clang-5.0 -cc1 -triple ez80 -S -disable-free -main-file-name test.c -mrelocation-model static -mthread-model posix -fmath-errno -no-integrated-as -mconstructor-aliases -target-cpu ez80 -momit-leaf-frame-pointer -dwarf-column-info -debugger-tuning=gdb -coverage-notes-file /-.gcno -resource-dir /opt/llvm/build/Debug/lib/clang/5.0.0 -D interrupt=__attribute__((__interrupt__)) -D double=float -D reentrant= -I /opt/CEdev/include/ -I /opt/CEdev/include/compat -O3 -w -fno-dwarf-directory-asm -fdebug-compilation-dir / -ferror-limit 19 -fmessage-length 0 -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -o - -x c <...>/test.c 
1.  <eof> parser at end of file
2.  Code generation
3.  Running pass 'Function Pass Manager' on module '<...>/test.c'.
4.  Running pass 'Z80 DAG->DAG Instruction Selection' on function '@test'
jacobly0 commented 7 years ago

No longer crashes.