diff options
author | Fariborz Jahanian <fjahanian@apple.com> | 2013-01-09 23:04:56 +0000 |
---|---|---|
committer | Fariborz Jahanian <fjahanian@apple.com> | 2013-01-09 23:04:56 +0000 |
commit | a18e70b25c85d7e653e642b5e6e58d6063af3d83 (patch) | |
tree | 3ed909ec4379a7032f622596801f2aad04e05ec9 /lib/Sema/SemaStmt.cpp | |
parent | 73189fb7077998a61e3251c65e136da3afcbc5af (diff) |
Issue warning when case value is too large to fit
in case condition type. // rdar://11577384.
Test is conditionalized on x86_64-apple triple as
I am not sure if the INT_MAX/LONG_MAX values in the test
will pass this test for other hosts.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@172016 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaStmt.cpp')
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 10 |
1 files changed, 9 insertions, 1 deletions
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. |