Accessing constant contents


I have a global variable in LLVM IR:

@mem8 = private unnamed_addr constant [9 x i8] c"Hello12\0A\00", align 1

I have loaded the module, so now have:
llvm::Value *value1;
That will output:
@mem8 = private unnamed_addr constant [9 x i8] c"Hello12\0A\00", align 1

What method should I use to access the contents of the constant.
I.e. I want the "Hello12" bytes contained in @mem8 to be put in a

I can access the Type hierarchy, but cannot find how to access the
value contents.

Kind Regards


Hi James,

I haven't tried it but if my memory is not failing me you should be able to

ask for the initializer of the llvm::GlobalVariable, which is a constant.

That should actually be a llvm::ConstantDataSequential in this case which has

methods like isString, getString, getCString,...

Oh, and your value1 is the llvm::GlobalVariable I am talking about, so something along the lines of:

auto *GV = cast<GlobalVariable>(value1);

auto *CDS = cast<ConstantDataSequential>(GV->getInitializer());


Hope this helps,


The "hello" string is a part of the GlobalVariable's initializer. You can use GlobalVariable::getInitializer to get a Constant with the initializer value, and then, depending on the actual type of it you can get the contents of it.