[cfe-commits] r41317 - in /cfe/trunk: Sema/SemaStmt.cpp test/Sema/switch.c

Chris Lattner sabre at nondot.org
Thu Aug 23 07:29:08 PDT 2007


Author: lattner
Date: Thu Aug 23 09:29:07 2007
New Revision: 41317

URL: http://llvm.org/viewvc/llvm-project?rev=41317&view=rev
Log:
fix a segfault in cases where there are no cases.

Modified:
    cfe/trunk/Sema/SemaStmt.cpp
    cfe/trunk/test/Sema/switch.c

Modified: cfe/trunk/Sema/SemaStmt.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/Sema/SemaStmt.cpp?rev=41317&r1=41316&r2=41317&view=diff

==============================================================================
--- cfe/trunk/Sema/SemaStmt.cpp (original)
+++ cfe/trunk/Sema/SemaStmt.cpp Thu Aug 23 09:29:07 2007
@@ -274,16 +274,18 @@
   // Sort all the scalar case values so we can easily detect duplicates.
   std::stable_sort(CaseVals.begin(), CaseVals.end());
   
-  for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
-    if (CaseVals[i].first == CaseVals[i+1].first) {
-      // If we have a duplicate, report it.
-      Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
-           diag::err_duplicate_case, CaseVals[i].first.toString());
-      Diag(CaseVals[i].second->getLHS()->getLocStart(), 
-           diag::err_duplicate_case_prev);
-      // FIXME: We really want to remove the bogus case stmt from the substmt,
-      // but we have no way to do this right now.
-      CaseListIsErroneous = true;
+  if (!CaseVals.empty()) {
+    for (unsigned i = 0, e = CaseVals.size()-1; i != e; ++i) {
+      if (CaseVals[i].first == CaseVals[i+1].first) {
+        // If we have a duplicate, report it.
+        Diag(CaseVals[i+1].second->getLHS()->getLocStart(),
+             diag::err_duplicate_case, CaseVals[i].first.toString());
+        Diag(CaseVals[i].second->getLHS()->getLocStart(), 
+             diag::err_duplicate_case_prev);
+        // FIXME: We really want to remove the bogus case stmt from the substmt,
+        // but we have no way to do this right now.
+        CaseListIsErroneous = true;
+      }
     }
   }
   

Modified: cfe/trunk/test/Sema/switch.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/switch.c?rev=41317&r1=41316&r2=41317&view=diff

==============================================================================
--- cfe/trunk/test/Sema/switch.c (original)
+++ cfe/trunk/test/Sema/switch.c Thu Aug 23 09:29:07 2007
@@ -15,3 +15,7 @@
   }
 }
 
+void test3(void) { 
+  switch (0); 
+}
+





More information about the cfe-commits mailing list