On Mon, 7 Oct 2024 11:27:33 GMT, Vladimir Kozelkov <d...@openjdk.org> wrote:

> Another test example. I can create a structure ending with PaddingLayout
> 
> ```
> {
>     Linker linker = Linker.nativeLinker();
>     var sequence0a8 = MemoryLayout.sequenceLayout(0, JAVA_LONG);
>     var sequence3a1 = MemoryLayout.sequenceLayout(3, JAVA_BYTE);
>     var padding5a1 = MemoryLayout.paddingLayout(5);
>     var struct8a8 = MemoryLayout.structLayout(sequence0a8, sequence3a1, 
> padding5a1);
>     var fd = FunctionDescriptor.of(struct8a8, struct8a8, struct8a8);
>     linker.downcallHandle(fd);
> }
> ```
> 
> Is it just me or is this a legal way to create an over-aligned layout?
> 
> ```
> {
>     Linker linker = Linker.nativeLinker();
>     var sequence0a8 = MemoryLayout.sequenceLayout(0, JAVA_LONG);
>     var sequence8a1 = MemoryLayout.sequenceLayout(8, JAVA_BYTE);
>     var struct8a8 = MemoryLayout.structLayout(sequence0a8, sequence8a1);
>     var fd = FunctionDescriptor.of(struct8a8, struct8a8, struct8a8);
>     linker.downcallHandle(fd);
> }
> ```
> 
> If I remove the PaddingLayout, the structure appears to be completely normal, 
> except that it doesn't contain a single real element that needs alignment 8

I think the new rules should explicitly ban zero-element sequence layouts.

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

PR Comment: https://git.openjdk.org/jdk/pull/21041#issuecomment-2396840477

Reply via email to