Strange exception in SelectionDAGBuilder

I’m working on the code to handle GC tracing of “intermediate values” (as described in the GC doc), and I’ve run into a weird problem. (Note, this has nothing to do with the patch I have proposed, this error occurs with regular old pointer-allocas.)

The exception I am getting occurs in this code here in SelectionDAGBuilder.cpp:

case Intrinsic::gcroot:

    **if** (GFI) {
      **const** Value *Alloca = I.getArgOperand(0);
      **const** Constant *TypeMap = cast<Constant>(I.getArgOperand(1));

<b>      FrameIndexSDNode *FI = cast<FrameIndexSDNode>(getValue(Alloca).getNode());
</b>      GFI->addStackRoot(FI->getIndex(), TypeMap);
    }
    **return** 0;

Specifically, the cast from SDNode to FrameIndexSDNode fails because the node type is DYNAMIC_STACKALLOC, while this code is expecting the node type to be “FrameIndex” or “TargetFrameIndex”. (I don’t know what either of these mean, I’m just telling you what the debugger is telling me.)

Here’s what the IR looks like:

%gc_root = alloca %tart.collections.KeyError*, align 8, !dbg !55084
store %tart.collections.KeyError* %7, %tart.collections.KeyError** %gc_root, align 8, !dbg !55084
%9 = bitcast %tart.collections.KeyError** %gc_root to i8**, !dbg !55084
call void @llvm.gcroot(i8** %9, i8* null), !dbg !55084

As you can see, it’s just creating an alloca of a pointer, bitcasting it to i8**, and passing it to llvm.gcroot, just like it does in a hundred other places. But in this place, for some reason, the SelectionDAGBuilder isn’t working.

I just sync’d to the most recent LLVM head and I still get the error.

Hi Talin,

I think that the framework for GC assumes llvm.gcroot to be in the first block. If it is not the case in your example, it will break these assumptions.

Nicolas

Hi Talin,

I think that the framework for GC assumes llvm.gcroot to be in the first block. If it is not the case in your example, it will break these assumptions.

Ah, that would explain it. Thanks.