[llvm-dev] Use iterator misunderstanding?

Pierre Gagelin via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 30 02:05:24 PDT 2016


I try to follow the use of the value yielded by a malloc call. Here follows
a concrete example of what I expect and what I get.

define void @main() #0 {
  %ptr = alloca i8*, align 8
  %call = call noalias i8* @malloc(i64 10) #2
  store i8* %call, i8** %ptr, align 8
  %0 = load i8*, i8** %ptr, align 8
  call void @free(i8* %0) #2
  ret void

It is a simple program that allocates and frees a pointer. Now I
intercepted the call instruction to malloc and iterated over its uses. I
expected to have 2 results:

  %call = call noalias i8* @malloc(i64 10) #2
  store i8* %call, i8** %ptr, align 8

But I only get the first one. Is it normal? What should I do to get both?
Here the piece of code I used to iterate:

CallInst *CI = ...The call to malloc...
errs() << "  Value use:\n";
  for(Value::use_iterator i = CI->use_begin(), e = CI->use_end(); i != e;
++i) {
    Use *use_i = &*i;
    if(Instruction *I = dyn_cast<Instruction>(use_i)) {
      errs() << "    instruction: " <<
        *I << "\n";

And I get this output:

  Value use:
    instruction:   %call = call noalias i8* @malloc(i64 10) #2

Thanks for your time and help,
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20160630/bfee128e/attachment.html>

More information about the llvm-dev mailing list