https://github.com/tbaederr created 
https://github.com/llvm/llvm-project/pull/227998

A `ConstantExpr` with an lvalue  subexpression should always have an lvalue 
APValue result. 

>From e847fb50df168c247f9ee8ba520f5fdc1d5b37d6 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <[email protected]>
Date: Thu, 1 Oct 2026 10:54:21 +0200
Subject: [PATCH] asdf

---
 clang/include/clang/AST/Expr.h  | 12 +++++++++++-
 clang/lib/Sema/SemaDeclAttr.cpp | 16 +++++++++++++---
 2 files changed, 24 insertions(+), 4 deletions(-)

diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index a0324240ce34d..ed33fc93f2383 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -1095,8 +1095,12 @@ class FullExpr : public Expr {
 /// Describes the kind of result that can be tail-allocated.
 enum class ConstantResultStorageKind { None, Int64, APValue };
 
-/// ConstantExpr - An expression that occurs in a constant context and
+/// An expression that occurs in a constant context and
 /// optionally the result of evaluating the expression.
+///
+/// \invariant The subexpression of a ConstantExpr and its APValue must have 
the
+/// same value category. In practice, this means that an lvalue subexpression
+/// must also have an APValue of type LValue.
 class ConstantExpr final
     : public FullExpr,
       private llvm::TrailingObjects<ConstantExpr, APValue, uint64_t> {
@@ -1161,6 +1165,12 @@ class ConstantExpr final
   }
 
   void SetResult(APValue Value, const ASTContext &Context) {
+    if (getSubExpr()->isGLValue())
+      assert(Value.isLValue() &&
+             "SubExpr and APValue value category must match");
+    else
+      assert(getSubExpr()->isPRValue());
+
     MoveIntoResult(Value, Context);
   }
   void MoveIntoResult(APValue &Value, const ASTContext &Context);
diff --git a/clang/lib/Sema/SemaDeclAttr.cpp b/clang/lib/Sema/SemaDeclAttr.cpp
index eb4a8c2ab9ae0..3fce8589739cd 100644
--- a/clang/lib/Sema/SemaDeclAttr.cpp
+++ b/clang/lib/Sema/SemaDeclAttr.cpp
@@ -6261,9 +6261,19 @@ static void handleClusterDimsAttr(Sema &S, Decl *D, 
const ParsedAttr &AL) {
       !AL.checkAtMostNumArgs(S, /*Num=*/3))
     return;
 
-  S.addClusterDimsAttr(D, AL, AL.getArgAsExpr(0),
-                       AL.getNumArgs() > 1 ? AL.getArgAsExpr(1) : nullptr,
-                       AL.getNumArgs() > 2 ? AL.getArgAsExpr(2) : nullptr);
+  // Convert all arguments to rvalues.
+  ExprResult Converted1 = S.DefaultLvalueConversion(AL.getArgAsExpr(0));
+  assert(!Converted1.isInvalid());
+  ExprResult Converted2 = AL.getNumArgs() > 1
+                              ? S.DefaultLvalueConversion(AL.getArgAsExpr(1))
+                              : ExprResult();
+  ExprResult Converted3 = AL.getNumArgs() > 2
+                              ? S.DefaultLvalueConversion(AL.getArgAsExpr(2))
+                              : ExprResult();
+
+  S.addClusterDimsAttr(D, AL, Converted1.get(),
+                       Converted2.isInvalid() ? nullptr : Converted2.get(),
+                       Converted3.isInvalid() ? nullptr : Converted3.get());
 }
 
 static void handleNoClusterAttr(Sema &S, Decl *D, const ParsedAttr &AL) {

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to