[foreign-jextract] RFR: 8249536: jextract throw IllegalStateException for bitfields in nested anonymous structs

Jorn Vernee jvernee at openjdk.java.net
Wed Jul 15 20:33:09 UTC 2020


On Wed, 15 Jul 2020 19:48:39 GMT, Paul Sandoz <psandoz at openjdk.org> wrote:

>> Hi,
>> 
>> This patch fixes an issue with grouping of bitfields into a container for structs that contain anonymous nested structs
>> that have bitfields in them. Such as
>> struct Foo {
>>     struct {
>>         int a : 7;
>>         int b : 25;
>>     };
>> };
>> 
>> The current code iterates over the member layouts of a struct, and when it finds a bitfield storage unit, it tries to
>> find matching bitfield Declarations and groups them into a synthetic nested BITFIELDS declaration.
>> But, the memory layout members also contain bitfields that are found in anonymous nested structs, since they are
>> flattened into the parent layout. However, for the jextract Declaration tree this is not the case, so the current code
>> can not find a matching declaration for these bitfield layouts. e.g. in the example `Foo` will have a bitfield storage
>> unit which contains `a` and `b`, but the Declaration tree has the declarations for `a` and `b` nested inside the
>> anonymous struct (layouts and declaration tree are different in this regard).  The fix is to ignore bitfields that come
>> from nested anonymous structs. They will be handled when processing the nested anonymous struct instead.  Thanks, Jorn
>
> What happens for the following?
> struct Foo {
>     struct {
>         int a : 7;
>         int b : 25;
>     };
>     struct Bar {
> 	int a : 12;
>     } bar;
> };

> 
> 
> What happens for the following?
> 
> ```c
> struct Foo {
>     struct {
>         int a : 7;
>         int b : 25;
>     };
>     struct Bar {
> 	int a : 12;
>     } bar;
> };
> ```

In that case there is no problem since the `bar` struct is not anonymous.

You get the following tree (On Windows):

Scoped: TOPLEVEL <toplevel>
    Scoped: STRUCT Foo layout =
    [b32[contents=[b7(a)[layout/name=a]b25(b)[layout/name=b]],abi/windows/class=INTEGER][b32[contents=[b12(a)[layout/name=a]x20],abi/windows/class=INTEGER]](bar)[layout/name=bar]](Foo)[layout/name=Foo]
        Scoped: STRUCT  layout = [b32[contents=[b7(a)[layout/name=a]b25(b)[layout/name=b]],abi/windows/class=INTEGER]]
            Scoped: BITFIELDS  layout = [b7(a)[layout/name=a]b25(b)[layout/name=b]]
                Variable: BITFIELD a type = Int(layout = b32[abi/windows/class=INTEGER]), layout = Optional[b7]
                Variable: BITFIELD b type = Int(layout = b32[abi/windows/class=INTEGER]), layout = Optional[b25]
        Scoped: STRUCT Bar layout = [b32[contents=[b12(a)[layout/name=a]x20],abi/windows/class=INTEGER]](Bar)[layout/name=Bar]
            Scoped: BITFIELDS  layout = [b12(a)[layout/name=a]x20]
                Variable: BITFIELD a type = Int(layout = b32[abi/windows/class=INTEGER]), layout = Optional[b12]
        Variable: FIELD bar type =
        Declared([b32[contents=[b12(a)[layout/name=a]x20],abi/windows/class=INTEGER]](Bar)[layout/name=Bar]), layout =
        Optional[[b32[contents=[b12(a)[layout/name=a]x20],abi/windows/class=INTEGER]](Bar)[layout/name=Bar]]

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

PR: https://git.openjdk.java.net/panama-foreign/pull/246


More information about the panama-dev mailing list