[PATCH] D127802: [HLSL] Support HLSL vector initializers
Chris Bieneman via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Jun 15 08:58:55 PDT 2022
beanz added inline comments.
================
Comment at: clang/test/SemaHLSL/BuiltIns/vector-constructors-erros.hlsl:12
+ float3 BrokenNormie = float3(3.0, 4.0); // expected-error{{too few elements in vector initialization (expected 3 elements, have 2)}}
+ float3 OverwhemledNormie = float3(3.0, 4.0, 5.0, 6.0); // expected-error{{excess elements in vector initializer}}
+}
----------------
aaron.ballman wrote:
> How do these examples behave:
> ```
> float f = 1.0f, g = 2.0f;
> float2 foo0 = float2(f, g); // Non-literal
>
> int i = 1, j = 2;
> float2 foo1 = float2(1, 2); // Integer literals
> float2 foo2 = float2(i, j); // Integer non-literal
>
> struct S { float f; } s;
> float2 foo3 = float2(s, s); // No potential type conversion possible
> float2 foo4 = float2(s.f, s.f); // Should work though?
>
> // and for good measure
> struct T {
> operator float() const;
> } t;
> float2 foo5 = float2(t, t); // Should work though?
>
> typedef float2 second_level_of_typedefs;
> second_level_of_typedefs foo6 = float2(1.0f, 2.0f); // Should work though?
> float2 foo7 = second_level_of_typedefs(1.0f, 2.0f); // Should work though?
> ```
I'll extend the test coverage to catch these cases.
> struct S { float f; } s;
> float2 foo3 = float2(s, s); // No potential type conversion possible
If you really want to regret reading this review... this actually is valid in HLSL. It isn't supported by this patch, but this is one of those odd behaviors I want to change in the language.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D127802/new/
https://reviews.llvm.org/D127802
More information about the cfe-commits
mailing list