[clang] [HLSL] error on out of bounds vector accesses (PR #128952)

Sarah Spall via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 27 13:16:30 PST 2025


================
@@ -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;
----------------
spall wrote:

There is a test which is meant to prevent new enabled by default warnings; Misc/warning-flags.c, which gives the impression that new by default warnings are not allowed. Or I'm misunderstanding what a default warning is. 

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


More information about the cfe-commits mailing list