Skip to content

[XCOFF]refactor isFunction, NFC #72232

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 15, 2023
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
2 changes: 1 addition & 1 deletion llvm/include/llvm/Object/XCOFFObjectFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -838,7 +838,7 @@ class XCOFFSymbolRef : public SymbolRef {
}

Expected<StringRef> getName() const;
bool isFunction() const;
Expected<bool> isFunction() const;
bool isCsectSymbol() const;
Expected<XCOFFCsectAuxRef> getXCOFFCsectAuxRef() const;

Expand Down
24 changes: 10 additions & 14 deletions llvm/lib/Object/XCOFFObjectFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,11 @@ Expected<SymbolRef::Type>
XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const {
XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);

if (XCOFFSym.isFunction())
Expected<bool> IsFunction = XCOFFSym.isFunction();
if (!IsFunction)
return IsFunction.takeError();

if (*IsFunction)
return SymbolRef::ST_Function;

if (XCOFF::C_FILE == XCOFFSym.getStorageClass())
Expand Down Expand Up @@ -1225,20 +1229,16 @@ std::optional<StringRef> XCOFFObjectFile::tryGetCPUName() const {
return StringRef("future");
}

bool XCOFFSymbolRef::isFunction() const {
Expected<bool> XCOFFSymbolRef::isFunction() const {
if (!isCsectSymbol())
return false;

if (getSymbolType() & FunctionSym)
return true;

Expected<XCOFFCsectAuxRef> ExpCsectAuxEnt = getXCOFFCsectAuxRef();
if (!ExpCsectAuxEnt) {
// If we could not get the CSECT auxiliary entry, then treat this symbol as
// if it isn't a function. Consume the error and return `false` to move on.
consumeError(ExpCsectAuxEnt.takeError());
return false;
}
if (!ExpCsectAuxEnt)
return ExpCsectAuxEnt.takeError();

const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get();

Expand All @@ -1253,12 +1253,8 @@ bool XCOFFSymbolRef::isFunction() const {

const int16_t SectNum = getSectionNumber();
Expected<DataRefImpl> SI = getObject()->getSectionByNum(SectNum);
if (!SI) {
// If we could not get the section, then this symbol should not be
// a function. So consume the error and return `false` to move on.
consumeError(SI.takeError());
return false;
}
if (!SI)
return SI.takeError();

return (getObject()->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT);
}
Expand Down