[PATCH] D127802: [HLSL] Support HLSL vector initializers

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Jun 15 08:13:18 PDT 2022


aaron.ballman added inline comments.


================
Comment at: clang/lib/Sema/SemaInit.cpp:5984
+        for (unsigned Idx = 0; Idx < Elm; ++Idx) {
+          InitArgs.emplace_back(new (Context) ArraySubscriptExpr(
+              Arg,
----------------
Huh, interesting -- I didn't realize we had AST nodes that didn't use `::Create()`. :-D


================
Comment at: clang/test/SemaHLSL/BuiltIns/vector-constructors-erros.hlsl:8
+void entry() {
+  float2 LilVec = float2(1.0, 2.0);
+  float2 BrokenVec = float2(1.0, 2.0, 3.0); // expected-error{{excess elements in vector initializer}}
----------------
beanz wrote:
> python3kgae wrote:
> > Could we have test case for array/struct when initialize vector?
> > Like
> > float a[2] = {1.2, 3.2};
> > float4 arrayVec = float4(a, 1.0, 2.0);
> This change does not support all of HLSL's odd initialization features. It only supports initializing vectors from scalars and vectors.
I'm surprised to see `float(1.0, 2.0)` work -- that's not list initialization, it's using round parens instead of curly braces so I'm pretty sure that's a function-style cast/constructor. Is that intentional?


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