diff options
author | Chen Zheng <czhengsz@cn.ibm.com> | 2023-11-15 10:41:59 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-15 10:41:59 +0800 |
commit | 1f6eb3ca5cb1551b537141fc84827d704917a97b (patch) | |
tree | 3a11e27e3b3c3737c46d247a8101492633009df5 /llvm/lib/Object/XCOFFObjectFile.cpp | |
parent | 72accbfd0a1023b3182202276904120524ff9200 (diff) | |
download | llvm-1f6eb3ca5cb1551b537141fc84827d704917a97b.zip llvm-1f6eb3ca5cb1551b537141fc84827d704917a97b.tar.gz llvm-1f6eb3ca5cb1551b537141fc84827d704917a97b.tar.bz2 |
[XCOFF]refactor isFunction, NFC (#72232)
suggested in review of https://github.com/llvm/llvm-project/pull/69553
This is actually not an NFC as isFunction() does not return false for
some "invalid" object, instead it returns the errors to its caller. But
since there is no such invalid object in the LIT tests, so no case
changes.
Diffstat (limited to 'llvm/lib/Object/XCOFFObjectFile.cpp')
-rw-r--r-- | llvm/lib/Object/XCOFFObjectFile.cpp | 24 |
1 files changed, 10 insertions, 14 deletions
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp index 4c192aa..07e1054f 100644 --- a/llvm/lib/Object/XCOFFObjectFile.cpp +++ b/llvm/lib/Object/XCOFFObjectFile.cpp @@ -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()) @@ -1225,7 +1229,7 @@ std::optional<StringRef> XCOFFObjectFile::tryGetCPUName() const { return StringRef("future"); } -bool XCOFFSymbolRef::isFunction() const { +Expected<bool> XCOFFSymbolRef::isFunction() const { if (!isCsectSymbol()) return false; @@ -1233,12 +1237,8 @@ bool XCOFFSymbolRef::isFunction() const { 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(); @@ -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); } |