[llvm-commits] [llvm] r86846 - /llvm/trunk/lib/VMCore/Verifier.cpp

Chris Lattner sabre at nondot.org
Wed Nov 11 09:37:02 PST 2009


Author: lattner
Date: Wed Nov 11 11:37:02 2009
New Revision: 86846

URL: http://llvm.org/viewvc/llvm-project?rev=86846&view=rev
Log:
Reject duplicate case values in a switch, PR5450.

Modified:
    llvm/trunk/lib/VMCore/Verifier.cpp

Modified: llvm/trunk/lib/VMCore/Verifier.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Verifier.cpp?rev=86846&r1=86845&r2=86846&view=diff

==============================================================================
--- llvm/trunk/lib/VMCore/Verifier.cpp (original)
+++ llvm/trunk/lib/VMCore/Verifier.cpp Wed Nov 11 11:37:02 2009
@@ -780,9 +780,13 @@
   // Check to make sure that all of the constants in the switch instruction
   // have the same type as the switched-on value.
   const Type *SwitchTy = SI.getCondition()->getType();
-  for (unsigned i = 1, e = SI.getNumCases(); i != e; ++i)
+  SmallPtrSet<ConstantInt*, 32> Constants;
+  for (unsigned i = 1, e = SI.getNumCases(); i != e; ++i) {
     Assert1(SI.getCaseValue(i)->getType() == SwitchTy,
             "Switch constants must all be same type as switch value!", &SI);
+    Assert2(Constants.insert(SI.getCaseValue(i)),
+            "Duplicate integer as switch case", &SI, SI.getCaseValue(i));
+  }
 
   visitTerminatorInst(SI);
 }





More information about the llvm-commits mailing list