[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
Tue Jan 16 05:18:11 PST 2024


================
@@ -437,6 +442,16 @@ namespace {
       MostDerivedArraySize = 2;
       MostDerivedPathLength = Entries.size();
     }
+    void addVectorUnchecked(QualType EltTy, uint64_t Size, uint64_t Idx) {
+      Entries.push_back(PathEntry::ArrayIndex(Idx));
+
+      // This is technically a most-derived object, though in practice this
+      // is unlikely to matter.
+      MostDerivedType = EltTy;
+      MostDerivedIsArrayElement = true;
+      MostDerivedArraySize = Size;
----------------
AaronBallman wrote:

> That said, I see it's what the `Complex` type is doing, and I whose elements I think are also not individually addressable, so 🤷

C23 6.2.5p17: Each complex type has the same representation and alignment requirements as an array type containing exactly two elements of the corresponding real type; the first element is equal to the real part, and the second element to the imaginary part, of the complex number.

CC @jcranmer-intel @arsenm for some other opinions on whether you should be able to address a vector type in a constant expression.

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


More information about the cfe-commits mailing list