Home:ALL Converter>LLVM Function::getContext() - private within this context

LLVM Function::getContext() - private within this context

Ask Time:2015-05-16T03:07:23         Author:Mike Chong

Json Formatter

So I am writing a FunctionPass for LLVM, and attempting to add some call instruction to a function.

If I make a call to Type::getVoidTy(); like this:

Type::getVoidTy(F.getContext());

Everything compiles fine.

However if I do this:

llvm::LLVMContext context = F.getContext();
Type::getVoidTy(context);

I get the following compile error when I try and compile the pass:

llvm-3.2.src/include/llvm/LLVMContext.h: In member function ‘virtual bool {anonymous}::Hello::runOnFunction(llvm::Function&)’:
llvm-3.2.src/include/llvm/LLVMContext.h:93:3: error: ‘llvm::LLVMContext::LLVMContext(llvm::LLVMContext&)’ is private
   LLVMContext(LLVMContext&) LLVM_DELETED_FUNCTION;
   ^
llvm-3.2.src/lib/Transforms/Hello/Hello.cpp:370:48: error: within this context
       llvm::LLVMContext context = F.getContext();
                                                ^

So I guess this is an issue with my understanding of c++, but I don't see why the call to the accessor would work in the one case, but not the other, in the same scope..

Author:Mike Chong,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/30267023/llvm-functiongetcontext-private-within-this-context
yy