[LLVMdev] getAnalysis<DataLayout>() Causing Compilation Error

Daniel Berlin dberlin at dberlin.org
Sun Jun 21 16:41:10 PDT 2015


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).




On Sun, Jun 21, 2015 at 4:31 PM, Peter Finn <peterdfinn at icloud.com> wrote:
> 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
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list