Finding the uses of a global variable

Hi everyone,
I am writing a pass that finds all uses of global variables (my goal is to find the uses of strings, and strings are defined as global variables). So, I can iterate over global vars by
for(Module::global_iterator gi = M.global_begin(), gend = M.global_end(); gi != gend; ++gi) …
But if I use its def-use chain
for(Value::use_iterator i = gi->use_begin(), e = F->use_end; i!=e; ++i)
it is not actually able to find its uses, as it gives instructions!
I have even tried to iterate over instructions in the module, then find the use-def of each instruction
for(User::op_iterator I = theInstruction->op_begin(), E=theInstruction->op_end(); I!=E; ++I)
After it I have tried to check whether this “theInstruction” is one of global vars (one of the “gi”-s).
But that doesn’t work either, as LLVM does not think that the global vars, which are used in an instruction, are operands of that instruction!
So anyway, how can I find the def-uses of global variables??
—Schuhmacher

Hi Deu,

I am writing a pass that finds all uses of global variables (my goal is to find
the uses of strings, and strings are defined as global variables). So, I can
iterate over global vars by
for(Module::global_iterator gi = M.global_begin(), gend = M.global_end(); gi !=
gend; ++gi) ......
But if I use its def-use chain
for(Value::use_iterator i = gi->use_begin(), e = F->use_end; i!=e; ++i)

this is the correct approach, though that should presumably be gi->use_end()
rather than F->use_end.

it is not actually able to find its uses, as it gives <null> instructions!

That just means that the uses are not instructions. Must likely they are
ConstantExpr's, probably bitcast or getelementptr constant expressions.

Ciao, Duncan.