Skip to content

[clang] [x86-64] enum layout without fixed type differs from GCC when big constants are involved #158472

@RalfJung

Description

@RalfJung

clang computes a different layout than GCC for this enum:

enum big {
    A = 9223372036854775808u,
    B = -1,
};

(Godbolt)

GCC gives this size 16 without any warning. clang gives it size 8 and says

<source>:3:6: warning: enumeration values exceed range of largest integer [-Wenum-too-large]
    3 | enum big {
      |      ^

(On x86-32, clang and GCC both give it size 8 and both emit a warning.)

Whether this is legal C or not depends on whether you consider __int128 to be an "extended integer type" or not... GCC apparently does not, though they do treat it like an extended integer type in many respects, so 🤷 . But legal C or not, it seems surprising that the two compilers would disagree here, and it could lead to ABI issues.

Metadata

Metadata

Assignees

No one assigned

    Labels

    ABIApplication Binary Interfaceclang:codegenIR generation bugs: mangling, exceptions, etc.diverges-from:gccDoes the clang frontend diverge from gcc on this issue

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions