<html><head><meta http-equiv="Content-Type" content="text/html charset=windows-1252"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br><div><div>On Mar 10, 2014, at 11:59 AM, Sean Callanan <<a href="mailto:scallanan@apple.com">scallanan@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><meta http-equiv="Content-Type" content="text/html charset=windows-1252"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;">In the following IR module:<div>–</div><div><div><font face="Menlo">define i8 @foo() #0 {</font></div><div><font face="Menlo">entry:</font></div><div><font face="Menlo">  %call0 = call i8 @bar()</font></div><div><font face="Menlo">  ret i8 %call0</font></div><div><font face="Menlo">}</font></div><div><font face="Menlo"><br></font></div><div><font face="Menlo">declare i8 @bar() #1</font></div><div>–</div><div>@bar() gets marked as its own user in top-of-tree LLVM.  I patched the Verifier to check it (but didn’t commit the patch):</div><div>–</div><div><font face="Menlo">Index: lib/IR/Verifier.cpp</font><br><font face="Menlo">===================================================================</font><br><font face="Menlo">--- lib/IR/Verifier.cpp</font><span class="Apple-tab-span" style="font-family: Menlo; white-space: pre;">  </span><font face="Menlo">(revision 203468)</font><br><font face="Menlo">+++ lib/IR/Verifier.cpp</font><span class="Apple-tab-span" style="font-family: Menlo; white-space: pre;">    </span><font face="Menlo">(working copy)</font><br><font face="Menlo">@@ -360,6 +360,11 @@</font><br><font face="Menlo">           "Global is external, but doesn't have external or weak linkage!",</font><br><font face="Menlo">           &GV);</font><br><font face="Menlo"> </font><br><font face="Menlo">+  for (Value::const_use_iterator UI = GV.use_begin(), UE = GV.use_end();</font><br><font face="Menlo">+       UI != UE; ++UI) {</font><br><font face="Menlo">+    Assert1(*UI != &GV, "Global values cannot be their own uses!", &GV);</font><br><font face="Menlo">+  }</font><br><font face="Menlo">+</font><br><font face="Menlo">   Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),</font><br><font face="Menlo">           "Only global variables can have appending linkage!", &GV);</font><br>–</div><div>Is it ever reasonable for a global value to be its own use?</div></div></div></blockquote><div><br></div><div>No, this is never possible.  The only globals that have uses are GlobalVariables and Aliases, and both of them require that the operand have a different type than the global itself (one level of pointer is removed).  Since LLVM 2.0, it isn’t possible to have a "pointer to itself” type anymore.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div><div>  If not, can I commit this patch?</div></div></div></blockquote><div><br></div><div>Sure, but note that it won’t apply to mainline.  use iterators got reworked to be C++’11ified and got renamed in the process.</div><br><blockquote type="cite"><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div>This really causes problems for LLDB in various parts of our logic, including infinite loops when following use chains, but a major issue is that we try to strip certain global values out of the module, and if they’re their own uses then that doesn’t work because we can never eliminate the last use.</div></div></blockquote><br></div><div>Are you sure that they are direct uses like this?  If *is* possible to have global variables that use themselves through constant expressions.  A C example would be something like:</div><div><br></div><div>extern void *G;<br>void *G = &G;<br><br></div><div>which compiles to:</div><div><br></div><div><div style="margin: 0px; font-size: 10px; font-family: Monaco;">@G = global i8* bitcast (i8** @G to i8*), align 8</div><div><br></div><div>-Chris</div></div></body></html>