================
@@ -14017,6 +14017,24 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, 
SourceRange TRange) {
     << TRange << Op->getSourceRange();
 }
 
+void Sema::CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr) {
+  const VectorType *VTy = BaseExpr->getType()->getAs<VectorType>();
+  if (!VTy)
+    return;
+
+  Expr::EvalResult Result;
+  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
+    return;
+
+  unsigned DiagID = getLangOpts().HLSL ? diag::err_vector_index_out_of_range
+                                       : diag::warn_vector_index_out_of_range;
----------------
llvm-beanz wrote:

@svenvh are you okay with this becoming an error for OpenCL?

If we make it an error everywhere that would simplify this patch. I had mostly 
thought to make it a warning to avoid disrupting users, but this is a case 
where it would 100% be an out-of-bounds access unless the generated code 
happens to get optimized away.

The vector element access expressions already error on out of bounds element 
accessors for all languages, so this probably isn't too far out of reasonable 
expectations.

https://github.com/llvm/llvm-project/pull/128952
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to