[llvm-dev] Question about global variable type

Mahesha S via llvm-dev llvm-dev at lists.llvm.org
Tue Jan 22 05:22:23 PST 2019


Hi,

Let's say, we want to insert a global variable to a module, that, we can
accomplish as shown in the below code snippet. However, if I compare the
original type with the type after the call to getOrInsertGlobal(), the two
pointers are different as shown. Is it a correct behavior? If so, what is
the right way to get the type of global variable so that it is same as
original type?

PS: I am using LLVM versoin 8

------------------
// Get type of global variable to be inserted
auto varType = IntegerType::get(M.getContext(), 32);
outs() << "varType = " << varType << "\n";


// Insert newly created variable to current module
auto globalVar = M.getOrInsertGlobal("myVar", varType);
outs() << "varType = " << globalVar->getType() << "\n";
------------------


------------------
varType = 0x5567b71a22b8
varType = 0x5567b71ce1b0
------------------

-- 
Thanks,
Mahesha
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20190122/7a3b5d7f/attachment.html>


More information about the llvm-dev mailing list