[LLVMdev] Segfault in ilist_node::getPrevNode for nodes with certain custom traits

Nico Rieck nico.rieck at gmail.com
Tue Jan 14 08:35:19 PST 2014

Is ilist_node::getPrevNode() supposed to work for node types with custom
traits that embed the sentinel? Examples: Instruction, MachineInstr,
BasicBlock, …

Calling getPrevNode on the first node in a such a list segfaults because
"Prev" is 0:

  NodeTy *getPrevNode() {
    NodeTy *Prev = this->getPrev();

    // Check for sentinel.
    if (!Prev->getNext())
      return 0;

    return Prev;

None of the ilist unit tests pass/run when done with similar traits.
They either segfault or run into the sentinel.

Prev could be initialized to the Sentinel in the traits constructor,
which avoids the segfault. But the sentinel check still won't work since
the sentinel is only an ilist_half_node, and its Next value and the list
head have the same memory address.


More information about the llvm-dev mailing list