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

Conversation

chenzheng1030
Copy link
Collaborator

@chenzheng1030 chenzheng1030 commented Nov 14, 2023

suggested in review of #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.

suggested in review of llvm#69553
@llvmbot
Copy link
Member

llvmbot commented Nov 14, 2023

@llvm/pr-subscribers-llvm-binary-utilities

Author: Chen Zheng (chenzheng1030)

Changes

suggested in review of #69553


Full diff: https://github.com/llvm/llvm-project/pull/72232.diff

2 Files Affected:

  • (modified) llvm/include/llvm/Object/XCOFFObjectFile.h (+1-1)
  • (modified) llvm/lib/Object/XCOFFObjectFile.cpp (+10-14)
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);
 }

consumeError(SI.takeError());
return false;
}
if (Error E = SI.takeError())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Contributor

@diggerlin diggerlin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@chenzheng1030 chenzheng1030 merged commit 1f6eb3c into llvm:main Nov 15, 2023
@chenzheng1030 chenzheng1030 deleted the isFunction branch November 15, 2023 02:42
zahiraam pushed a commit to zahiraam/llvm-project that referenced this pull request Nov 20, 2023
suggested in review of llvm#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.
Guzhu-AMD pushed a commit to GPUOpen-Drivers/llvm-project that referenced this pull request Nov 23, 2023
Local branch amd-gfx 8cdc496 Merged main:beb702c0ad69 into amd-gfx:70925faeed6a
Remote branch main 1f6eb3c [XCOFF]refactor isFunction, NFC (llvm#72232)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants