Question about global variable type


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

Globals (as an instance of Value) have a type that's a pointer to the
allocated storage. So in this case globalVar->getType() is actually
"i32*" rather than i32. GlobalValue::getValueType will return the
underlying type.

You could use Type::dump to see this kind of thing more quickly in future.