Skip to content

Commit d8ca85a

Browse files
authored
[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.
1 parent f48a8da commit d8ca85a

File tree

3 files changed

+22
-43
lines changed

3 files changed

+22
-43
lines changed

clang/include/clang/AST/Expr.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -553,17 +553,13 @@ class Expr : public ValueStmt {
553553
bool IgnoreTemplateOrMacroSubstitution = false) const;
554554

555555
/// isIntegerConstantExpr - Return the value if this expression is a valid
556-
/// integer constant expression. If not a valid i-c-e, return std::nullopt
557-
/// and fill in Loc (if specified) with the location of the invalid
558-
/// expression.
556+
/// integer constant expression. If not a valid i-c-e, return std::nullopt.
559557
///
560558
/// Note: This does not perform the implicit conversions required by C++11
561559
/// [expr.const]p5.
562560
std::optional<llvm::APSInt>
563-
getIntegerConstantExpr(const ASTContext &Ctx,
564-
SourceLocation *Loc = nullptr) const;
565-
bool isIntegerConstantExpr(const ASTContext &Ctx,
566-
SourceLocation *Loc = nullptr) const;
561+
getIntegerConstantExpr(const ASTContext &Ctx) const;
562+
bool isIntegerConstantExpr(const ASTContext &Ctx) const;
567563

568564
/// isCXX98IntegralConstantExpr - Return true if this expression is an
569565
/// integral constant expression in C++98. Can only be used in C++.
@@ -574,8 +570,8 @@ class Expr : public ValueStmt {
574570
///
575571
/// Note: This does not perform the implicit conversions required by C++11
576572
/// [expr.const]p5.
577-
bool isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result = nullptr,
578-
SourceLocation *Loc = nullptr) const;
573+
bool isCXX11ConstantExpr(const ASTContext &Ctx,
574+
APValue *Result = nullptr) const;
579575

580576
/// isPotentialConstantExpr - Return true if this function's definition
581577
/// might be usable in a constant expression in C++11, if it were marked

clang/lib/AST/ExprConstant.cpp

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -17312,8 +17312,7 @@ bool Expr::EvalResult::isGlobalLValue() const {
1731217312
/// comma, etc
1731317313

1731417314
// CheckICE - This function does the fundamental ICE checking: the returned
17315-
// ICEDiag contains an ICEKind indicating whether the expression is an ICE,
17316-
// and a (possibly null) SourceLocation indicating the location of the problem.
17315+
// ICEDiag contains an ICEKind indicating whether the expression is an ICE.
1731717316
//
1731817317
// Note that to reduce code duplication, this helper does no evaluation
1731917318
// itself; the caller checks whether the expression is evaluatable, and
@@ -17777,46 +17776,38 @@ static ICEDiag CheckICE(const Expr* E, const ASTContext &Ctx) {
1777717776
/// Evaluate an expression as a C++11 integral constant expression.
1777817777
static bool EvaluateCPlusPlus11IntegralConstantExpr(const ASTContext &Ctx,
1777917778
const Expr *E,
17780-
llvm::APSInt *Value,
17781-
SourceLocation *Loc) {
17782-
if (!E->getType()->isIntegralOrUnscopedEnumerationType()) {
17783-
if (Loc) *Loc = E->getExprLoc();
17779+
llvm::APSInt *Value) {
17780+
if (!E->getType()->isIntegralOrUnscopedEnumerationType())
1778417781
return false;
17785-
}
1778617782

1778717783
APValue Result;
17788-
if (!E->isCXX11ConstantExpr(Ctx, &Result, Loc))
17784+
if (!E->isCXX11ConstantExpr(Ctx, &Result))
1778917785
return false;
1779017786

17791-
if (!Result.isInt()) {
17792-
if (Loc) *Loc = E->getExprLoc();
17787+
if (!Result.isInt())
1779317788
return false;
17794-
}
1779517789

1779617790
if (Value) *Value = Result.getInt();
1779717791
return true;
1779817792
}
1779917793

17800-
bool Expr::isIntegerConstantExpr(const ASTContext &Ctx,
17801-
SourceLocation *Loc) const {
17794+
bool Expr::isIntegerConstantExpr(const ASTContext &Ctx) const {
1780217795
assert(!isValueDependent() &&
1780317796
"Expression evaluator can't be called on a dependent expression.");
1780417797

1780517798
ExprTimeTraceScope TimeScope(this, Ctx, "isIntegerConstantExpr");
1780617799

1780717800
if (Ctx.getLangOpts().CPlusPlus11)
17808-
return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr, Loc);
17801+
return EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, nullptr);
1780917802

1781017803
ICEDiag D = CheckICE(this, Ctx);
17811-
if (D.Kind != IK_ICE) {
17812-
if (Loc) *Loc = D.Loc;
17804+
if (D.Kind != IK_ICE)
1781317805
return false;
17814-
}
1781517806
return true;
1781617807
}
1781717808

1781817809
std::optional<llvm::APSInt>
17819-
Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
17810+
Expr::getIntegerConstantExpr(const ASTContext &Ctx) const {
1782017811
if (isValueDependent()) {
1782117812
// Expression evaluator can't succeed on a dependent expression.
1782217813
return std::nullopt;
@@ -17825,12 +17816,12 @@ Expr::getIntegerConstantExpr(const ASTContext &Ctx, SourceLocation *Loc) const {
1782517816
APSInt Value;
1782617817

1782717818
if (Ctx.getLangOpts().CPlusPlus11) {
17828-
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value, Loc))
17819+
if (EvaluateCPlusPlus11IntegralConstantExpr(Ctx, this, &Value))
1782917820
return Value;
1783017821
return std::nullopt;
1783117822
}
1783217823

17833-
if (!isIntegerConstantExpr(Ctx, Loc))
17824+
if (!isIntegerConstantExpr(Ctx))
1783417825
return std::nullopt;
1783517826

1783617827
// The only possible side-effects here are due to UB discovered in the
@@ -17855,8 +17846,7 @@ bool Expr::isCXX98IntegralConstantExpr(const ASTContext &Ctx) const {
1785517846
return CheckICE(this, Ctx).Kind == IK_ICE;
1785617847
}
1785717848

17858-
bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
17859-
SourceLocation *Loc) const {
17849+
bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result) const {
1786017850
assert(!isValueDependent() &&
1786117851
"Expression evaluator can't be called on a dependent expression.");
1786217852

@@ -17877,15 +17867,7 @@ bool Expr::isCXX11ConstantExpr(const ASTContext &Ctx, APValue *Result,
1787717867
// call us on arbitrary full-expressions should generally not care.
1787817868
Info.discardCleanups() && !Status.HasSideEffects;
1787917869

17880-
if (!Diags.empty()) {
17881-
IsConstExpr = false;
17882-
if (Loc) *Loc = Diags[0].first;
17883-
} else if (!IsConstExpr) {
17884-
// FIXME: This shouldn't happen.
17885-
if (Loc) *Loc = getExprLoc();
17886-
}
17887-
17888-
return IsConstExpr;
17870+
return IsConstExpr && Diags.empty();
1788917871
}
1789017872

1789117873
bool Expr::EvaluateWithSubstitution(APValue &Value, ASTContext &Ctx,

clang/lib/Sema/SemaDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14724,9 +14724,10 @@ void Sema::CheckCompleteVariableDeclaration(VarDecl *var) {
1472414724
type->isIntegralOrEnumerationType()) {
1472514725
// In C++98, in-class initialization for a static data member must
1472614726
// be an integer constant expression.
14727-
SourceLocation Loc;
14728-
if (!Init->isIntegerConstantExpr(Context, &Loc)) {
14729-
Diag(Loc, diag::ext_in_class_initializer_non_constant)
14727+
// SourceLocation Loc;
14728+
if (!Init->isIntegerConstantExpr(Context)) {
14729+
Diag(Init->getExprLoc(),
14730+
diag::ext_in_class_initializer_non_constant)
1473014731
<< Init->getSourceRange();
1473114732
}
1473214733
}

0 commit comments

Comments
 (0)