Bugzilla – Bug 340
Verifier misses malformed switch instruction
Last modified: 2004-05-21 11:49:55
You need to log in before you can comment on or make changes to this bug.
The bytecode reader seems to fail on the attached input. I suspect that it is a bug in the verifier, since the problem occurs from a switch statement that selects on a uint with each possible case typed as an int This was reported by Mark Hills: llvm-as file.ll opt file.bc -o null.bc opt: /home/vadve/criswell/llvm/include/Support/Casting.h:197: typename llvm::cast_retty<To, From>::ret_type llvm::cast(const Y&) [with X = llvm::Constant, Y = llvm::Value*]: Assertion `isa<X>(Val) && "cast<Ty>() argument of incompatible type!"' failed. opt[0x861e78a] opt[0x861e9aa] opt[0x42029188] opt(abort+0x16e)[0x4202a8c2] opt[0x42022ecb] opt(llvm::cast_retty<llvm::Constant, llvm::Value*>::ret_type llvm::cast<llvm::Constant, llvm::Value*>(llvm::Value* const&)+0x3b)[0x83bcbd7] opt(llvm::BytecodeParser::ParseInstruction(unsigned char const*&, unsigned char const*, std::vector<unsigned, std::allocator<unsigned> >&, llvm::BasicBlock*)+0x11f4)[0x83af6ec] opt(llvm::BytecodeParser::ParseInstructionList(llvm::Function*, unsigned char const*&, unsigned char const*)+0x2ca)[0x83b2ffc] opt(llvm::BytecodeParser::materializeFunction(llvm::Function*)+0x58a)[0x83b3ae6] opt(llvm::BytecodeParser::materializeModule()+0x5c)[0x83c2b76] opt(llvm::ModuleProvider::releaseModule()+0x18)[0x83c8238] opt(llvm::BytecodeParser::releaseModule()+0x11)[0x83c2b91] opt(llvm::ParseBytecodeFile(std::basic_string<char, std::char_traits<char>, std::allocator<char> > const&, std::basic_string<char, std::char_traits<char>, std::allocator<char> >*)+0x39)[0x83b7b8d] opt(main+0x6b)[0x83a5efb] opt(__libc_start_main+0x95)[0x42017589] opt(std::basic_ostream<char, std::char_traits<char> >& std::operator<< <std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char)+0x5d)[0x83a5de1] Abort (core dumped)
Created an attachment (id=118) [details] Code to reproduce the problem This is code from Mark that reproduces the problem.
Created an attachment (id=119) [details] Reduced test case This is a reduced test case. It is the same as the previous test case, but isolates the problem down into the switch statement that Mark suspected was the problem.
Interesting. Does the problem go away when you change the int constant to be a uint? This is probably a matter of having the verifier assert that the constatns have the same type as the switched value... i.e. that this is malformed LLVM code. -Chris
Yes, the bug goes away when the switch selector and labels are all uints.
Okay, then this is a verifier bug (for not catching it) and the input is malformed. I'll make patch for the verifier. -Chris
Fixed. Testcase here: test/Regression/Verifier/2004-05-21-SwitchConstantMismatch.ll Patch here: http://mail.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20040517/014436.html -Chris