[LLVMdev] Segmentation fault on using get parent of a PHINode

John McCall rjmccall at apple.com
Sun Feb 6 02:57:01 PST 2011


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.



More information about the llvm-dev mailing list