I'm writing a function pass, and would like to add a global variable of type int in the initialisation phase, for use in the actual work of the pass.
So far, I have
bool doInitialization(Module &M) { LLVMContext &c = M.getContext(); Type *intTy = TypeBuilder<int,false>::get(c); Value *p = M.getOrInsertGlobal("var1",intTy); return true } For whatever reason, var1 has type int*. For example, adding this after the declaration
Type *pt = p->getType(); if (isa<PointerType>(pt)) { errs().write_escaped("Is a pointer ty") << '\n'; } Will end up with a print when the compiled code is run, and
if ((intTy->getPointerTo()) == (p->getType())) { errs().write_escaped("This is confusing") << '\n'; } Will again print the string.
Is it possible to add a global variable of type int using this method, and if so, where am I going wrong?