[llvm] [XCOFF]refactor isFunction, NFC (PR #72232)
Chen Zheng via llvm-commits
llvm-commits at lists.llvm.org
Tue Nov 14 01:02:55 PST 2023
https://github.com/chenzheng1030 created https://github.com/llvm/llvm-project/pull/72232
suggested in review of https://github.com/llvm/llvm-project/pull/69553
>From e49bba68246d60827bd404e1159072929ce5c705 Mon Sep 17 00:00:00 2001
From: Chen Zheng <czhengsz at cn.ibm.com>
Date: Tue, 14 Nov 2023 04:01:08 -0500
Subject: [PATCH] nfc, refactor isFunction
suggested in review of https://github.com/llvm/llvm-project/pull/69553
---
llvm/include/llvm/Object/XCOFFObjectFile.h | 2 +-
llvm/lib/Object/XCOFFObjectFile.cpp | 24 +++++++++-------------
2 files changed, 11 insertions(+), 15 deletions(-)
diff --git a/llvm/include/llvm/Object/XCOFFObjectFile.h b/llvm/include/llvm/Object/XCOFFObjectFile.h
index 63064abb4d3c322..e3b91961d636c52 100644
--- a/llvm/include/llvm/Object/XCOFFObjectFile.h
+++ b/llvm/include/llvm/Object/XCOFFObjectFile.h
@@ -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;
diff --git a/llvm/lib/Object/XCOFFObjectFile.cpp b/llvm/lib/Object/XCOFFObjectFile.cpp
index 4c192aa37a7ecc7..9b2bc2cffc4a2fb 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 (Error E = IsFunction.takeError())
+ return std::move(E);
+
+ 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 (Error E = ExpCsectAuxEnt.takeError())
+ return std::move(E);
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 (Error E = SI.takeError())
+ return std::move(E);
return (getObject()->getSectionFlags(SI.get()) & XCOFF::STYP_TEXT);
}
More information about the llvm-commits
mailing list