[clang] [OpenCL] Diagnose invalid conversion from pointer to vector (PR #180318)

Wenju He via cfe-commits cfe-commits at lists.llvm.org
Fri Feb 6 20:29:55 PST 2026


================
@@ -8112,6 +8112,13 @@ ExprResult Sema::BuildVectorLiteral(SourceLocation LParenLoc,
     // it will be replicated to all components of the vector.
     if (getLangOpts().OpenCL && VTy->getVectorKind() == VectorKind::Generic &&
         numExprs == 1) {
+      QualType SrcTy = exprs[0]->getType();
+      if (!SrcTy->isArithmeticType()) {
+        Diag(exprs[0]->getBeginLoc(), diag::err_typecheck_convert_incompatible)
+            << Ty << SrcTy << AssignmentAction::Initializing << /*elidable=*/0
+            << /*c_style=*/0 << /*cast_kind=*/"" << exprs[0]->getSourceRange();
+        return ExprError();
+      }
----------------
wenju-he wrote:

> (int4)((short4)x)

This will be diagnosed earlier at https://github.com/llvm/llvm-project/blob/2a2a394215b38631588d504d2b671df13370395b/clang/lib/Sema/SemaExpr.cpp#L7927

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


More information about the cfe-commits mailing list