diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/ExprConstant.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 10 |
2 files changed, 12 insertions, 2 deletions
diff --git a/lib/AST/ExprConstant.cpp b/lib/AST/ExprConstant.cpp index 338cd74b32..622f37b178 100644 --- a/lib/AST/ExprConstant.cpp +++ b/lib/AST/ExprConstant.cpp @@ -6364,8 +6364,10 @@ bool Expr::isEvaluatable(const ASTContext &Ctx) const { return EvaluateAsRValue(Result, Ctx) && !Result.HasSideEffects; } -APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx) const { +APSInt Expr::EvaluateKnownConstInt(const ASTContext &Ctx, + llvm::SmallVectorImpl<PartialDiagnosticAt> *Diag) const { EvalResult EvalResult; + EvalResult.Diag = Diag; bool Result = EvaluateAsRValue(EvalResult, Ctx); (void)Result; assert(Result && "Could not evaluate expression"); diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index 08f78d06ca..592c6a6b74 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -13,6 +13,7 @@ #include "clang/Sema/SemaInternal.h" #include "clang/AST/ASTContext.h" +#include "clang/AST/ASTDiagnostic.h" #include "clang/AST/CharUnits.h" #include "clang/AST/DeclObjC.h" #include "clang/AST/EvaluatedExprVisitor.h" @@ -725,7 +726,14 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, Stmt *Switch, } else { // We already verified that the expression has a i-c-e value (C99 // 6.8.4.2p3) - get that value now. - LoVal = Lo->EvaluateKnownConstInt(Context); + llvm::SmallVector<PartialDiagnosticAt, 8> Diags; + LoVal = Lo->EvaluateKnownConstInt(Context, &Diags); + if (Diags.size() == 1 && + Diags[0].second.getDiagID() == diag::note_constexpr_overflow) { + Diag(Lo->getLocStart(), diag::warn_case_value_overflow) << + LoVal.toString(10) << "switch condition value"; + Diag(Diags[0].first, Diags[0].second); + } // If the LHS is not the same type as the condition, insert an implicit // cast. |