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

Mital Ashok via cfe-commits cfe-commits at lists.llvm.org
Thu Aug 8 06:03:34 PDT 2024


MitalAshok 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.

Also see https://github.com/llvm/llvm-project/issues/98310#issuecomment-2248326726: This might need to be renamed to `__builtin_is_scalarized_layout_compatible` to be consistent with new type traits. Unsure if this applies to HLSL or Clang-only extensions (I'll ask for confirmation), but the logic is that standard libraries can use `__is_scalarized_layout_compatible` and the compiler provides `__builtin_is_scalarized_layout_compatible`.

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


More information about the cfe-commits mailing list