[llvm-dev] Creating a global variable for a struct array
Tim Northover via llvm-dev
llvm-dev at lists.llvm.org
Thu Oct 1 10:53:10 PDT 2020
On Thu, 1 Oct 2020 at 16:01, Niddodi, Chaitra <chaitra at illinois.edu> wrote:
> //create global variable to hold filename string
> Constant *filenmInit = ConstantDataArray::getString(M.getContext(), "myfile.txt");
> Constant *filenmConst = new GlobalVariable(M, filenmInit->getType(), false,
> GlobalVariable::ExternalLinkage, filenmInit, ".filenm");
filenmConst's LLVM type is "[12 x i8]*" (or similar if I've
miscounted), but I assume the slot in the struct is i8*. So you need
either a bitcast or a getelementptr constant expression to convert it.
Cheers.
Tim.
More information about the llvm-dev
mailing list