I'm trying to track down the problem with the assertion failure in SelectionDAGBuilder.cpp. This is the code:<div><span style="font-family:monospace;font-size:medium;white-space:pre-wrap"><pre>  <b><font color="#A020F0">case</font></b> <b><font color="#5F9EA0">Intrinsic</font></b>::gcroot:
    <b><font color="#A020F0">if</font></b> (GFI) {
      <b><font color="#228B22">const</font></b> Value *Alloca = I.getArgOperand(0);
      <b><font color="#228B22">const</font></b> Constant *TypeMap = cast<Constant>(I.getArgOperand(1));

<b>      FrameIndexSDNode *FI = cast<FrameIndexSDNode>(getValue(Alloca).getNode());
</b>      GFI->addStackRoot(FI->getIndex(), TypeMap);
    }
    <b><font color="#A020F0">return</font></b> 0</pre></span>The cast<FrameIndexSDNode> is what's failing. Apparently the node isn't a FrameIndexSDNode.</div><div><br></div><div>Now, we discussed a similar problem on this list earlier, and it was stated that the cause was due to calls to llvm.gcroot() not being in the first block. However, that's not the case this time - here's the function being processed (according to I.Parent.Parent->dump()):</div>


<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font face="'courier new', monospace"><span style="font-size:x-small">define internal %tart.core.Object* @"tart.core.Object.coerce[int32](int32)->tart.core.Object"(i32 %value) gc "tart-gc" {</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">prologue:</span></font></div></div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  call void @llvm.dbg.declare(metadata !{i32 %value}, metadata !48487)</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  %gc_root = alloca %"tart.core.ValueRef[char]"*, !dbg !48488</span></font></div>
</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  store %"tart.core.ValueRef[char]"* null, %"tart.core.ValueRef[char]"** %gc_root</span></font></div>
</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  %0 = bitcast %"tart.core.ValueRef[char]"** %gc_root to i8**, !dbg !48488</span></font></div>
</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  call void @llvm.gcroot(i8** %0, i8* null), !dbg !48488</span></font></div>
</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  br label %entry, !dbg !48488</span></font></div></div><div><div><font face="'courier new', monospace"><span style="font-size:x-small"><br>


</span></font></div></div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">entry:                                            ; preds = %prologue</span></font></div>
</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  %ValueRef_new = call %"tart.core.ValueRef[char]"* @"tart.core.ValueRef[int32].type.alloc"(), !dbg !48488</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  store %"tart.core.ValueRef[char]"* %ValueRef_new, %"tart.core.ValueRef[char]"** %gc_root, !dbg !48488</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  %construct = call %tart.core.Hashable @"tart.core.ValueRef[int32].construct(int32)"(%"tart.core.ValueRef[char]"* %ValueRef_new, i32 %value), !dbg !48488</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  store %"tart.core.ValueRef[char]"* null, %"tart.core.ValueRef[char]"** %gc_root, !dbg !48488</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  %upcast = getelementptr inbounds %"tart.core.ValueRef[char]"* %ValueRef_new, i32 0, i32 0, i32 0, !dbg !48488</span></font></div>


</div><div><div><font face="'courier new', monospace"><span style="font-size:x-small">  ret %tart.core.Object* %upcast, !dbg !48488</span></font></div></div><div>
<div><font face="'courier new', monospace"><span style="font-size:x-small">}</span></font></div></div></blockquote><div><br></div><div>As you can see, the only call to llvm.gcroot() is in fact in the first block.</div>


<div><br></div><div>Now, here's the weird part: If I turn on optimization, the assertion failure no longer happens. What's the difference? Here's what the function looks like (I.Parent.Parent->dump()) with -O2:</div>


<div><br></div><blockquote style="margin:0 0 0 40px;border:none;padding:0px"><div><div><font class="Apple-style-span" face="'courier new', monospace"><span class="Apple-style-span" style="font-size: x-small;"><div>

define internal %7* @"tart.reflect.Type[].iterate->tart.core.Iterator[tart.reflect.Type]"(%"tart.reflect.Type[]"* %self) nounwind gc "tart-gc" {</div><div>prologue:</div><div>  %gc_root = alloca i8*, align 8</div>

<div>  store i8* null, i8** %gc_root</div><div>  call void @llvm.gcroot(i8** %gc_root, i8* null), !dbg !48487</div><div>  %new.i = call i8* @malloc(i64 32) nounwind, !dbg !48488</div><div>  %0 = bitcast i8* %new.i to %tart.core.TypeInfoBlock**</div>

<div>  store %tart.core.TypeInfoBlock* bitcast (%25* @"tart.reflect.Type[].ArrayIterator.type.tib" to %tart.core.TypeInfoBlock*), %tart.core.TypeInfoBlock** %0, align 8, !dbg !48488</div><div>  tail call void @llvm.dbg.declare(metadata !{null}, metadata !48489)</div>

<div>  %1 = getelementptr inbounds i8* %new.i, i64 16</div><div>  %2 = bitcast i8* %1 to %"tart.reflect.Type[]"**</div><div>  store %"tart.reflect.Type[]"* %self, %"tart.reflect.Type[]"** %2, align 8, !dbg !48490</div>

<div>  %3 = getelementptr inbounds i8* %new.i, i64 24</div><div>  %4 = bitcast i8* %3 to i64*</div><div>  store i64 0, i64* %4, align 8, !dbg !48491</div><div>  %intf_ptr = bitcast i8* %new.i to %7*</div><div>  ret %7* %intf_ptr, !dbg !48487</div>

<div>}</div><div><br></div></span></font></div></div></blockquote><div>OK, I'm looking at the crash in the debugger, and it looks like the NodeType (getValue(Alloca).getNode().getOpcode()) is value 41. According to what the debugger is telling me, that value corresponse to llvm::ISD::CopyFromReg.</div>

<div><br></div><div>When I debug the optimized version, the node value is 13 (llvm::ISD::FrameIndex) which seems right.</div><div><br></div><div>Does any of that make any sense?</div><meta http-equiv="content-type" content="text/html; charset=utf-8"><div>

<br></div>
<div>-- <br>-- Talin<br>
</div>