[clang] [clang][ExprConst] allow single element access of vector object to be constant expression (PR #72607)

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Wed Dec 6 11:53:54 PST 2023


================
@@ -8721,15 +8771,63 @@ bool LValueExprEvaluator::VisitMemberExpr(const MemberExpr *E) {
   return LValueExprEvaluatorBaseTy::VisitMemberExpr(E);
 }
 
+bool LValueExprEvaluator::VisitExtVectorElementExpr(
+    const ExtVectorElementExpr *E) {
+  bool Success = true;
+
+  APValue Val;
+  if (!Evaluate(Val, Info, E->getBase())) {
+    if (!Info.noteFailure())
+      return false;
+    Success = false;
+  }
+
+  SmallVector<uint32_t, 4> Indices;
+  E->getEncodedElementAccess(Indices);
+  // FIXME: support accessing more than one element
+  if (Indices.size() > 1)
+    return false;
+
+  if (Success) {
+    Result.setFrom(Info.Ctx, Val);
+    const VectorType *VT = E->getBase()->getType()->castAs<VectorType>();
----------------
AaronBallman wrote:

```suggestion
    const auto *VT = E->getBase()->getType()->castAs<VectorType>();
```

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


More information about the cfe-commits mailing list