Fix for PR340: Verifier misses malformed switch instruction
authorChris Lattner <sabre@nondot.org>
Fri, 21 May 2004 16:47:21 +0000 (16:47 +0000)
committerChris Lattner <sabre@nondot.org>
Fri, 21 May 2004 16:47:21 +0000 (16:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@13618 91177308-0d34-0410-b5e6-96231b3b80d8

lib/VMCore/Verifier.cpp

index dfd13c9256f91513eafd86b7090d045bbc19261b..b69511bc246cc0da94a78966c1ec5224c7837ded 100644 (file)
@@ -173,6 +173,7 @@ namespace {  // Anonymous namespace for class
     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); }
@@ -362,6 +363,17 @@ void Verifier::visitReturnInst(ReturnInst &RI) {
   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) {
   Assert1(SI.getCondition()->getType() == Type::BoolTy,
           "Select condition type must be bool!", &SI);