Alexandru Ionut Diaconescu
2012-Dec-20 10:42 UTC
[LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
Hello John, I was following your procedures and I isolated the problem. The problem are represented by the basic blocks with only one element. for (Function::iterator II = F.begin(), EE = F.end(); II != EE; ++II, ++ii) { BasicBlock* BB=II; if (BB->getTerminator()) { Instruction* current = BB->getTerminator(); Instruction* previous; errs()<<"AAA\n"; if(*current->getPrevNode()*) { errs()<<"BBB\n"; previous = current->getPrevNode(); ok=1; } if (ok){ errs()<<"CCC\n"; ........ It does print AAA, but then I have the segfault. So when I am evaluating the *current->getPrevNode() *condition, I got the segfault. Do you know how can I solve this? Thank you Alex -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121220/feea7b5a/attachment.html>
Stephen McGruer
2012-Dec-20 11:06 UTC
[LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
I may be mistaken as I just took a quick look, but in ilist_node the function "getPrevNode()" actually calls a method on the previous node: NodeTy *getPrevNode() { NodeTy *Prev = this->getPrev(); // Check for sentinel. if (!Prev->getNext()) return 0; return Prev; } http://llvm.org/docs/doxygen/html/ilist__node_8h_source.html#l00058 Try checking if current->getPrev() is null before calling current->getPrevNode(). Stephen On 20 December 2012 10:42, Alexandru Ionut Diaconescu < alexandruionutdiaconescu at gmail.com> wrote:> Hello John, > > I was following your procedures and I isolated the problem. The problem > are represented by the basic blocks with only one element. > > > for (Function::iterator II = F.begin(), EE = F.end(); II != EE; ++II, > ++ii) > { > BasicBlock* BB=II; > > > if (BB->getTerminator()) > { > Instruction* current = BB->getTerminator(); > > Instruction* previous; > > errs()<<"AAA\n"; > if(*current->getPrevNode()*) > { > errs()<<"BBB\n"; > previous = current->getPrevNode(); > ok=1; > } > > if (ok){ > errs()<<"CCC\n"; > ........ > > > It does print AAA, but then I have the segfault. So when I am evaluating > the *current->getPrevNode() *condition, I got the segfault. > Do you know how can I solve this? > > Thank you > Alex > > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev > >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121220/a2ce2291/attachment.html>
Óscar Fuentes
2012-Dec-20 11:10 UTC
[LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
Alexandru Ionut Diaconescu <alexandruionutdiaconescu at gmail.com> writes:> I was following your procedures and I isolated the problem. The problem are > represented by the basic blocks with only one element. > > > for (Function::iterator II = F.begin(), EE = F.end(); II != EE; ++II, ++ii) > { > BasicBlock* BB=II; > > > if (BB->getTerminator()) > { > Instruction* current = BB->getTerminator(); > > Instruction* previous; > > errs()<<"AAA\n"; > if(*current->getPrevNode()*) > { > errs()<<"BBB\n"; > previous = current->getPrevNode(); > ok=1; > } > > if (ok){ > errs()<<"CCC\n"; > ........ > > > It does print AAA, but then I have the segfault. So when I am evaluating > the *current->getPrevNode() *condition, I got the segfault. > Do you know how can I solve this?The documentation for BasickBlock::getTerminator says: /// getTerminator() - If this is a well formed basic block, then this returns /// a pointer to the terminator instruction. If it is not, then you get a /// null pointer back. Maybe BB is not well formed (it doesn't have proper terminator) and BB->getTerminator returns NULL ?
Alexandru Ionut Diaconescu
2012-Dec-20 11:42 UTC
[LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
Hello, Thank you for your answer. If I want to use then I have error: ‘NodeTy* llvm::ilist_half_node<NodeTy>::getPrev() [with NodeTy llvm::Instruction]’ is protected error: ‘llvm::ilist_half_node<llvm::Instruction>’ is not an accessible base of ‘llvm::Instruction’ Do you know any other method to access the previous instruction of a terminator instruction? PS: back() is not an option. On Thu, Dec 20, 2012 at 12:06 PM, Stephen McGruer <stephen.mcgruer at gmail.com> wrote:> current->getPrev()-- Best regards, Alexandru Ionut Diaconescu -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20121220/c610d364/attachment.html>
Apparently Analagous Threads
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*
- [LLVMdev] LLVM segmentation fault / need use Instruction instead of Instruction*