[llvm] [AsmPrinter] Fix handling in emitGlobalConstantImpl for AIX (PR #116255)
Hubert Tong via llvm-commits
llvm-commits at lists.llvm.org
Mon Nov 18 12:22:24 PST 2024
================
@@ -3858,7 +3860,29 @@ static void emitGlobalConstantImpl(const DataLayout &DL, const Constant *CV,
if (!BaseCV && CV->hasOneUse())
BaseCV = dyn_cast<Constant>(CV->user_back());
- if (isa<ConstantAggregateZero>(CV) || isa<UndefValue>(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) {
+ emitGlobalAliasInline(AP, Offset + SizeSoFar, AliasList);
+ uint64_t GapToNext = Layout->getElementOffset(i + 1) - SizeSoFar;
+ AP.OutStreamer->emitZeros(GapToNext);
+ SizeSoFar += GapToNext;
+ }
+ emitGlobalAliasInline(AP, Offset + SizeSoFar, AliasList);
----------------
hubert-reinterpretcast wrote:
The alias-at-offset-zero-from-`Offset` case is already handled in the status quo.
```suggestion
uint64_t GapToNext = Layout->getElementOffset(i + 1) - SizeSoFar;
AP.OutStreamer->emitZeros(GapToNext);
SizeSoFar += GapToNext;
emitGlobalAliasInline(AP, Offset + SizeSoFar, AliasList);
}
```
https://github.com/llvm/llvm-project/pull/116255
More information about the llvm-commits
mailing list