[clang] [clang][AST] Assert that ConstantExpr type and APValue kind match (PR #230388)

Eli Friedman via cfe-commits cfe-commits at lists.llvm.org
Sat Oct 10 11:41:19 PDT 2026


Timm =?utf-8?q?Bäder?= <tbaeder at redhat.com>
Message-ID:
In-Reply-To: <llvm.org/llvm/llvm-project/pull/230388 at github.com>


================
@@ -319,6 +319,107 @@ ConstantResultStorageKind ConstantExpr::getStorageKind(const APValue &Value) {
   }
 }
 
+// Check that V is a valid APValue result of E, i.e. the node type needs to
+// match the APValue kind.
+static void assertAPValueKind(const ConstantExpr *E, const APValue &V) {
+  // FIXME: We shouldn't be creating ConstantExpr nodes for missing APValues in
+  // the first place, but for the time being, accept this for any type.
+  if (V.isAbsent())
+    return;
+
+  if (E->isGLValue()) {
+    // NOTE: The restrictions for lvalue expressions are not 100% clear. We
+    // can't assert(V.isLValue()) because some ConstantExprs are lvalue and
+    // their result is a string literal, so an Array.
----------------
efriedma-quic wrote:

Oh, I see.

Maybe we should have a cast kind for "array lvalue-to-rvalue conversion", and use that in cases where we treat a string as an rvalue.  (This is similar to HLSLArrayRValue cast.)

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


More information about the cfe-commits mailing list