Chris, this is a patch against top-of-tree. Maybe I wrote something wrong in the patch? $ svn info … Last Changed Author: chapuni Last Changed Rev: 203523 Last Changed Date: 2014-03-10 17:34:38 -0700 (Mon, 10 Mar 2014) $ svn diff Index: lib/IR/Verifier.cpp ==================================================================--- lib/IR/Verifier.cpp (revision 203523) +++ 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); $ cat whatever.ll define i8 @foo() #0 { entry: %call0 = call i8 @bar() ret i8 %call0 } declare i8 @bar() #1 $ /Volumes/Excelion/lldb/llvm-build/Debug+Asserts/x86_64/Debug+Asserts/bin/llc whatever.ll Global values cannot be their own uses! i8 ()* @bar LLVM ERROR: Broken module found, compilation aborted! Sean On Mar 10, 2014, at 3:36 PM, Chris Lattner <clattner at apple.com> wrote:> > On Mar 10, 2014, at 11:59 AM, Sean Callanan <scallanan at apple.com> wrote: > >> 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? > > 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. > >> If not, can I commit this patch? > > Sure, but note that it won’t apply to mainline. use iterators got reworked to be C++’11ified and got renamed in the process. > >> 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. > > 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: > > extern void *G; > void *G = &G; > > which compiles to: > > @G = global i8* bitcast (i8** @G to i8*), align 8 > > -Chris-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140310/455991ad/attachment.html>
Chandler Carruth
2014-Mar-11 01:23 UTC
[LLVMdev] GlobalValues appear in their own use lists?
On Mon, Mar 10, 2014 at 6:16 PM, Sean Callanan <scallanan at apple.com> wrote:> Chris, > > this is a patch against top-of-tree. Maybe I wrote something wrong in the > patch? >As Chris said, use_iterator walks over the Use objects now, not over the User objects. Sadly, a Use *implicitly converts* to the used value. IE, directly back to the Value you called 'use_begin()' on. That is why this assert is firing. =[ If you want to walk the Users which Use an object (rather than the Use nodes that connect them) use the newly minted Value::user_iterator (or a range based for loop over GV.users()). -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140310/9b80e682/attachment.html>
On Mar 10, 2014, at 6:23 PM, Chandler Carruth <chandlerc at google.com> wrote:> > On Mon, Mar 10, 2014 at 6:16 PM, Sean Callanan <scallanan at apple.com> wrote: > Chris, > > this is a patch against top-of-tree. Maybe I wrote something wrong in the patch? > > As Chris said, use_iterator walks over the Use objects now, not over the User objects. > > Sadly, a Use *implicitly converts* to the used value. IE, directly back to the Value you called 'use_begin()' on. That is why this assert is firing. =[ > > If you want to walk the Users which Use an object (rather than the Use nodes that connect them) use the newly minted Value::user_iterator (or a range based for loop over GV.users()).Chandler, the implicit conversion is an extremely scary thing now in the presence of both use_iterator and user_iterator. Can you remove the implicit conversion? If not, I think we have to get rid of one or the other, or rename them to be less similar. -Chris -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140310/89c2c42c/attachment.html>
Ohhh, I see! Thanks Chandler and Chris, that makes more sense now. All I have to do, then, is fix some of LLDB’s logic that is now using the implicit conversion. Sean On Mar 10, 2014, at 6:23 PM, Chandler Carruth <chandlerc at google.com> wrote:> > On Mon, Mar 10, 2014 at 6:16 PM, Sean Callanan <scallanan at apple.com> wrote: > Chris, > > this is a patch against top-of-tree. Maybe I wrote something wrong in the patch? > > As Chris said, use_iterator walks over the Use objects now, not over the User objects. > > Sadly, a Use *implicitly converts* to the used value. IE, directly back to the Value you called 'use_begin()' on. That is why this assert is firing. =[ > > If you want to walk the Users which Use an object (rather than the Use nodes that connect them) use the newly minted Value::user_iterator (or a range based for loop over GV.users()).-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140311/e8f5983b/attachment.html>