[LLVMbugs] [Bug 1758] New: opt -verify-each doesn' t catch invalid bitcode generated by a pass

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Oct 30 12:39:19 PDT 2007


http://llvm.org/bugs/show_bug.cgi?id=1758

           Summary: opt -verify-each doesn't catch invalid bitcode generated
                    by a pass
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: unassignedbugs at nondot.org
        ReportedBy: edwintorok at gmail.com
                CC: llvmbugs at cs.uiuc.edu


Created an attachment (id=1176)
 --> (http://llvm.org/bugs/attachment.cgi?id=1176)
the invalid bitcode generated

While learning how to write a FunctionPass/ModulePass I made the stupid mistake
of inserting instructions after a 'ret' instruction in a BasicBlock.
Needless to say, it generated invalid bitcode, however opt -verify-each didn't
catch the problem, and the next optimizer pass crashed.

However if I try to run llvm-dis on the invalid bitcode,  it *does* say it is
invalid. I think opt -verify-each behaviour should be consistent with
llvm-dis's way of loading bitcode.

Here it is the invalid bitcode generated (of course this won't even assemble
with llvm-as, however LLVMBuilder happily creates it):

define i32 @test1() {
entry:
        %retval = alloca i32, align 4           ; <i32*> [#uses=1]
        %"alloca point" = bitcast i32 0 to i32          ; <i32> [#uses=0]
        store i32 5, i32* @o, align 4
        br label %return

return:         ; preds = %entry
        %retval1 = load i32* %retval            ; <i32> [#uses=1]
        ret i32 %retval1
        malloc i32              ; <i32*>:0 [#uses=0]
}

opt: /home/edwin/llvm-svn/llvm/include/llvm/Support/CFG.h:98:
llvm::SuccIterator<Term, BB>::SuccIterator(Term_) [with Term_ =
llvm::TerminatorInst*, BB_ = llvm::BasicBlock]: Assertion `T && "getTerminator
returned null!"' failed.
opt[0x9bfcae]
opt[0x9bff1a]
/lib/libc.so.6[0x32d1c31710]
/lib/libc.so.6(gsignal+0x35)[0x32d1c316a5]
/lib/libc.so.6(abort+0x110)[0x32d1c33100]
/lib/libc.so.6(__assert_fail+0xef)[0x32d1c2ac2f]
opt(llvm::SuccIterator<llvm::TerminatorInst*,
llvm::BasicBlock>::SuccIterator(llvm::TerminatorInst*)+0x4f)[0x6b927d]
opt(llvm::succ_begin(llvm::BasicBlock*)+0x21)[0x6bc575]
opt(llvm::GraphTraits<llvm::BasicBlock*>::child_begin(llvm::BasicBlock*)+0x15)[0x6bc5a3]
opt(unsigned int llvm::DFSPass<llvm::GraphTraits<llvm::BasicBlock*>
>(llvm::DominatorTreeBase<llvm::GraphTraits<llvm::BasicBlock*>::NodeType>&,
llvm::GraphTraits<llvm::BasicBlock*>::NodeType*, unsigned int)+0x241)[0x8a0357]
opt(void llvm::Calculate<llvm::Function,
llvm::BasicBlock*>(llvm::DominatorTreeBase<llvm::GraphTraits<llvm::BasicBlock*>::NodeType>&,
llvm::Function&)+0x64)[0x8a13da]
opt(void
llvm::DominatorTreeBase<llvm::BasicBlock>::recalculate<llvm::Function>(llvm::Function&)+0xba)[0x8a208a]
opt(llvm::DominatorTree::runOnFunction(llvm::Function&)+0x21)[0x91e6cf]
opt(llvm::FPPassManager::runOnFunction(llvm::Function&)+0x10e)[0x952876]
opt(llvm::FPPassManager::runOnModule(llvm::Module&)+0x52)[0x9529e4]
opt(llvm::MPPassManager::runOnModule(llvm::Module&)+0xec)[0x952570]
opt(llvm::PassManagerImpl::run(llvm::Module&)+0x74)[0x952700]
opt(llvm::PassManager::run(llvm::Module&)+0x20)[0x952762]
opt(main+0x986)[0x6bee48]
/lib/libc.so.6(__libc_start_main+0xf4)[0x32d1c1db44]
opt(cos+0x121)[0x6b05d9]
Aborted


The buggy part of the pass that generates this invalid bitcode is:
        UnifyFunctionExitNodes &unifyExitNode =
getAnalysis<UnifyFunctionExitNodes>();
        LLVMBuilder builder;
        BasicBlock* End = unifyExitNode.getReturnBlock();
        builder.SetInsertPoint(End);
        builder.CreateMalloc(Type::Int32Ty);


It should be 'builder.SetInsertPoint(End, End->begin());' of course.
But my point is that the bitcode validator in opt should catch this error.

Attached invalid bitcode file, and buggy pass.


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.



More information about the llvm-bugs mailing list