https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93622
Bug ID: 93622
Summary: bool register arguments are underspecified on x86_64
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: maxim.yegorushkin at gmail dot com
Target Milestone: ---
bool register arguments are underspecified on x86_64
The following code:
#include <cstdint>
struct A {
int32_t a;
uint32_t b : 1;
uint32_t c : 31;
constexpr A(int a, int c, bool b)
: a(a), b(b), c(c)
{}
};
A f(int a, int c, bool b) {
return {a, c, b};
}
With g++ trunk and `-O3 -march=skylake -std=gnu++17` compiles to:
f(int, int, bool):
add esi, esi
movzx edx, dl <--- zero out top 7 bytes of rdx
or esi, edx
sal rsi, 32
mov eax, edi
or rax, rsi
ret
Whereas clang-9 with the same flags generates:
f(int, int, bool):
lea ecx, [rdx + 2*rsi] <--- rdx is either 0 or 1.
shl rcx, 32
mov eax, edi
or rax, rcx
ret
Why does g++ assume that a `bool` argument in a 64-bit register (rdx here) has
its top 7 bytes filled with indeterminate values, whereas clang assumes that
the register is exactly 0 or 1, please?