aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/AST/ExprConstant.cpp
diff options
context:
space:
mode:
authorTimm Baeder <tbaeder@redhat.com>2025-08-01 14:09:06 +0200
committerGitHub <noreply@github.com>2025-08-01 14:09:06 +0200
commitd8ca85a184c0fb511fe6483c4c24e48b5b1eb07a (patch)
treefb3d6c7bcecb5461909a126031cf5b2a530f6651 /clang/lib/AST/ExprConstant.cpp
parentf48a8da34292b367ba8a5e7b25065172df966848 (diff)
downloadllvm-d8ca85a184c0fb511fe6483c4c24e48b5b1eb07a.zip
llvm-d8ca85a184c0fb511fe6483c4c24e48b5b1eb07a.tar.gz
llvm-d8ca85a184c0fb511fe6483c4c24e48b5b1eb07a.tar.bz2
[clang][ExprConst] Remove Loc param (#151461)
The Loc param to these functions was weird and not always set in error cases. It wasn't reliable to use. This was almost entirely unused inside of clang and the one call site that used the returned source location doesn't make a difference in practice.
Diffstat (limited to 'clang/lib/AST/ExprConstant.cpp')
-rw-r--r--clang/lib/AST/ExprConstant.cpp44
1 files changed, 13 insertions, 31 deletions
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 993b64b..244fd92 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -17312,8 +17312,7 @@ bool Expr::EvalResult::isGlobalLValue() const {
/// comma, etc
// CheckICE - This function does the fundamental ICE checking: the returned
-// ICEDiag contains an ICEKind indicating whether the expression is an ICE,
-// and a (possibly null) SourceLocation indicating the location of the problem.
+// ICEDiag contains an ICEKind indicating whether the expression is an ICE.
//
// Note that to reduce code duplication, this helper does no evaluation
// itself; the caller checks whether the expression is evaluatable, and
@@ -17777,46 +17776,38 @@ static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) {
/// Evaluate an expression as a C++11 integral constant expression.
static bool EvaluateCPlusPlus11IntegralConstantExpr(const ASTContext &Ctx,
const Expr *E,
- llvm::APSInt *Value,
- SourceLocation *Loc) {
- if (!E->getType()->isIntegralOrUnscopedEnumerationType()) {
- if (Loc) *Loc = E->getExprLoc();
+ llvm::APSInt *Value) {
+ if (!E->getType()->isIntegralOrUnscopedEnumerationType())
return false;
- }
APValue Result;
- if (!E->isCXX11ConstantExpr(Ctx, &Result, Loc))
+ if (!E->isCXX11ConstantExpr(Ctx, &Result))
return false;
- if (!Result.isInt()) {
- if (Loc) *Loc = E->getExprLoc();
+ if (!Result.isInt())
return false;
- }
if (Value) *Value = Result.getInt();
return true;
}
-bool Expr::isIntegerConstantExpr(const ASTContext &Ctx,
- SourceLocation *Loc) const {
+bool Expr::isIntegerConstantExpr(const ASTContext &Ctx) const {
assert(!isValueDependent() &&
"Expression evaluator can't be called on a dependent expression.");
ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
if (Ctx.getLangOpts().CPlusPlus11)
- return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr, Loc);
+ return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr);
ICEDiag D = CheckICE(this, Ctx);
- if (D.Kind != IK_ICE) {
- if (Loc) *Loc = D.Loc;
+ if (D.Kind != IK_ICE)
return false;
- }
return true;
}
std::optional<llvm::APSInt>
-Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
+Expr::getIntegerConstantExpr(const ASTContext &Ctx) const {
if (isValueDependent()) {
// Expression evaluator can't succeed on a dependent expression.
return std::nullopt;
@@ -17825,12 +17816,12 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
APSInt Value;
if (Ctx.getLangOpts().CPlusPlus11) {
- if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc))
+ if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value))
return Value;
return std::nullopt;
}
- if (!isIntegerConstantExpr(Ctx, Loc))
+ if (!isIntegerConstantExpr(Ctx))
return std::nullopt;
// The only possible side-effects here are due to UB discovered in the
@@ -17855,8 +17846,7 @@ bool Expr::isCXX98IntegralConstantExpr(const ASTContext &Ctx) const {
return CheckICE(this, Ctx).Kind == IK_ICE;
}
-bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
- SourceLocation *Loc) const {
+bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result) const {
assert(!isValueDependent() &&
"Expression evaluator can't be called on a dependent expression.");
@@ -17877,15 +17867,7 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
// call us on arbitrary full-expressions should generally not care.
Info.discardCleanups() && !Status.HasSideEffects;
- if (!Diags.empty()) {
- IsConstExpr = false;
- if (Loc) *Loc = Diags[0].first;
- } else if (!IsConstExpr) {
- // FIXME: This shouldn't happen.
- if (Loc) *Loc = getExprLoc();
- }
-
- return IsConstExpr;
+ return IsConstExpr && Diags.empty();
}
bool Expr::EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,