#960246 ldc: ICE / SIGSEGV when trying to compile D code with -mattr=-x87

Package:
ldc
Source:
ldc
Description:
LLVM D Compiler
Submitter:
Witold Baryluk
Date:
2021-11-19 18:42:03 UTC
Severity:
normal
#960246#5
Date:
2020-05-11 00:16:48 UTC
From:
To:
This is probably related to the fact that pow by default uses real for
the argument, and it tries to generate x87 code for this.

$ cat f.d
import std.math : pow;

void main() {
    double x = pow(1.01, 1.3);
}
$


$ gdb --args ldc2 -mcpu=znver2 -mattr=-x87 ./f.d
Reading symbols from ldc2...
Reading symbols from /usr/lib/debug/.build-id/ad/062faf6b99f47b20e4afca986359f365881f56.debug...
(gdb) r
Starting program: /usr/bin/ldc2 -mcpu=znver2 -mattr=-x87 ./f.d
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

Program received signal SIGSEGV, Segmentation fault.
allocVirtReg () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:675
675	/build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp: No such file or directory.
(gdb) bt
#0  allocVirtReg () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:675
#1  0x00007ffff4ad4a4a in defineVirtReg () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:795
#2  0x00007ffff4ad26e1 in allocateInstruction () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:1188
#3  allocateBasicBlock () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:1277
#4  runOnMachineFunction () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/RegAllocFast.cpp:1316
#5  0x00007ffff4a090b8 in runOnFunction () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/CodeGen/MachineFunctionPass.cpp:73
#6  0x00007ffff4881c86 in runOnFunction () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/IR/LegacyPassManager.cpp:1648
#7  0x00007ffff4881f33 in runOnModule () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/IR/LegacyPassManager.cpp:1685
#8  0x00007ffff48823e0 in runOnModule () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/IR/LegacyPassManager.cpp:1750
#9  run () at /build/llvm-toolchain-9-RFyMo0/llvm-toolchain-9-9.0.1/llvm/lib/IR/LegacyPassManager.cpp:1863
#10 0x0000555555cd1219 in (anonymous namespace)::codegenModule (Target=..., m=..., filename=filename@entry=0x55555617f0b0 "f.o", fileType=fileType@entry=llvm::TargetMachine::CGFT_ObjectFile)
    at ./driver/toobj.cpp:131
#11 0x0000555555cd1fa6 in (anonymous namespace)::writeObjectFile (filename=0x55555617f0b0 "f.o", m=0x5555563e54e0) at ./driver/toobj.cpp:284
#12 writeModule (m=m@entry=0x5555563e54e0, filename=filename@entry=0x55555617f0b0 "f.o") at ./driver/toobj.cpp:469
#13 0x0000555555ccea04 in ldc::CodeGenerator::writeAndFreeLLModule (this=this@entry=0x7fffffffd9f0, filename=0x55555617f0b0 "f.o") at ./driver/codegenerator.cpp:285
#14 0x0000555555ccecef in ldc::CodeGenerator::finishLLModule (this=this@entry=0x7fffffffd9f0, m=m@entry=0x7ffff1f55930) at ./driver/codegenerator.cpp:258
#15 0x0000555555ccede3 in ldc::CodeGenerator::finishLLModule (m=0x7ffff1f55930, this=0x7fffffffd9f0) at ./driver/codegenerator.cpp:336
#16 ldc::CodeGenerator::emit (this=this@entry=0x7fffffffd9f0, m=0x7ffff1f55930) at ./driver/codegenerator.cpp:336
#17 0x0000555555c9e9ef in codegenModules (modules=...) at ./driver/main.cpp:1107
#18 0x0000555555a75dfb in mars_mainBody(Param&, Array<char const*>&, Array<char const*>&) () at /usr/lib/llvm-9/include/llvm/LinkAllIR.h:46
#19 0x0000555555ca0e62 in cppmain () at ./driver/main.cpp:1078
#20 0x0000555555e03430 in _D2rt6dmain212_d_run_main2UAAamPUQgZiZ6runAllMFZv ()
#21 0x0000555555e0323f in _d_run_main2 ()
#22 0x0000555555e0309e in _d_run_main ()
#23 0x000055555598180e in main (argc=argc@entry=4, originalArgv=originalArgv@entry=0x7fffffffe0a8) at /usr/lib/llvm-9/include/llvm/ADT/SmallVector.h:144
#24 0x00007ffff36ece0b in __libc_start_main (main=0x5555559815c0 <main(int, char const**)>, argc=4, argv=0x7fffffffe0a8, init=<optimized out>, fini=<optimized out>, rtld_fini=<optimized out>,
    stack_end=0x7fffffffe098) at ../csu/libc-start.c:308
#25 0x0000555555983afa in _start () at /usr/lib/llvm-9/include/llvm/LinkAllIR.h:46
(gdb)

#960246#10
Date:
2021-05-13 15:02:51 UTC
From:
To:
Issue still reproducible using ldc 1:1.24.0-2 and libllvm11 1:11.0.1-2 on amd64.
#960246#15
Date:
2021-11-19 18:39:34 UTC
From:
To:
Same with 1.28.0