[clang] [HLSL] Vector standard conversions (PR #71098)

Chris B via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 14:03:17 PST 2024


================
@@ -6432,7 +6432,7 @@ void InitializationSequence::InitializeFrom(Sema &S,
   // For HLSL ext vector types we allow list initialization behavior for C++
   // constructor syntax. This is accomplished by converting initialization
   // arguments an InitListExpr late.
-  if (S.getLangOpts().HLSL && DestType->isExtVectorType() &&
+  if (S.getLangOpts().HLSL && Args.size() > 1 && DestType->isExtVectorType() &&
----------------
llvm-beanz wrote:

This is subtle but there are tests that cover this. The tests introduced here cover the `Args.size() == 1` case. Take this example:
```c++
void Fn(double2 D);
void Call(float2 F) {
  Fn(F);
}
```
In the call to `Fn` the argument becomes an implicit initialization list expression with one argument (fun right). In that case we rely on HLSL's standard conversion sequences to convert the first argument to the target type.

In other cases that we cover in the vector-constructors.hlsl test, we initialize vectors with initializer lists that are more than one argument like:

```c++
float2 f = float2(1, 2);
```

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


More information about the cfe-commits mailing list