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

Justin Bogner via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 14 12:02:25 PST 2024


================
@@ -4772,6 +4788,76 @@ Sema::PerformImplicitConversion(Expr *From, QualType ToType,
     llvm_unreachable("Improper second standard conversion");
   }
 
+  if (SCS.Element != ICK_Identity) {
+    // If SCS.Element is not ICK_Identity the To and From types must be HLSL
+    // vectors or matrices. HLSL matrices aren't yet supported so this code only
+    // handles vectors for now.
+
+    assert(From->getType()->isVectorType() && ToType->isVectorType() &&
+           "Element conversion is only supported for vector types.");
+    assert(From->getType()->getAs<VectorType>()->getNumElements() ==
+               ToType->getAs<VectorType>()->getNumElements() &&
+           "Element conversion is only supported for vectors with the same "
+           "element counts.");
+    QualType FromElTy = From->getType()->getAs<VectorType>()->getElementType();
+    unsigned NumElts = ToType->getAs<VectorType>()->getNumElements();
+    switch (SCS.Element) {
+    case ICK_Identity:
+      // Nothing to do.
+      break;
----------------
bogner wrote:

`SCS.Element == ICK_Identity` is unreachable - we checked above

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


More information about the cfe-commits mailing list