[clang] [HLSL] Add __is_scalarized_layout_compatible (PR #102227)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 15 10:59:46 PDT 2024


llvm-beanz wrote:

> Is this the expected behaviour:
> 
> ```c++
> struct EmptyPadding : Empty { Empty e; int X; };
> struct Repeated : Empty, DerivedEmpty { int X; }; // expected-warning {{inaccessible due to ambiguity}}
> _Static_assert(sizeof(EmptyPadding) == 8, "");
> _Static_assert(sizeof(Repeated) == 8, "");
> _Static_assert(sizeof(NotEmpty) == 4, "");
> _Static_assert(__is_scalarized_layout_compatible(EmptyPadding, NotEmpty), "");
> _Static_assert(__is_scalarized_layout_compatible(Repeated, NotEmpty), "");
> ```
> 
> I.e., is the "scalarization" expected to get rid of padding? A similar issue happens with padding introduced by over-alignment.

Yes, the scalarized layout ignores padding. Because HLSL generally assumes that structures become fully scalarized with elements stored in registers we have way laxer requirements around structure layout for "local" memory.

> Also see [#98310 (comment)](https://github.com/llvm/llvm-project/issues/98310#issuecomment-2248326726): This should be renamed to `__builtin_is_scalarized_layout_compatible` to be consistent with new type traits.

Will do!


https://github.com/llvm/llvm-project/pull/102227


More information about the cfe-commits mailing list