Handle ConstantAggregateZero when upgrading global_ctors.

llvm-svn: 209075
This commit is contained in:
Rafael Espindola 2014-05-17 21:00:22 +00:00
parent 6172277e9f
commit 77bbb54fbf
3 changed files with 12 additions and 6 deletions

View File

@ -191,10 +191,12 @@ static bool UpgradeGlobalStructors(GlobalVariable *GV) {
StructType::get(GV->getContext(), Tys, /*isPacked=*/false);
// Build new constants with a null third field filled in.
ConstantArray *OldInit = dyn_cast<ConstantArray>(GV->getInitializer());
if (!OldInit)
Constant *OldInitC = GV->getInitializer();
ConstantArray *OldInit = dyn_cast<ConstantArray>(OldInitC);
if (!OldInit && !isa<ConstantAggregateZero>(OldInitC))
return false;
std::vector<Constant *> Initializers;
if (OldInit) {
for (Use &U : OldInit->operands()) {
ConstantStruct *Init = cast<ConstantStruct>(&U);
Constant *NewInit =
@ -202,6 +204,7 @@ static bool UpgradeGlobalStructors(GlobalVariable *GV) {
Constant::getNullValue(VoidPtrTy), nullptr);
Initializers.push_back(NewInit);
}
}
assert(Initializers.size() == ATy->getNumElements());
// Replace the old GV with a new one.

View File

@ -0,0 +1,3 @@
; RUN: llvm-dis < %s.bc| FileCheck %s
; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer

Binary file not shown.