Simplify: we don't care why constant evaluation might have failed when we're

checking an expression for constant overflow.

llvm-svn: 194099
This commit is contained in:
Richard Smith 2013-11-05 22:23:30 +00:00
parent 6d4c6586c9
commit e9ff770f8b
3 changed files with 8 additions and 14 deletions

View File

@ -579,15 +579,14 @@ public:
/// \brief Determine whether this expression involves a call to any function /// \brief Determine whether this expression involves a call to any function
/// that is not trivial. /// that is not trivial.
bool hasNonTrivialCall(ASTContext &Ctx); bool hasNonTrivialCall(ASTContext &Ctx);
/// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded /// EvaluateKnownConstInt - Call EvaluateAsRValue and return the folded
/// integer. This must be called on an expression that constant folds to an /// integer. This must be called on an expression that constant folds to an
/// integer. /// integer.
llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx, llvm::APSInt EvaluateKnownConstInt(const ASTContext &Ctx,
SmallVectorImpl<PartialDiagnosticAt> *Diag=0) const; SmallVectorImpl<PartialDiagnosticAt> *Diag=0) const;
void EvaluateForOverflow(const ASTContext &Ctx, void EvaluateForOverflow(const ASTContext &Ctx) const;
SmallVectorImpl<PartialDiagnosticAt> *Diag) const;
/// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an /// EvaluateAsLValue - Evaluate an expression to see if we can fold it to an
/// lvalue with link time known address, with no side-effects. /// lvalue with link time known address, with no side-effects.

View File

@ -566,12 +566,12 @@ namespace {
switch (EvalMode) { switch (EvalMode) {
case EM_ConstantExpression: case EM_ConstantExpression:
case EM_PotentialConstantExpression: case EM_PotentialConstantExpression:
case EM_EvaluateForOverflow:
HasActiveDiagnostic = false; HasActiveDiagnostic = false;
return OptionalDiagnostic(); return OptionalDiagnostic();
case EM_ConstantFold: case EM_ConstantFold:
case EM_IgnoreSideEffects: case EM_IgnoreSideEffects:
case EM_EvaluateForOverflow:
break; break;
} }
} }
@ -615,8 +615,7 @@ namespace {
unsigned ExtraNotes = 0) { unsigned ExtraNotes = 0) {
// Don't override a previous diagnostic. Don't bother collecting // Don't override a previous diagnostic. Don't bother collecting
// diagnostics if we're evaluating for overflow. // diagnostics if we're evaluating for overflow.
if (!EvalStatus.Diag || !EvalStatus.Diag->empty() || if (!EvalStatus.Diag || !EvalStatus.Diag->empty()) {
EvalMode == EM_EvaluateForOverflow) {
HasActiveDiagnostic = false; HasActiveDiagnostic = false;
return OptionalDiagnostic(); return OptionalDiagnostic();
} }
@ -8133,11 +8132,9 @@ APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx,
return EvalResult.Val.getInt(); return EvalResult.Val.getInt();
} }
void Expr::EvaluateForOverflow(const ASTContext &Ctx, void Expr::EvaluateForOverflow(const ASTContext &Ctx) const {
SmallVectorImpl<PartialDiagnosticAt> *Diags) const {
bool IsConst; bool IsConst;
EvalResult EvalResult; EvalResult EvalResult;
EvalResult.Diag = Diags;
if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) { if (!FastEvaluateAsRValue(this, EvalResult, Ctx, IsConst)) {
EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow); EvalInfo Info(Ctx, EvalResult, EvalInfo::EM_EvaluateForOverflow);
(void)::EvaluateAsRValue(Info, this, EvalResult.Val); (void)::EvaluateAsRValue(Info, this, EvalResult.Val);

View File

@ -5620,10 +5620,8 @@ void Sema::CheckImplicitConversions(Expr *E, SourceLocation CC) {
/// Diagnose when expression is an integer constant expression and its evaluation /// Diagnose when expression is an integer constant expression and its evaluation
/// results in integer overflow /// results in integer overflow
void Sema::CheckForIntOverflow (Expr *E) { void Sema::CheckForIntOverflow (Expr *E) {
if (isa<BinaryOperator>(E->IgnoreParens())) { if (isa<BinaryOperator>(E->IgnoreParens()))
SmallVector<PartialDiagnosticAt, 4> Diags; E->EvaluateForOverflow(Context);
E->EvaluateForOverflow(Context, &Diags);
}
} }
namespace { namespace {