[llvm-commits] CVS: llvm/lib/VMCore/Verifier.cpp

Chris Lattner lattner at cs.uiuc.edu
Fri May 21 11:49:01 PDT 2004


Changes in directory llvm/lib/VMCore:

Verifier.cpp updated: 1.98 -> 1.99

---
Log message:

Fix for PR340: http://llvm.cs.uiuc.edu/PR340 : Verifier misses malformed switch instruction


---
Diffs of the changes:  (+12 -0)

Index: llvm/lib/VMCore/Verifier.cpp
diff -u llvm/lib/VMCore/Verifier.cpp:1.98 llvm/lib/VMCore/Verifier.cpp:1.99
--- llvm/lib/VMCore/Verifier.cpp:1.98	Mon May 17 16:15:18 2004
+++ llvm/lib/VMCore/Verifier.cpp	Fri May 21 11:47:21 2004
@@ -173,6 +173,7 @@
     void visitInstruction(Instruction &I);
     void visitTerminatorInst(TerminatorInst &I);
     void visitReturnInst(ReturnInst &RI);
+    void visitSwitchInst(SwitchInst &SI);
     void visitSelectInst(SelectInst &SI);
     void visitUserOp1(Instruction &I);
     void visitUserOp2(Instruction &I) { visitUserOp1(I); }
@@ -360,6 +361,17 @@
   // Check to make sure that the return value has necessary properties for
   // terminators...
   visitTerminatorInst(RI);
+}
+
+void Verifier::visitSwitchInst(SwitchInst &SI) {
+  // 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)
+    Assert1(SI.getCaseValue(i)->getType() == SwitchTy,
+            "Switch constants must all be same type as switch value!", &SI);
+
+  visitTerminatorInst(SI);
 }
 
 void Verifier::visitSelectInst(SelectInst &SI) {





More information about the llvm-commits mailing list