fneg instruction unsupported
Closed this issue · 4 comments
When I tried to decompile the bitcode generated by following source code:
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char **argv) {
float state = -12345.12345;
state = -state;
}
I have the unsupported instruction error as followed, which should correspond to "state = -state":
unsupported LLVM instruction in: %7 = fneg float %6 @
unsupported LLVM instruction
UNREACHABLE executed at /home/muqi/decompile_tool/llvm-cbe/lib/Target/CBackend/CBackend.cpp:5351!
/usr/lib/llvm-10/lib/libLLVM-10.so.1(_ZN4llvm3sys15PrintStackTraceERNS_11raw_ostreamE+0x1f)[0x7f21b35b8c3f]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(_ZN4llvm3sys17RunSignalHandlersEv+0x22)[0x7f21b35b6ed2]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(+0x978205)[0x7f21b35b9205]
/lib/x86_64-linux-gnu/libc.so.6(+0x3f040)[0x7f21b22ee040]
/lib/x86_64-linux-gnu/libc.so.6(gsignal+0xc7)[0x7f21b22edfb7]
/lib/x86_64-linux-gnu/libc.so.6(abort+0x141)[0x7f21b22ef921]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(+0x8d6231)[0x7f21b3517231]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x5aef9)[0x556040017ef9]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x661a2)[0x5560400231a2]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x7f95d)[0x55604003c95d]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x79345)[0x556040036345]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x72c5b)[0x55604002fc5b]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x6bfab)[0x556040028fab]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x6a66d)[0x55604002766d]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x48f49)[0x556040005f49]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x49031)[0x556040006031]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x49158)[0x556040006158]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x59e17)[0x556040016e17]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x72f79)[0x55604002ff79]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x6c1a3)[0x5560400291a3]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x6a66d)[0x55604002766d]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x48f49)[0x556040005f49]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x52cdb)[0x55604000fcdb]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x52737)[0x55604000f737]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x420d1)[0x55603ffff0d1]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE+0x466)[0x7f21b36bf866]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE+0x33)[0x7f21b36bfae3]
/usr/lib/llvm-10/lib/libLLVM-10.so.1(_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE+0x3c0)[0x7f21b36bff90]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x190e1)[0x55603ffd60e1]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x18545)[0x55603ffd5545]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xe7)[0x7f21b22d0bf7]
/home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe(+0x169ea)[0x55603ffd39ea]
Stack dump:
0. Program arguments: /home/muqi/decompile_tool/llvm-cbe/build/tools/llvm-cbe/llvm-cbe ./test_muqi/generatedll/test.ll --o ./test_muqi/generatedc/test.c
1. Running pass 'Function Pass Manager' on module './test_muqi/generatedll/test.ll'.
2. Running pass 'C backend' on function '@main'
Aborted (core dumped)
Traceback (most recent call last):
File "generate_symbolic.py", line 145, in <module>
main()
File "generate_symbolic.py", line 115, in main
modify_main(filepath_generatedc)
File "generate_symbolic.py", line 40, in modify_main
fin = open(filepath,'r')
FileNotFoundError: [Errno 2] No such file or directory: './test_muqi/generatedc/test.c'
The bitcode is generated by: clang-10 -emit-llvm -c -O0
And assembly language is by: llvm-dis-10
My llvm-cbe version is:
LLVM (http://llvm.org/):
LLVM version 10.0.0
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: skylake
Registered Targets:
aarch64 - AArch64 (little endian)
aarch64_32 - AArch64 (little endian ILP32)
aarch64_be - AArch64 (big endian)
amdgcn - AMD GCN GPUs
arm - ARM
arm64 - ARM64 (little endian)
arm64_32 - ARM64 (little endian ILP32)
armeb - ARM (big endian)
avr - Atmel AVR Microcontroller
bpf - BPF (host endian)
bpfeb - BPF (big endian)
bpfel - BPF (little endian)
c - C backend
hexagon - Hexagon
lanai - Lanai
mips - MIPS (32-bit big endian)
mips64 - MIPS (64-bit big endian)
mips64el - MIPS (64-bit little endian)
mipsel - MIPS (32-bit little endian)
msp430 - MSP430 [experimental]
nvptx - NVIDIA PTX 32-bit
nvptx64 - NVIDIA PTX 64-bit
ppc32 - PowerPC 32
ppc64 - PowerPC 64
ppc64le - PowerPC 64 LE
r600 - AMD GPUs HD2XXX-HD6XXX
riscv32 - 32-bit RISC-V
riscv64 - 64-bit RISC-V
sparc - Sparc
sparcel - Sparc LE
sparcv9 - Sparc V9
systemz - SystemZ
thumb - Thumb
thumbeb - Thumb (big endian)
wasm32 - WebAssembly 32-bit
wasm64 - WebAssembly 64-bit
x86 - 32-bit X86: Pentium-Pro and above
x86-64 - 64-bit X86: EM64T and AMD64
xcore - XCore
I thought LLVM represented floating-point negation (i.e. fneg) as a subtraction from -0.0
, but apparently that fairly recently changed, and that must be the cause of the problem. I guess it would be easy to fix.
If we only need to support these newer LLVM versions then the code could even be simplified a bit. Currently -0.0 - x
is special-cased.
Ah, it was LLVM 8 where this was added: llvm/llvm-project@cbde0d9 (curiously the release notes don't mention it?)
If this project is only to support versions 8 and above then it could remove the special case for -0.0 - x
and just support true fneg
probably.
Hi, does #97 fix your problem? :)
Yes, thanks!~