Description
Bugzilla Link | 39427 |
Resolution | FIXED |
Resolved on | Mar 07, 2019 00:13 |
Version | 7.0 |
OS | Linux |
Blocks | #38454 |
Attachments | ABI demonstration |
Reporter | LLVM Bugzilla Contributor |
CC | @aleden,@d0k,@dwblaikie,@zmodem,@cuviper,@slacka,@zygoloid,@rnk,@serge-sans-paille,@sylvestre,@TNorthover,@tstellar |
Fixed by commit(s) | r346985 |
Extended Description
Calling llvm::ConstantExpr::getGetElementPtr crashes when LLVM 7 is compiled with gcc 8.2 and the caller is compiled with clang 7.
The reason is an ABI incompatibility: clang wants to pass the llvm::Optional parameter by value (i.e., as a single i64), while gcc expects the value to be passed by reference.
I have attached a simple test program that demonstrates the problem explicitly, regardless how the underlying LLVM was compiled. (It still uses the LLVM 7 headers, but the problem is triggered purely in the example code here).
To reproduce, compile and run the attached program like this:
clang++-7 -c -opart1.o foo.cpp llvm-config-7 --cxxflags
g++ -c -opart2.cpp -DPART2 foo.cpp llvm-config-7 --cxxflags
clang++-7 -ofoo part1.o part2.o llvm-config-7 --cxxflags
./foo
This leads to a crash. Using either g++ or clang++ for both files is fine, but mixing them leads to a crash. By inspecting the assembler code we can see that clang++ passes by value, and g++ passes by reference.