llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-hlsl

Author: Timm Baeder (tbaederr)

<details>
<summary>Changes</summary>

We want to discourage people from just checking if something is a constant 
expression without using the value, which we always compute anyways.

There are only three call sites, all in clang, and all pass a value already. 
Change the parameter type to a reference to enforce this.

---
Full diff: https://github.com/llvm/llvm-project/pull/226493.diff


4 Files Affected:

- (modified) clang/include/clang/AST/Expr.h (+1-1) 
- (modified) clang/lib/AST/ExprConstant.cpp (+4-7) 
- (modified) clang/lib/Sema/SemaHLSL.cpp (+1-1) 
- (modified) clang/lib/Sema/SemaOverload.cpp (+1-1) 


``````````diff
diff --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c03c88232e13d..a0324240ce34d 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -584,7 +584,7 @@ class Expr : public ValueStmt {
   /// If \p AllowRelaxedEval is \c true, this will allow certain constructs 
that
   /// are not valid per the specification.
   // FIXME: Add proper documentation about the constructs we allow.
-  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
+  bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue &Result,
                            bool AllowRelaxedEval = false) const;
 
   /// isPotentialConstantExpr - Return true if this function's definition
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index dea859382918b..9fbaf63e51e1f 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -22791,7 +22791,7 @@ EvaluateCPlusPlus11IntegralConstantExpr(const 
ASTContext &Ctx, const Expr *E,
     return false;
 
   APValue Result;
-  if (!E->isCXX11ConstantExpr(Ctx, &Result, AllowRelaxedEval))
+  if (!E->isCXX11ConstantExpr(Ctx, Result, AllowRelaxedEval))
     return false;
 
   if (!Result.isInt())
@@ -22857,7 +22857,7 @@ bool Expr::isCXX98IntegralConstantExpr(const ASTContext 
&Ctx) const {
   return CheckICE(this, Ctx).Kind == IK_ICE;
 }
 
-bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
+bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue &Result,
                                bool AllowRelaxedEval) const {
   assert(!isValueDependent() &&
          "Expression evaluator can't be called on a dependent expression.");
@@ -22868,11 +22868,8 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, 
APValue *Result,
 
   bool IsConst;
   APValue Scratch;
-  if (FastEvaluateAsRValue(this, Scratch, Ctx, IsConst) && Scratch.hasValue()) 
{
-    if (Result)
-      *Result = std::move(Scratch);
+  if (FastEvaluateAsRValue(this, Result, Ctx, IsConst) && Result.hasValue())
     return true;
-  }
 
   // Build evaluation settings.
   Expr::EvalStatus Status;
@@ -22881,7 +22878,7 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, 
APValue *Result,
   Status.ExtendedDiag = AllowRelaxedEval ? &MSRelaxedDiag : nullptr;
 
   bool IsConstExpr =
-      ::EvaluateAsRValue(Info, this, Result ? *Result : Scratch) &&
+      ::EvaluateAsRValue(Info, this, Result) &&
       // NOTE: We don't produce a diagnostic for this, but the callers that
       // call us on arbitrary full-expressions should generally not care.
       Info.discardCleanups() && !Status.HasSideEffects;
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index 124f5bd23a623..187b8d286a26f 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -6661,7 +6661,7 @@ bool SemaHLSL::handleInitialization(VarDecl *VDecl, Expr 
*&Init) {
   ASTContext &Context = SemaRef.getASTContext();
 
   APValue InitValue;
-  if (!Init->isCXX11ConstantExpr(Context, &InitValue)) {
+  if (!Init->isCXX11ConstantExpr(Context, InitValue)) {
     Diag(VDecl->getLocation(), diag::err_specialization_const);
     VDecl->setInvalidDecl();
     return false;
diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp
index 31422ab51d8b6..86c029ecd6995 100644
--- a/clang/lib/Sema/SemaOverload.cpp
+++ b/clang/lib/Sema/SemaOverload.cpp
@@ -483,7 +483,7 @@ NarrowingKind StandardConversionSequence::getNarrowingKind(
       Expr::EvalResult R;
       if ((Ctx.getLangOpts().C23 && Initializer->EvaluateAsRValue(R, Ctx)) ||
           ((Ctx.getLangOpts().CPlusPlus &&
-            Initializer->isCXX11ConstantExpr(Ctx, &ConstantValue,
+            Initializer->isCXX11ConstantExpr(Ctx, ConstantValue,
                                              AllowRelaxedEval)))) {
         // Constant!
         if (Ctx.getLangOpts().C23)

``````````

</details>


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

Reply via email to