Skip to content

Argument -fshort-enums and __attribute__((packed)) on enums are ignored #70607

Closed
@whypet

Description

@whypet

When specifying -fshort-enums in the command line or marking an enum with __attribute__((packed)), the size of the enum should be smaller than an int if all the values in the enum fit in a short or a char, however the size of the enum is 4 bytes.
I'm facing this issue on the LLVM 17.0.3 Win32 builds.

Repro

main.c:

#include <assert.h>

enum __attribute__((packed)) BYTE_ENUM {
	A = 0,
	B = 1
};

static_assert(sizeof(enum BYTE_ENUM) == 1, "Size of BYTE_ENUM should be 1 byte.");

Command line: clang main.c -fshort-enums (or clang main.c since we are adding the attribute to the enum anyway)

Screenshot

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:codegenIR generation bugs: mangling, exceptions, etc.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions