Error LTO::runRegularLTO(AddOutputFn AddOutput) {
// Make sure commons have the right size/alignment: we kept the largest from
// all the prevailing when adding the inputs, and we apply it here.
+ const DataLayout &DL = RegularLTO.CombinedModule->getDataLayout();
for (auto &I : RegularLTO.Commons) {
- ArrayType *Ty =
- ArrayType::get(Type::getInt8Ty(RegularLTO.Ctx), I.second.Size);
GlobalVariable *OldGV = RegularLTO.CombinedModule->getNamedGlobal(I.first);
- if (OldGV && OldGV->getType()->getElementType() == Ty) {
+ if (OldGV && DL.getTypeAllocSize(OldGV->getValueType()) == I.second.Size) {
// Don't create a new global if the type is already correct, just make
// sure the alignment is correct.
OldGV->setAlignment(I.second.Align);
continue;
}
+ ArrayType *Ty =
+ ArrayType::get(Type::getInt8Ty(RegularLTO.Ctx), I.second.Size);
auto *GV = new GlobalVariable(*RegularLTO.CombinedModule, Ty, false,
GlobalValue::CommonLinkage,
ConstantAggregateZero::get(Ty), "");
; RUN: llvm-dis %t3.o -o - | FileCheck %s --check-prefix=B
; (i16 align 8) + (i8 align 16) = i16 align 16
-; B: @a = common global [2 x i8] zeroinitializer, align 16
+; B: @a = common global i16 0, align 16
; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN: --plugin-opt=emit-llvm \
; RUN: llvm-dis %t3.o -o - | FileCheck %s --check-prefix=C
; (i16 align 8) + (i8 align 1) = i16 align 8.
-; C: @a = common global [2 x i8] zeroinitializer, align 8
+; C: @a = common global i16 0, align 8
; RUN: %gold -plugin %llvmshlibdir/LLVMgold.so \
; RUN: --plugin-opt=emit-llvm \
; RUN: llvm-dis %t3.o -o - | FileCheck --check-prefix=MIXED %s
; Mixed ELF and IR. We keep ours as common so the linker will finish the merge.
-; MIXED: @a = common global [2 x i8] zeroinitializer, align 8
+; MIXED: @a = common global i16 0, align 8