https://gcc.gnu.org/bugzilla/show_bug.cgi?id=121938
Bug ID: 121938
Summary: x86-32: enum with big value gets too small size
(disagreement with clang)
Product: gcc
Version: 15.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: post+gcc at ralfj dot de
Target Milestone: ---
Consider this code:
#include <stdio.h>
enum enum1 {
A = 18446744071562067968,
};
enum enum2 {
B = 18446744071562067967,
};
int main(void) {
printf("size(enum1) = %zd\n", sizeof(enum enum1));
printf("size(enum2) = %zd\n", sizeof(enum enum2));
}
I would expect both enums to end up with size 8, and that is indeed what
happens with -m64 with both gcc and clang (https://godbolt.org/z/bE588r3Th).
However, with -m32, gcc changes its behavior to give enum1 a size of 4. enum2,
despite having a *smaller* value to store, remains at size 8
(https://godbolt.org/z/4qvMchjan).
The value in enum is equal to 0xffffffff80000000, so I assume there's some sort
of overflow here. (Funny enough, if I write the value in the code in hex
instead of decimal, the size of the enum changes to 8.)