Issue 154374
Summary __alignof(_BitInt(64)) evaluates to 4 when targeting IA-32, whereas GCC evaluates it as 8
Labels new issue
Assignees
Reporter pascal-cuoq
    While investigating the implementation of the _BitInt construct in Clang and GCC together with @MisterDA, we found some differences between Clang and GCC. Some of the differences are redundant with https://github.com/llvm/llvm-project/issues/47017 or with https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61447 but at least the value of `__alignof(_BitInt(64))`, 4 in Clang and 8 in GCC, seems to me to be a previously-undocumented difference between the compilers, that does not even rely on the compiler extension of allowing lvalues in alignof constructs, although it does rely on the compiler extension `__alignof` which provides the recommended alignment (8 for the type `long long` for IA-32, considering modern implementations of that ISA).

```c
long long vll;
_BitInt(64) vbi;

struct result {
int uppercase_alignof_bi64;
int uppercase_alignof_vbi;
int uppercase_alignof_longlong;
int uppercase_alignof_vll;
int lowercase_alignof_bi64;
int lowercase_alignof_vbi;
int lowercase_alignof_longlong;
int lowercase_alignof_vll;
} result =
{
.uppercase_alignof_bi64 = _Alignof(_BitInt(64)),
.uppercase_alignof_vbi = _Alignof(vbi),
.uppercase_alignof_longlong = _Alignof(long long),
.uppercase_alignof_vll = _Alignof(vll),
.lowercase_alignof_bi64 = __alignof(_BitInt(64)),
.lowercase_alignof_vbi = __alignof(vbi),
.lowercase_alignof_longlong = __alignof(long long),
.lowercase_alignof_vll = __alignof(vll),
};
```

Using Clang 20.1.0 with `-O2 -std=c23 -m32`:
```asm
result:
        .long   4
 .long   4
        .long   4
        .long   8
        .long   4
 .long   4
        .long   8
        .long   8
```

Using GCC 15.2 with the same options:
```
result:
        .long   4
        .long   8
 .long   4
        .long   8
        .long   8
        .long   8
 .long   8
        .long   8
```

Compiler Explorer link: https://gcc.godbolt.org/z/z59c6Tn7n
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to