[llvm-dev] Creating a global variable for a struct array
Niddodi, Chaitra via llvm-dev
llvm-dev at lists.llvm.org
Thu Oct 1 13:26:17 PDT 2020
The error still persists despite adding the following cast:
filenmConst = ConstantExpr::getBitCast(filenmConst, Type::getInt8PtrTy(M.getContext()));
That's why I had omitted this line from code earlier.
Thanks,
Chaitra
________________________________
From: Tim Northover <t.p.northover at gmail.com>
Sent: Thursday, October 1, 2020 12:53
To: Niddodi, Chaitra
Cc: llvm-dev at lists.llvm.org
Subject: Re: [llvm-dev] Creating a global variable for a struct array
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20201001/229c1be0/attachment.html>
More information about the llvm-dev
mailing list