Skip to content

Commit 1f6eb3c

Browse files
author
Chen Zheng
authored
[XCOFF]refactor isFunction, NFC (llvm#72232)
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.
1 parent 72accbf commit 1f6eb3c

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

llvm/include/llvm/Object/XCOFFObjectFile.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -838,7 +838,7 @@ class XCOFFSymbolRef : public SymbolRef {
838838
}
839839

840840
Expected<StringRef> getName() const;
841-
bool isFunction() const;
841+
Expected<bool> isFunction() const;
842842
bool isCsectSymbol() const;
843843
Expected<XCOFFCsectAuxRef> getXCOFFCsectAuxRef() const;
844844

llvm/lib/Object/XCOFFObjectFile.cpp

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,11 @@ Expected<SymbolRef::Type>
299299
XCOFFObjectFile::getSymbolType(DataRefImpl Symb) const {
300300
XCOFFSymbolRef XCOFFSym = toSymbolRef(Symb);
301301

302-
if (XCOFFSym.isFunction())
302+
Expected<bool> IsFunction = XCOFFSym.isFunction();
303+
if (!IsFunction)
304+
return IsFunction.takeError();
305+
306+
if (*IsFunction)
303307
return SymbolRef::ST_Function;
304308

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

1228-
bool XCOFFSymbolRef::isFunction() const {
1232+
Expected<bool> XCOFFSymbolRef::isFunction() const {
12291233
if (!isCsectSymbol())
12301234
return false;
12311235

12321236
if (getSymbolType() & FunctionSym)
12331237
return true;
12341238

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

12431243
const XCOFFCsectAuxRef CsectAuxRef = ExpCsectAuxEnt.get();
12441244

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

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

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

0 commit comments

Comments
 (0)