I cannot seem to figure out how to set up zeroinitializer
for a global integer array. At the moment my code outputs:
@a = common global [1 x i32], align 4
However, clang foo.c -S -emit-llvm
produces:
@a = common global [1 x i32] zeroinitializer, align 4
My code is currently this, my setInitializer()
code does not work and is commented out:
TheModule = (argc > 1) ? new Module(argv[1], Context) : new Module("Filename", Context);
// Unrelated code
// currentGlobal->id is a string, currentGlobal->stype->dimension is the array length
TheModule->getOrInsertGlobal(currentGlobal->id, ArrayType::get(Builder.getInt32Ty(), currentGlobal->stype->dimension));
GlobalVariable* gVar = TheModule->getNamedGlobal(currentGlobal->id);
gVar->setLinkage(GlobalValue::CommonLinkage);
// Not working, not sure if this is how it should be done roughly either
/*gVar->setInitializer(
ConstantArray::get(
ArrayType::get(Builder.getInt32Ty(), currentGlobal->stype->dimension),
ArrayRef(0, currentGlobal->stype->dimension)
)
);*/
gVar->setAlignment(4);