getAnalysis<DataLayout>() Causing Compilation Error

I’m debugging SAFECode source code files, and in AllocatorInfo.cpp, in the function getObjectSize(Value* V), the function getAnalysis<DataLayout>() is called. I’ve run into this problem before, and the first time I saw it, my employer recommended I use M.getDataLayout() instead, where M was a reference to a Module. However, in getObjectSize(Value* V), there is no Module reference in the list of parameters. Is there a way to obtain a Module affiliated with the Value* argument, which I can then use to call M.getDataLayout? Is there some other way I can get the DataLayout reference I need?

Thanks,
Peter Finn

So, this is because AllocatorInfo is an ImmutablePass.

This leaves you having to grab it the hard way:

If value* is an instruction,

dyn_cast<Instruction>(V)->getModule()->getDataLayout().

if value * is a GlobalValue
/* getParent gives a module here */

dyn_cast<GlobalValue>(V)->getParent()->getDataLayout();

if value * is an argument
/* getParent gives a function, and getParent on the function gives our module */
dyn_cast<Argument>(V)->getParent()->getParent()->getDataLayout();

It may be worth making a helper (or making this consistent in some way
by adding getDataLayout() to Value* and overriding it in subclasses or
something).

Thank you, but how can I determine whether a given Value* V is an Instruction, or a GlobalValue, or an Argument?

Peter Finn

Peter Finn wrote:

Thank you, but how can I determine whether a given Value* V is an Instruction, or a GlobalValue, or an Argument?

http://llvm.org/docs/ProgrammersManual.html#the-isa-cast-and-dyn-cast-templates

Nick