diff options
author | Chris Lattner <sabre@nondot.org> | 2004-05-21 16:47:21 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2004-05-21 16:47:21 +0000 |
commit | ab5aa144030de814e482037769deb93862982d08 (patch) | |
tree | 052d0367e464949fe1e605440bb5b48560977467 /llvm/lib | |
parent | 6041fee872fd8c2aa065245385863a89edb52f4b (diff) | |
download | bcm5719-llvm-ab5aa144030de814e482037769deb93862982d08.tar.gz bcm5719-llvm-ab5aa144030de814e482037769deb93862982d08.zip |
Fix for PR340: Verifier misses malformed switch instruction
llvm-svn: 13618
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/VMCore/Verifier.cpp | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/llvm/lib/VMCore/Verifier.cpp b/llvm/lib/VMCore/Verifier.cpp index dfd13c9256f..b69511bc246 100644 --- a/llvm/lib/VMCore/Verifier.cpp +++ b/llvm/lib/VMCore/Verifier.cpp @@ -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); |