RFR: 7903777: jextract layout for enum with big constant values is wrong [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Jul 16 13:59:32 UTC 2024


On Tue, 16 Jul 2024 13:56:00 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This PR fixes the code that generates enum layouts. Currently, the layout of an enum type is determined by looking at the type of the first enum constant.
>> In some platforms, this strategy does not work, as an enum can have constants of **different** types.
>> 
>> The solution is to ask clang what the integral type of the enum declaration is, and store that as an attribute in the enum declaration. Then, we should simply retrieve that type when generating layouts that depend on the enum.
>> 
>> I've added a platform-dependent test, since this functionality is only really available on Linux/gcc (on Windows, enum constants are all truncated to 32 bits, it seems).
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Use import

src/main/java/org/openjdk/jextract/impl/DeclarationImpl.java line 352:

> 350:      * An attribute to mark enum constants, with a link to the name of their parent enum.
> 351:      */
> 352:     record EnumConstant(String enumName) {

the name of this component was odd (`get`) so I renamed it

src/main/java/org/openjdk/jextract/impl/Utils.java line 157:

> 155:     static boolean isPrimitive(Type type) {
> 156:         return switch (type) {
> 157:             case Type.Declared declared when declared.tree().kind() == Declaration.Scoped.Kind.ENUM -> true;

seems to me that if a type is an enum, it should always be considered a "primitive", no need to recurse

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/252#discussion_r1679448158
PR Review Comment: https://git.openjdk.org/jextract/pull/252#discussion_r1679451288


More information about the jextract-dev mailing list