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

Yaron Keren yaron.keren at gmail.com
Wed Apr 30 02:01:53 PDT 2014


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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140430/f0d09463/attachment.html>


More information about the cfe-dev mailing list