【发布时间】:2014-04-27 22:49:41
【问题描述】:
我似乎不知道如何为全局整数数组设置zeroinitializer。目前我的代码输出:
@a = common global [1 x i32], align 4
但是,clang foo.c -S -emit-llvm 会产生:
@a = common global [1 x i32] zeroinitializer, align 4
我的代码目前是这样的,我的setInitializer()代码不起作用并被注释掉:
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);
【问题讨论】: