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

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 19 14:06:36 PDT 2025


================
@@ -14054,6 +14054,23 @@ void Sema::CheckCastAlign(Expr *Op, QualType T, SourceRange TRange) {
     << TRange << Op->getSourceRange();
 }
 
+void Sema::CheckVectorAccess(const Expr *BaseExpr, const Expr *IndexExpr) {
+  const auto *VTy = BaseExpr->getType()->getAs<VectorType>();
+  if (!VTy)
+    return;
+
+  Expr::EvalResult Result;
+  if (!IndexExpr->EvaluateAsInt(Result, Context, Expr::SE_AllowSideEffects))
----------------
efriedma-quic wrote:

Generally, if a value is not required to be a constant, we don't want different semantic rules depending on whether the value is in fact constant.  (There are a few places that do in fact work like this, like array bounds, but it causes weird results. Especially when people do stuff with macros.)  So I don't think we want to reject here.

A DiagRuntimeBehavior() is probably appropriate, though.

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


More information about the cfe-commits mailing list