From e7a6c2f1dfca147cdedb9683f7193882b548753d Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Sat, 17 May 2014 21:00:22 +0000 Subject: [PATCH] Handle ConstantAggregateZero when upgrading global_ctors. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@209075 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/IR/AutoUpgrade.cpp | 15 +++++++++------ test/Bitcode/upgrade-global-ctors.ll | 3 +++ test/Bitcode/upgrade-global-ctors.ll.bc | Bin 0 -> 316 bytes 3 files changed, 12 insertions(+), 6 deletions(-) create mode 100644 test/Bitcode/upgrade-global-ctors.ll create mode 100644 test/Bitcode/upgrade-global-ctors.ll.bc diff --git a/lib/IR/AutoUpgrade.cpp b/lib/IR/AutoUpgrade.cpp index d0fb71f341b..e255113aab7 100644 --- a/lib/IR/AutoUpgrade.cpp +++ b/lib/IR/AutoUpgrade.cpp @@ -191,16 +191,19 @@ 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(GV->getInitializer()); - if (!OldInit) + Constant *OldInitC = GV->getInitializer(); + ConstantArray *OldInit = dyn_cast(OldInitC); + if (!OldInit && !isa(OldInitC)) return false; std::vector Initializers; - for (Use &U : OldInit->operands()) { - ConstantStruct *Init = cast(&U); - Constant *NewInit = + if (OldInit) { + for (Use &U : OldInit->operands()) { + ConstantStruct *Init = cast(&U); + Constant *NewInit = ConstantStruct::get(NewTy, Init->getOperand(0), Init->getOperand(1), Constant::getNullValue(VoidPtrTy), nullptr); - Initializers.push_back(NewInit); + Initializers.push_back(NewInit); + } } assert(Initializers.size() == ATy->getNumElements()); diff --git a/test/Bitcode/upgrade-global-ctors.ll b/test/Bitcode/upgrade-global-ctors.ll new file mode 100644 index 00000000000..bd253a81620 --- /dev/null +++ b/test/Bitcode/upgrade-global-ctors.ll @@ -0,0 +1,3 @@ +; RUN: llvm-dis < %s.bc| FileCheck %s + +; CHECK: @llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }] zeroinitializer diff --git a/test/Bitcode/upgrade-global-ctors.ll.bc b/test/Bitcode/upgrade-global-ctors.ll.bc new file mode 100644 index 0000000000000000000000000000000000000000..927fd91867e916a35fecbfa76fceb24166039599 GIT binary patch literal 316 zcmZ>AK5$Qwhk?O|fq{X$Nr8b0NDBcmd!zD1#}h1`Yyw7>lNeigR9QJBt%tiM#YaG4z^NfN2tpMMb20mjRC%HohWzQ{?Ni$#tD{GcM!)$xP*|vw-_Dn@jNdbE` y2YaPQdqDwvRRMEZMSFn)JJ9Sx1qKEdAk8MA>wWacu}3TiK5