[cfe-commits] r172102 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaStmt.cpp test/Sema/switch-1.c

Fariborz Jahanian fjahanian at apple.com
Thu Jan 10 12:26:43 PST 2013


Author: fjahanian
Date: Thu Jan 10 14:26:42 2013
New Revision: 172102

URL: http://llvm.org/viewvc/llvm-project?rev=172102&view=rev
Log:
Provide a better warning when case value overflows.
// rdar://11577384

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/switch-1.c

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=172102&r1=172101&r2=172102&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Thu Jan 10 14:26:42 2013
@@ -5712,6 +5712,9 @@
 def warn_case_value_overflow : Warning<
   "overflow converting case value to switch condition type (%0 to %1)">,
   InGroup<Switch>;
+def warn_case_constant_overflow : Warning<
+  "overflow in case constant expression results in new value (%0)">,
+  InGroup<DiagGroup<"switch">>;
 def err_duplicate_case : Error<"duplicate case value '%0'">;
 def err_duplicate_case_differing_expr : Error<
   "duplicate case value: '%0' and '%1' both equal '%2'">;

Modified: cfe/trunk/lib/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaStmt.cpp?rev=172102&r1=172101&r2=172102&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/lib/Sema/SemaStmt.cpp Thu Jan 10 14:26:42 2013
@@ -730,8 +730,8 @@
         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(Lo->getLocStart(), diag::warn_case_constant_overflow) <<
+            LoVal.toString(10);
           Diag(Diags[0].first, Diags[0].second);
         }
 

Modified: cfe/trunk/test/Sema/switch-1.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch-1.c?rev=172102&r1=172101&r2=172102&view=diff
==============================================================================
--- cfe/trunk/test/Sema/switch-1.c (original)
+++ cfe/trunk/test/Sema/switch-1.c Thu Jan 10 14:26:42 2013
@@ -5,10 +5,10 @@
 int f(int i) {
   switch (i) {
     case 2147483647 + 2: // expected-note {{value 2147483649 is outside the range of representable values of type 'int'}}  \
-                      // expected-warning {{overflow converting case value to switch condition type}} 
+                      // expected-warning {{overflow in case constant expression results in new value (-2147483647)}} 
       return 1;
     case 9223372036854775807L * 4 : // expected-note {{value 36893488147419103228 is outside the range of representable values of type 'long'}}   \
-                        // expected-warning {{overflow converting case value to switch condition type}} 
+                        // expected-warning {{overflow in case constant expression results in new value (-4)}} 
       return 2;
     case 2147483647:
       return 0;





More information about the cfe-commits mailing list