Skip to content

Commit

Permalink
[AIX][TOC] Fix buildbot failures from commit b4ae8df (#85303)
Browse files Browse the repository at this point in the history
The following tests fail when built with Address
and Undefined sanitizers:
CodeGen/PowerPC/basic-toc-data-def.ll
CodeGen/PowerPC/toc-data-large-array2.ll

Subtarget may be null in emitGlobalVariable, for example in the testcase
where we have no functions in the IR. The fix moves this function from
PPCSubtarget to a static helper function. This only fails with
sanitizers because the Subtarget is not used in the member function.
  • Loading branch information
syzaara committed Mar 14, 2024
1 parent c56bd7a commit 00ba2a6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 25 deletions.
23 changes: 22 additions & 1 deletion llvm/lib/Target/PowerPC/PPCAsmPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2651,6 +2651,27 @@ uint64_t PPCAIXAsmPrinter::getAliasOffset(const Constant *C) {
return 0;
}

static void tocDataChecks(unsigned PointerSize, const GlobalVariable *GV) {
// TODO: These asserts should be updated as more support for the toc data
// transformation is added (struct support, etc.).
assert(
PointerSize >= GV->getAlign().valueOrOne().value() &&
"GlobalVariables with an alignment requirement stricter than TOC entry "
"size not supported by the toc data transformation.");

Type *GVType = GV->getValueType();
assert(GVType->isSized() && "A GlobalVariable's size must be known to be "
"supported by the toc data transformation.");
if (GV->getParent()->getDataLayout().getTypeSizeInBits(GVType) >
PointerSize * 8)
report_fatal_error(
"A GlobalVariable with size larger than a TOC entry is not currently "
"supported by the toc data transformation.");
if (GV->hasPrivateLinkage())
report_fatal_error("A GlobalVariable with private linkage is not "
"currently supported by the toc data transformation.");
}

void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// Special LLVM global arrays have been handled at the initialization.
if (isSpecialLLVMGlobalArrayToSkip(GV) || isSpecialLLVMGlobalArrayForStaticInit(GV))
Expand All @@ -2660,7 +2681,7 @@ void PPCAIXAsmPrinter::emitGlobalVariable(const GlobalVariable *GV) {
// when we emit the .toc section.
if (GV->hasAttribute("toc-data")) {
unsigned PointerSize = GV->getParent()->getDataLayout().getPointerSize();
Subtarget->tocDataChecks(PointerSize, GV);
tocDataChecks(PointerSize, GV);
TOCDataGlobalVars.push_back(GV);
return;
}
Expand Down
22 changes: 0 additions & 22 deletions llvm/lib/Target/PowerPC/PPCSubtarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,28 +185,6 @@ bool PPCSubtarget::enableSubRegLiveness() const {
return UseSubRegLiveness;
}

void PPCSubtarget::tocDataChecks(unsigned PointerSize,
const GlobalVariable *GV) const {
// TODO: These asserts should be updated as more support for the toc data
// transformation is added (struct support, etc.).
assert(
PointerSize >= GV->getAlign().valueOrOne().value() &&
"GlobalVariables with an alignment requirement stricter than TOC entry "
"size not supported by the toc data transformation.");

Type *GVType = GV->getValueType();
assert(GVType->isSized() && "A GlobalVariable's size must be known to be "
"supported by the toc data transformation.");
if (GV->getParent()->getDataLayout().getTypeSizeInBits(GVType) >
PointerSize * 8)
report_fatal_error(
"A GlobalVariable with size larger than a TOC entry is not currently "
"supported by the toc data transformation.");
if (GV->hasPrivateLinkage())
report_fatal_error("A GlobalVariable with private linkage is not "
"currently supported by the toc data transformation.");
}

bool PPCSubtarget::isGVIndirectSymbol(const GlobalValue *GV) const {
// Large code model always uses the TOC even for local symbols.
if (TM.getCodeModel() == CodeModel::Large)
Expand Down
2 changes: 0 additions & 2 deletions llvm/lib/Target/PowerPC/PPCSubtarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,6 @@ class PPCSubtarget : public PPCGenSubtargetInfo {
/// True if the GV will be accessed via an indirect symbol.
bool isGVIndirectSymbol(const GlobalValue *GV) const;

void tocDataChecks(unsigned PointerSize, const GlobalVariable *GV) const;

/// True if the ABI is descriptor based.
bool usesFunctionDescriptors() const {
// Both 32-bit and 64-bit AIX are descriptor based. For ELF only the 64-bit
Expand Down

0 comments on commit 00ba2a6

Please sign in to comment.