Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 14 additions & 13 deletions llvm/lib/CodeGen/AsmPrinter/AsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3914,21 +3914,22 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
if (isa<ConstantAggregateZero>(CV)) {
StructType *structType;
if (AliasList && (structType = llvm::dyn_cast<StructType>(CV->getType()))) {
// Handle cases of aliases to direct struct elements
const StructLayout *Layout = DL.getStructLayout(structType);
uint64_t SizeSoFar = 0;
for (unsigned int i = 0, n = structType->getNumElements(); i < n - 1;
++i) {
uint64_t GapToNext = Layout->getElementOffset(i + 1) - SizeSoFar;
AP.OutStreamer->emitZeros(GapToNext);
SizeSoFar += GapToNext;
emitGlobalAliasInline(AP, Offset + SizeSoFar, AliasList);
unsigned numElements = {structType->getNumElements()};
if (numElements != 0) {
// Handle cases of aliases to direct struct elements
const StructLayout *Layout = DL.getStructLayout(structType);
uint64_t SizeSoFar = 0;
for (unsigned int i = 0; i < numElements - 1; ++i) {
uint64_t GapToNext = Layout->getElementOffset(i + 1) - SizeSoFar;
AP.OutStreamer->emitZeros(GapToNext);
SizeSoFar += GapToNext;
emitGlobalAliasInline(AP, Offset + SizeSoFar, AliasList);
}
AP.OutStreamer->emitZeros(Size - SizeSoFar);
return;
}
AP.OutStreamer->emitZeros(Size - SizeSoFar);
return;
} else {
return AP.OutStreamer->emitZeros(Size);
}
return AP.OutStreamer->emitZeros(Size);
}

if (isa<UndefValue>(CV))
Expand Down
20 changes: 20 additions & 0 deletions llvm/test/CodeGen/PowerPC/global-merge-aix-zero-size-struct.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr7 < %s | FileCheck %s

; RUN: llc -verify-machineinstrs -mtriple powerpc64-ibm-aix-xcoff -mcpu=pwr7 --filetype=obj -o %t.o < %s
; RUN: llvm-objdump --syms %t.o | FileCheck %s --check-prefix=OBJ

%struct.anon = type {}

@a = internal constant %struct.anon zeroinitializer, align 1
@b = internal constant [6 x i8] c"hello\00", align 1

; CHECK: .csect L.._MergedGlobals[RO],2
; CHECK-NEXT: .lglobl a # @_MergedGlobals
; CHECK-NEXT: .lglobl b
; CHECK-NEXT: a:
; CHECK-NEXT: b:
; CHECK-NEXT: .string "hello"

; OBJ: 0000000000000000 l .text 0000000000000006 L.._MergedGlobals
; OBJ-NEXT: 0000000000000000 l .text (csect: L.._MergedGlobals) 0000000000000000 a
; OBJ-NEXT: 0000000000000000 l .text (csect: L.._MergedGlobals) 0000000000000000 b
Loading