[Clang][ABI] Clang's ABI classification of Atomic types is incompatible with GCC
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Clang's ABI classification of atomic types in function signatures does not match the behavior of GCC.
For example, for non-Windows x86-64 targets a struct of two `_Atomic(float)` values is passed indirectly as a `byval` pointer in clang, while GCC passes such a structure in an SSE register.
It's unclear whether this was intentional behavior or if it is just a consequence of Clang's type system having an explicit `AtomicType` that is not directly handled by the ABI type classifiers. The ABI classifier default to classifying all types as `MEMORY` and the `AtomicType` wrapper prevents these types from being handled by the builtin-type handlers.
In the case of a single `_Atomic(float)` argument, the argument is classified as `MEMORY` but the getIndirectResult() handling calls `ConvertType` for non-aggregates and this function unwraps the AtomicType so the single value ends up in an SSE register.
https://gcc.godbolt.org/z/z1bWvrhjW
Note that this issue is not specific to x86-64 targets. For example, Arm64 targets exhibit the same behavior.
https://gcc.godbolt.org/z/36fvYcEn7
Contributor guide
Research direction
Reproduce the x86-64 and Arm64 examples in the linked Compiler Explorer cases, then read the ABI type classifiers and the mentioned AtomicType, getIndirectResult(), and ConvertType paths. Compare struct and single-argument classification with GCC; done means atomic types use compatible register or indirect calling conventions on the affected targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- c
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100