[clang] [HLSL] Fix vector list initialization (PR #161421)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Tue Sep 30 12:03:34 PDT 2025


================
@@ -6817,33 +6820,17 @@ void InitializationSequence::InitializeFrom(Sema &S,
   assert(Args.size() >= 1 && "Zero-argument case handled above");
 
   // For HLSL ext vector types we allow list initialization behavior for C++
-  // constructor syntax. This is accomplished by converting initialization
-  // arguments an InitListExpr late.
+  // functional cast expressions which look like constructor syntax. This is
+  // accomplished by converting initialization arguments an InitListExpr.
   if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() &&
       (SourceType.isNull() ||
        !Context.hasSameUnqualifiedType(SourceType, DestType))) {
-
-    llvm::SmallVector<Expr *> InitArgs;
-    for (auto *Arg : Args) {
-      if (Arg->getType()->isExtVectorType()) {
-        const auto *VTy = Arg->getType()->castAs<ExtVectorType>();
-        unsigned Elm = VTy->getNumElements();
-        for (unsigned Idx = 0; Idx < Elm; ++Idx) {
-          InitArgs.emplace_back(new (Context) ArraySubscriptExpr(
-              Arg,
-              IntegerLiteral::Create(
-                  Context, llvm::APInt(Context.getIntWidth(Context.IntTy), Idx),
-                  Context.IntTy, SourceLocation()),
-              VTy->getElementType(), Arg->getValueKind(), Arg->getObjectKind(),
-              SourceLocation()));
-        }
-      } else
-        InitArgs.emplace_back(Arg);
-    }
     InitListExpr *ILE = new (Context) InitListExpr(
-        S.getASTContext(), SourceLocation(), InitArgs, SourceLocation());
+        S.getASTContext(), SourceLocation(), Args, SourceLocation());
----------------
farzonl wrote:

If we use SourceLocation() the source locations for columns become `<invalid sloc>>` Also can we update `clang/test/AST/HLSL/vector-constructors.hlsl` tests to include column numbers?

```suggestion
S.getASTContext(), Args[0]->getBeginLoc(), Args, Args[Args.size()-1]->getEndLoc());
```

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


More information about the cfe-commits mailing list