[LLVMdev] GlobalValues appear in their own use lists?

Sean Callanan
Mon, 10 Mar 2014 18:59:30 -0000

In the following IR module:
–
define i8 @foo() #0 {
entry:
  %call0 = call i8 @bar()
  ret i8 %call0
}

declare i8 @bar() #1
–
@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):
–
Index: lib/IR/Verifier.cpp
==================================================================---
lib/IR/Verifier.cpp	(revision 203468)
+++ lib/IR/Verifier.cpp	(working copy)
@@ -360,6 +360,11 @@
           "Global is external, but doesn't have external or weak
linkage!",
           &GV);

+  for (Value::const_use_iterator UI = GV.use_begin(), UE = GV.use_end();
+       UI != UE; ++UI) {
+    Assert1(*UI != &GV, "Global values cannot be their own
uses!", &GV);
+  }
+
   Assert1(!GV.hasAppendingLinkage() || isa<GlobalVariable>(GV),
           "Only global variables can have appending linkage!",
&GV);
–
Is it ever reasonable for a global value to be its own use?  If not, can I
commit this patch?

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.

Sean

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20140310/bf33267f/attachment.html>