appleseedlab / maki

A tool for analyzing syntactic and semantic properties of C Preprocessor macros in C programs
8 stars 3 forks source link

Handle enums in line with the C standard #60

Closed SilverMight closed 1 month ago

SilverMight commented 2 months ago

The C standard defines that enums must an "integer constant expression whose value is representable as a value of type int(until C23). If the enumeration has a fixed underlying type, representable as a value of type(since C23)".

The C standard only guarantees that int is at least 16-bits.

This is a problem as we currently handle translating object-like macros to enums in MerC by looking at the property IsICERepresentableByInt32, and translating it to an enum if it is.

While a lot of platforms have int as 32-bit (and a lot of codebases assume this), we need to adhere to the standard here for platforms that only have 16 bit integers.

I think that keeping the existing field IsICERepresentableByInt32 is a good idea and perhaps adding an equivalent field for Int16 may be the move, so MerC can have some options on how to translate this with user configuration. That way we have larger coverage with the vast majority of platforms, and also have an option to adhere strictly to the standard.