Skip to content

gcc ABI incompatibility when passing llvm::Optional #38775

Closed
@llvmbot

Description

@llvmbot
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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions