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

Henry Jen henryjen at openjdk.java.net
Wed Jul 15 21:37:50 UTC 2020


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

>>> 
>>> 
>>> 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]]
>
> Will the bit fields named "a" in the anonymous and named nested structs clash. so processing "a" in struct Bar will get
> filtered out because "a" is added to the `nestedBitfieldNames` set?

That won't have name clash as access would be foo.a and foo.bar.a in C, same should apply in Java code.

I am more concerned about, as we have two anonymous in parallel, we should have a test case for something like this to
make sure out field mapping strategy would be able to find foo.[abcd] properly.

struct Foo {
    struct {
        int a : 7;
        int b : 25;
    };
    struct {
	int c : 12;
	int d : 12;
    };
};

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

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


More information about the panama-dev mailing list