Surinder
2011-Jan-31 08:29 UTC
[LLVMdev] Segmentation fault on using get parent of a PHINode
I am getting a segmentation fault as soon as I touch the Basic block *b value defined as : std::string getPHIAssigns(const PHINode *PH) { const BasicBlock *b = PH->getParent(); errs() << b->size(); where as getPHIAssigns is being called from for (BasicBlock::iterator ins=b->begin(), e3=b->end(); ins!=e3; ++ins, ++l) // get instructions { if (const PHINode *PH = dyn_cast<PHINode>(&ins)) // Phi ers() << getPHIAssigns(PH); Can you see what is wrong here? The dump is : 0 opt 0x0000000000bc9cfa 1 opt 0x0000000000bca288 2 libpthread.so.0 0x00000037ef20e540 3 opt 0x0000000000910849 llvm::iplist<llvm::Instruction, llvm::ilist_traits<llvm::Instruction> >::size() const + 17 4 opt 0x00000000009108a5 llvm::BasicBlock::size() const + 25 5 dfl.so 0x00002aaaaaaf101d 6 dfl.so 0x00002aaaaaaf2965 7 dfl.so 0x00002aaaaaaf308a 8 opt 0x0000000000b467fa llvm::FPPassManager::runOnFunction(llvm::Function&) + 348 9 opt 0x0000000000b469cf llvm::FPPassManager::runOnModule(llvm::Module&) + 81 10 opt 0x0000000000b464bd llvm::MPPassManager::runOnModule(llvm::Module&) + 381 11 opt 0x0000000000b478f7 llvm::PassManagerImpl::run(llvm::Module&) + 111 12 opt 0x0000000000b47959 llvm::PassManager::run(llvm::Module&) + 33 13 opt 0x00000000007a14a6 main + 3438 14 libc.so.6 0x00000037ee61e074 __libc_start_main + 244 15 opt 0x00000000007929a9 Stack dump: 0. Program arguments: opt -load /u1/suri/llvm-local/build/x86-64/Debug/llvm/Debug/lib/dfl.so -dfl /u1/suri/suri/testing/cfgs/test99foo.c.bc 1. Running pass 'Function Pass Manager' on module '/u1/suri/suri/testing/cfgs/test99foo.c.bc'. 2. Running pass 'emit cfg in dfl format' on function '@main' Surinder>
Duncan Sands
2011-Feb-05 18:09 UTC
[LLVMdev] Segmentation fault on using get parent of a PHINode
Hi Surinder, I don't see anything obviously wrong with your code. I suggest that (1) you build LLVM with assertions enabled, (2) you run the verifier on your bitcode, and (3) run your program under valgrind. Ciao, Duncan.> I am getting a segmentation fault as soon as I touch the Basic block > *b value defined as : > > std::string getPHIAssigns(const PHINode *PH) > { const BasicBlock *b = PH->getParent(); > errs()<< b->size(); > > > where as getPHIAssigns is being called from > > for (BasicBlock::iterator ins=b->begin(), e3=b->end(); > ins!=e3; ++ins, ++l) // get instructions > { if (const PHINode *PH = dyn_cast<PHINode>(&ins)) // Phi > ers()<< getPHIAssigns(PH); > > Can you see what is wrong here? > > The dump is : > > 0 opt 0x0000000000bc9cfa > 1 opt 0x0000000000bca288 > 2 libpthread.so.0 0x00000037ef20e540 > 3 opt 0x0000000000910849 llvm::iplist<llvm::Instruction, > llvm::ilist_traits<llvm::Instruction> >::size() const + 17 > 4 opt 0x00000000009108a5 llvm::BasicBlock::size() const + 25 > 5 dfl.so 0x00002aaaaaaf101d > 6 dfl.so 0x00002aaaaaaf2965 > 7 dfl.so 0x00002aaaaaaf308a > 8 opt 0x0000000000b467fa > llvm::FPPassManager::runOnFunction(llvm::Function&) + 348 > 9 opt 0x0000000000b469cf > llvm::FPPassManager::runOnModule(llvm::Module&) + 81 > 10 opt 0x0000000000b464bd > llvm::MPPassManager::runOnModule(llvm::Module&) + 381 > 11 opt 0x0000000000b478f7 > llvm::PassManagerImpl::run(llvm::Module&) + 111 > 12 opt 0x0000000000b47959 llvm::PassManager::run(llvm::Module&) + 33 > 13 opt 0x00000000007a14a6 main + 3438 > 14 libc.so.6 0x00000037ee61e074 __libc_start_main + 244 > 15 opt 0x00000000007929a9 > Stack dump: > 0. Program arguments: opt -load > /u1/suri/llvm-local/build/x86-64/Debug/llvm/Debug/lib/dfl.so -dfl > /u1/suri/suri/testing/cfgs/test99foo.c.bc > 1. Running pass 'Function Pass Manager' on module > '/u1/suri/suri/testing/cfgs/test99foo.c.bc'. > 2. Running pass 'emit cfg in dfl format' on function '@main' > > Surinder >> > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
John McCall
2011-Feb-06 10:57 UTC
[LLVMdev] Segmentation fault on using get parent of a PHINode
On Feb 5, 2011, at 10:09 AM, Duncan Sands wrote:> Hi Surinder, I don't see anything obviously wrong with your code. I suggest > that (1) you build LLVM with assertions enabled, (2) you run the verifier on > your bitcode, and (3) run your program under valgrind.I think there might be something unsound in our current dyn_cast implementation; that is, I'm pretty sure it type-checks for things it's not supposed to type-check for. In this example, &ins has type llvm::ilist_iterator<Instruction>*, because the iterator type (like most iterator types) does not overload operator&. This should really not compile, and yet it does. Anyway, the immediate fix is to use the iterator correctly:>> for (BasicBlock::iterator ins=b->begin(), e3=b->end(); >> ins!=e3; ++ins, ++l) // get instructions >> { if (const PHINode *PH = dyn_cast<PHINode>(&ins)) // Phi >> ers()<< getPHIAssigns(PH);This should be dyn_cast<PHINode>(*ins). John.