[cfe-dev] Why do "Uses" always point to self?

James Molloy james at jamesmolloy.co.uk
Wed Apr 30 02:49:22 PDT 2014


Hi Yaron,

A Use is an edge between a Value and its users. If you dereference a Use,
you get the Value it points to (which of course is your function - the
thing that "is being used" is F). What you want is the *user* of that use,
so you need to call U.getUser().

http://llvm.org/docs/doxygen/html/classllvm_1_1Use.html#details

Cheers,

James


On 30 April 2014 10:01, Yaron Keren <yaron.keren at gmail.com> wrote:

> Hi,
>
> I use the code from the LLVM programmer manual
>
>
> http://www.llvm.org/docs/ProgrammersManual.html#iterating-over-def-use-use-def-chains
>
>   for (llvm::Value::use_iterator i = F->use_begin(), e = F->use_end(); i
> != e; ++i) {
>
> to iterate over Function '_Z2tcv' uses in the trivial module
>
> ; ModuleID = 'module'
> target datalayout = "e-m:w-p:32:32-i64:64-f80:32-n8:16:32-S32"
> target triple = "i686-pc-windows-gnu"
>
> ; Function Attrs: nounwind
> define void @_Z2tcv() #0 {
> entry:
>   ret void
> }
>
> ; Function Attrs: nounwind
> define i32 @main() #0 {
> entry:
>   call void @_Z2tcv()
>   ret i32 0
> }
>
> attributes #0 = { nounwind "less-precise-fpmad"="false"
> "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf"
> "no-infs-fp-math"="false" "no-nans-fp-math"="false"
> "stack-protector-buffer-size"="8" "unsafe-fp-math"="false" "use-soft
> -float"="false" }
>
> !llvm.ident = !{!0}
>
> !0 = metadata !{metadata !"clang version 3.5.0 (207351)"}
>
> _Z2tcv has indeed one use, as expected, but the use is not a call
> instruction as in main as expected so
>
>  llvm::Instruction *Inst = dyn_cast<llvm::Instruction>(*i)
>
> results in NULL.
>
> Examining the use value with the code
>
> const llvm::Use &U = (*i);
>
> indeed shows that U is same value as F, so F uses itself??
>
> I have seen this in more complicated cases, the number of uses is as
> expected but the uses always point to the function or variable and not the
> real users.
>
> What is wrong?
>
> Thanks, Yaron
>
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140430/5fc43e66/attachment.html>


More information about the cfe-dev mailing list