<div dir="ltr">Hi David and Craig, <br><br>That turned out to be the issue exactly! I used a normal <font face="monospace">Metadata*</font> array as suggested and now the pass works as it does in the Debug version. Thanks for your quick responses! <br><br>Just for curiosity's sake, any ideas as to why this error would only appear in the Release+Asserts version of LLVM? <br><br>Best, <br>Shishir Jessu</div><img src="https://my-email-signature.link/signature.gif?u=452460&e=95036764&v=f28f27703adf4e8959cf91ce9fb923432b0bdbbf4b10715eb85bf2ae4706adb8" style="width:2px;max-height:0;overflow:hidden"><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 30, 2020 at 12:01 PM Craig Topper <<a href="mailto:craig.topper@gmail.com">craig.topper@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">I agree that the ArrayRef is likely the issue. I've debugged a crash caused by a temporary ArrayRef like that a couple times.<div><br></div><div>Either do what David suggested or use a normal array:</div><div><br></div><div>Metadata *mdArray[] = 

<span style="color:rgb(80,0,80);font-family:monospace">{ConstantInt::get(Int64Ty, 0), newMD};</span> <br><div><br clear="all"><div><div dir="ltr">~Craig</div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 30, 2020 at 9:56 AM David Blaikie via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, Apr 30, 2020 at 9:51 AM Shishir V Jessu via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">Hello, <br><br>I am editing the LowerTypeTests pass in LLVM, and part of my additions include the following 3 lines of code:<div><br></div><div><font face="monospace">// newTypeName is a std::string<br>MDString* newMD = MDString::get(M.getContext(), newTypeName);<br>ArrayRef<Metadata*> mdArray {ConstantInt::get(Int64Ty, 0), newMD};<br>auto* node = MDTuple::get(M.getContext(), mdArray);<br></font></div></div></blockquote><div><br>If I had to hazard a guess, it's that mdArray is left with dangling pointers to an array (initializer list) that ceases to exist once the ';' on line 2 is reached. So when the elements the ArrayRef references are accessed, it gets crashy.<br><br>I'd say try writing it like:<br><br>auto *node = MDTuple::get(M.getContext(), {ConstantInt::get(Int64Ty, 0), newMD});<br><br>Also try testing with ASan or MSan, perhaps?<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div><font face="monospace"></font><br>Thus far, I have been developing on a version of Clang with debugging symbols enabled, and this code has worked. However, on the Release+Asserts version, the third line results in a segmentation fault. The backtrace for the error, up to the method I'm working on, is as follows:<br><font face="monospace"><br>// signal handling...<br> #4 0x00005556e48d6120 llvm::ReplaceableMetadataImpl::getOrCreate(llvm::Metadata&) (/home/sjessu/build-no-debug/bin/clang-10+0x2787120)<br> #5 0x00005556e48db8c2 llvm::MetadataTracking::track(void*, llvm::Metadata&, llvm::PointerUnion<llvm::MetadataAsValue*, llvm::Metadata*>) (/home/sjessu/build-no-debug/bin/clang-10+0x278c8c2)<br> #6 0x00005556e48dbc12 llvm::MDNode::MDNode(llvm::LLVMContext&, unsigned int, llvm::Metadata::StorageType, llvm::ArrayRef<llvm::Metadata*>, llvm::ArrayRef<llvm::Metadata*>) (/home/sjessu/build-no-debug/bin/clang-10+0x278cc12)<br> #7 0x00005556e48dd70d llvm::MDTuple::getImpl(llvm::LLVMContext&, llvm::ArrayRef<llvm::Metadata*>, llvm::Metadata::StorageType, bool) (/home/sjessu/build-no-debug/bin/clang-10+0x278e70d)<br> #8 0x00005556e4a4b293 (anonymous namespace)::LowerTypeTestsModule::lower() (.part.1843) (/home/sjessu/build-no-debug/bin/clang-10+0x28fc293)<br></font><br><br>Crucially, <i>this error does not occur in the Debug version</i>, so I am lost as to how to diagnose it. I have checked that <font face="monospace">newMD </font><font face="arial, sans-serif">is non-null and contains the value I expect. Are there any discrepancies in the Debug version as compared to the Release + Asserts version that would cause such an error? Thanks for your help!<br></font><br>Best, <br>Shishir Jessu<br><br><br></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
</blockquote></div>
</blockquote></div>