<html><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><blockquote type="cite" class="">On Jan 19, 2015, at 1:41 PM, Christian Schafmeister <<a href="mailto:chris.schaf@verizon.net" class="">chris.schaf@verizon.net</a>> wrote:<br class=""><br class="">Some more data.<br class=""><br class="">I upgraded to todays llvm/clang/clang-extra-tools  top-of-trunk and I upgraded my compiler to deal with all of the changes in llvm/clang since last September.<br class="">My current ToT llvm commit is 4b678bff4ebae28ec7e04ec936cf924ee8d289df<br class=""><br class="">I am still getting an assertion failure at exactly the same point, when I’m calling DIBuilder::finalize but the assertion has changed (but similar)- it is now:<br class="">Assertion failed: (isa<X>(Val) && "cast<Ty>() argument of incompatible type!"), function cast, file /Users/meister/Development/externals-clasp/llvm36/include/llvm/Support/Casting.h, line 237.<br class=""><br class="">Below is some info that may answer your (Duncan and Frederic) questions:<br class=""><br class="">1) Duncan asked “are you using two different `LLVMContext`s?”<br class="">Answer: I may be - in frame 6 the DbgNode->Context reference looks mangled<br class=""><br class="">2) Frederic asked “is TempEnumTypes null at this point”<br class="">Answer: No, it has the value 0x000000011c81fda8<br class=""><br class="">Below is an lldb session where I’m looking at the backtrace.<br class=""><br class="">(lldb) up<br class="">frame #4: 0x0000000103de1811 clasp_boehm_d`__assert_rtn(func=0x00000001043a5749, file=0x00000001043a574e, line=237, expr=0x00000001043a579f) + 129 at Signals.inc:533<br class="">   530 <span class="Apple-tab-span" style="white-space:pre">      </span>  else<br class="">   531 <span class="Apple-tab-span" style="white-space:pre">      </span>    fprintf(stderr, "Assertion failed: (%s), file %s, line %d.\n",<br class="">   532 <span class="Apple-tab-span" style="white-space:pre">   </span>            expr, file, line);<br class="">-> 533 <span class="Apple-tab-span" style="white-space:pre">    </span>  abort();<br class="">   534 <span class="Apple-tab-span" style="white-space:pre">  </span>}<br class="">   535 <span class="Apple-tab-span" style="white-space:pre">        </span><br class="">   536 <span class="Apple-tab-span" style="white-space:pre"> </span>void abort() {<br class="">(lldb) up<br class="">frame #5: 0x0000000103cf47dc clasp_boehm_d`llvm::cast_retty<llvm::MDNodeFwdDecl, llvm::MDNode*>::ret_type llvm::cast<llvm::MDNodeFwdDecl, llvm::MDNode>(Val=0x000000011c81fda8) + 108 at Casting.h:237<br class="">   234 <span class="Apple-tab-span" style="white-space:pre"> </span><br class="">   235 <span class="Apple-tab-span" style="white-space:pre"> </span>template <class X, class Y><br class="">   236 <span class="Apple-tab-span" style="white-space:pre">        </span>inline typename cast_retty<X, Y *>::ret_type cast(Y *Val) {<br class="">-> 237 <span class="Apple-tab-span" style="white-space:pre">       </span>  assert(isa<X>(Val) && "cast<Ty>() argument of incompatible type!");<br class="">   238 <span class="Apple-tab-span" style="white-space:pre"> </span>  return cast_convert_val<X, Y*,<br class="">   239 <span class="Apple-tab-span" style="white-space:pre"> </span>                          typename simplify_type<Y*>::SimpleType>::doit(Val);<br class="">   240 <span class="Apple-tab-span" style="white-space:pre">  </span>}<br class="">(lldb) up<br class="">frame #6: 0x0000000103b6bf6a clasp_boehm_d`llvm::DIDescriptor::replaceAllUsesWith(this=0x00007fff5fbdba18, D=0x0000000109d24380) + 218 at DebugInfo.cpp:349<br class="">   346 <span class="Apple-tab-span" style="white-space:pre">     </span>void DIDescriptor::replaceAllUsesWith(MDNode *D) {<br class="">   347 <span class="Apple-tab-span" style="white-space:pre">       </span>  assert(DbgNode && "Trying to replace an unverified type!");<br class="">   348 <span class="Apple-tab-span" style="white-space:pre">     </span>  assert(DbgNode != D && "This replacement should always happen");<br class="">-> 349 <span class="Apple-tab-span" style="white-space:pre">       </span>  auto *Node = cast<MDNodeFwdDecl>(const_cast<MDNode *>(DbgNode));<br class=""></blockquote><br class="">According to the backtrace, DbgNode here should be TempEnumTypes. In a correct flow, TempEnumTypes has been initialized by createCompileUnit() to a temporary node (a MDNodeFwdDecl nowadays). This cast should not be able to fail if you have called createCompileUnit() and of course if TempEnumTypes hasn’t been corrupted. Can you check that the value you have at that point is the same that was assigned by createCompileUnit()? If not, then you have your bug (another thought: would it be possible that finalize is called twice on the same CU?).<div class=""><br class=""></div><div class="">Fred <br class=""><br class=""><br class=""><blockquote type="cite" class="">   350 <span class="Apple-tab-span" style="white-space:pre">   </span>  Node->replaceAllUsesWith(D);<br class="">   351 <span class="Apple-tab-span" style="white-space:pre">   </span>  MDNode::deleteTemporary(Node);<br class="">   352 <span class="Apple-tab-span" style="white-space:pre">    </span>}<br class="">(lldb) up<br class="">frame #7: 0x0000000103b4ff19 clasp_boehm_d`llvm::DIBuilder::finalize(this=0x000000011c81feb0) + 185 at DIBuilder.cpp:74<br class="">   71  <span class="Apple-tab-span" style="white-space:pre"> </span><br class="">   72  <span class="Apple-tab-span" style="white-space:pre"> </span>void DIBuilder::finalize() {<br class="">   73  <span class="Apple-tab-span" style="white-space:pre">     </span>  DIArray Enums = getOrCreateArray(AllEnumTypes);<br class="">-> 74  <span class="Apple-tab-span" style="white-space:pre">  </span>  DIType(TempEnumTypes).replaceAllUsesWith(Enums);<br class="">   75  <span class="Apple-tab-span" style="white-space:pre">  </span><br class="">   76  <span class="Apple-tab-span" style="white-space:pre"> </span>  SmallVector<Metadata *, 16> RetainValues;<br class="">   77  <span class="Apple-tab-span" style="white-space:pre">   </span>  // Declarations and definitions of the same type may be retained. Some<br class="">(lldb) print TempEnumTypes<br class="">(llvm::MDNode *) $0 = 0x000000011c81fda8<br class="">;;;    Later on<br class="">(lldb) down<br class="">frame #6: 0x0000000103b6bf6a clasp_boehm_d`llvm::DIDescriptor::replaceAllUsesWith(this=0x00007fff5fbdba18, D=0x0000000109d24380) + 218 at DebugInfo.cpp:349<br class="">   346 <span class="Apple-tab-span" style="white-space:pre">     </span>void DIDescriptor::replaceAllUsesWith(MDNode *D) {<br class="">   347 <span class="Apple-tab-span" style="white-space:pre">       </span>  assert(DbgNode && "Trying to replace an unverified type!");<br class="">   348 <span class="Apple-tab-span" style="white-space:pre">     </span>  assert(DbgNode != D && "This replacement should always happen");<br class="">-> 349 <span class="Apple-tab-span" style="white-space:pre">       </span>  auto *Node = cast<MDNodeFwdDecl>(const_cast<MDNode *>(DbgNode));<br class="">   350 <span class="Apple-tab-span" style="white-space:pre">      </span>  Node->replaceAllUsesWith(D);<br class="">   351 <span class="Apple-tab-span" style="white-space:pre">   </span>  MDNode::deleteTemporary(Node);<br class="">   352 <span class="Apple-tab-span" style="white-space:pre">    </span>}<br class="">(lldb) print DbgNode<br class="">(const llvm::MDNode *) $1 = 0x000000011c81fda8<br class="">(lldb) call DbgNode->dump()<br class="">!{error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=EXC_I386_GPFLT).<br class="">The process has been returned to the state before expression evaluation.<br class="">(lldb) frame variable<br class="">(llvm::DIDescriptor *) this = 0x00007fff5fbdba18<br class="">(llvm::MDNode *) D = 0x0000000109d24380<br class="">(llvm::MDNodeFwdDecl *) Node = 0x0000000102f55985<br class="">(lldb) call D->dump()<br class="">!{}<br class=""><br class="">(lldb) call DbgNode<br class="">(const llvm::MDNode *) $2 = 0x000000011c81fda8<br class="">(lldb) print *DbgNode<br class="">(const llvm::MDNode) $3 = {<br class="">  llvm::Metadata = {<br class="">    SubclassID = '\0'<br class="">    IsDistinctInContext = false<br class="">    SubclassData16 = 0<br class="">    SubclassData32 = 2415919104<br class="">  }<br class="">  Context = 0x0000000109e00009<br class="">  NumOperands = 1<br class="">  MDNodeSubclassData = 0<br class="">}<br class="">(lldb) print *D<br class="">(llvm::MDNode) $4 = {<br class="">  llvm::Metadata = {<br class="">    SubclassID = '\0'<br class="">    IsDistinctInContext = false<br class="">    SubclassData16 = 0<br class="">    SubclassData32 = 0<br class="">  }<br class="">  Context = 0x0000000109e02430<br class="">  NumOperands = 0<br class="">  MDNodeSubclassData = 3267742850<br class="">}<br class="">(lldb) print D->Context<br class="">(llvm::LLVMContext) $5 = {<br class="">  pImpl = 0x000000010b003000<br class="">}<br class="">(lldb) print DbgNode->Context<br class="">(llvm::LLVMContext) $6 = {<br class="">  pImpl = 0xd00000000109d003<br class="">}<br class="">(lldb) <br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class=""><br class="">On Jan 19, 2015, at 3:49 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" class="">dexonsmith@apple.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="">On 2015-Jan-19, at 12:38, Frédéric Riss <friss@apple.com> wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On Jan 19, 2015, at 12:04 PM, Christian Schafmeister <chris.schaf@verizon.net> wrote:<br class=""><br class=""><br class="">I forgot to mention this in my initial email.<br class=""><br class="">The build of LLVM that I was using was commit a0d5d7aed8e177cea381b3d054d80c212ece9f2c<br class="">The date on the commit is: Date:   Fri Sep 26 12:34:06 2014<br class=""><br class="">Also:<br class="">Today I grabbed the ToT llvm/clang/clang-extra-tools  and I’m working on getting my code to be compatible with it.<br class=""><br class="">I can switch back and forth between the current ToT llvm and the old one.<br class=""></blockquote><br class="">Hmmm, I didn’t look closely enough and I thought you were hitting an assertions I added a few weeks after that commit in the Metadata RAUW method. But it is the equivalent assertion in Value::RAUW that you are hitting and that has been there forever. Looking at your exact revision, the assertion seems to trigger while executing:<br class=""><br class="">DIType(TempEnumTypes).replaceAllUsesWith(Enums);<br class=""><br class="">in DIBuilder::finalize(). Can you check if TempEnumTypes is null at this point? If that is the issue (which I’m not sure), then you need to call DIBuilder::createCompileUnit() at some point.<br class=""><br class="">Fred<br class=""></blockquote><br class="">I had a thought, too: are you using two different `LLVMContext`s?  That<br class="">would cause the `metadata` type to compare unequal.<br class=""></blockquote><br class=""></blockquote><br class=""></div></body></html>