[clang] [HLSL][Matrix] Add support for Matrix element and trunc Casts (PR #168915)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 2 09:10:40 PST 2025


================
@@ -12591,6 +12592,19 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
   if (auto VecTy = dyn_cast<VectorType>(Target))
     Target = VecTy->getElementType().getTypePtr();
 
+  if (isa<ConstantMatrixType>(Source)) {
+    if (!isa<ConstantMatrixType>(Target)) {
+      return DiagnoseImpCast(*this, E, T, CC, diag::warn_impcast_matrix_scalar);
+    } else if (getLangOpts().HLSL &&
----------------
farzonl wrote:

It can not happen in  non HLSL code. There is a bunch of earlier stuff already gating  the HLSL implicit cast. The getLangOpts().HLSL isn't necessary but thus far we always check ` if (getLangOpts().HLSL)` whenever doing a diagnostic warning or error that is specific to HLSL. Further if C++ ever did support an implicit cast then we would be exposing this warning to them. I think it makes sense to future proof and guard for HLSL for now and later future implementers can decide to add the truncation warning and generalize this diagnostic beyond HLSL.

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


More information about the cfe-commits mailing list