Skip to content

Commit

Permalink
[RISCV][NFC] Use errorToBool (#76429)
Browse files Browse the repository at this point in the history
To reduce calls to `consumeError`.
  • Loading branch information
wangpc-pp committed Dec 28, 2023
1 parent 52770d8 commit 5c27e00
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 19 deletions.
3 changes: 1 addition & 2 deletions clang/lib/Basic/Targets/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -416,8 +416,7 @@ static void handleFullArchString(StringRef FullArchStr,
Features.push_back("__RISCV_TargetAttrNeedOverride");
auto RII = llvm::RISCVISAInfo::parseArchString(
FullArchStr, /* EnableExperimentalExtension */ true);
if (!RII) {
consumeError(RII.takeError());
if (llvm::errorToBool(RII.takeError())) {
// Forward the invalid FullArchStr.
Features.push_back("+" + FullArchStr.str());
} else {
Expand Down
6 changes: 2 additions & 4 deletions clang/lib/Driver/ToolChains/Arch/RISCV.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,8 @@ StringRef riscv::getRISCVABI(const ArgList &Args, const llvm::Triple &Triple) {

auto ParseResult = llvm::RISCVISAInfo::parseArchString(
Arch, /* EnableExperimentalExtension */ true);
if (!ParseResult)
// Ignore parsing error, just go 3rd step.
consumeError(ParseResult.takeError());
else
// Ignore parsing error, just go 3rd step.
if (!llvm::errorToBool(ParseResult.takeError()))
return (*ParseResult)->computeDefaultABI();

// 3. Choose a default based on the triple
Expand Down
7 changes: 2 additions & 5 deletions clang/lib/Driver/ToolChains/Clang.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2072,12 +2072,9 @@ void Clang::AddRISCVTargetArgs(const ArgList &Args,
StringRef Arch = riscv::getRISCVArch(Args, Triple);
auto ISAInfo = llvm::RISCVISAInfo::parseArchString(
Arch, /*EnableExperimentalExtensions*/ true);
if (!ISAInfo) {
// Ignore parsing error.
consumeError(ISAInfo.takeError());
} else {
// Ignore parsing error.
if (!errorToBool(ISAInfo.takeError()))
MinVLen = (*ISAInfo)->getMinVLen();
}

// If the value is "zvl", use MinVLen from march. Otherwise, try to parse
// as integer as long as we have a MinVLen.
Expand Down
12 changes: 4 additions & 8 deletions clang/lib/Driver/ToolChains/Gnu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1741,11 +1741,9 @@ selectRISCVMultilib(const MultilibSet &RISCVMultilibSet, StringRef Arch,
llvm::RISCVISAInfo::parseArchString(
Arch, /*EnableExperimentalExtension=*/true,
/*ExperimentalExtensionVersionCheck=*/false);
if (!ParseResult) {
// Ignore any error here, we assume it will be handled in another place.
consumeError(ParseResult.takeError());
// Ignore any error here, we assume it will be handled in another place.
if (llvm::errorToBool(ParseResult.takeError()))
return false;
}

auto &ISAInfo = *ParseResult;

Expand Down Expand Up @@ -1780,10 +1778,8 @@ selectRISCVMultilib(const MultilibSet &RISCVMultilibSet, StringRef Arch,
llvm::RISCVISAInfo::parseArchString(
Flag, /*EnableExperimentalExtension=*/true,
/*ExperimentalExtensionVersionCheck=*/false);
if (!MLConfigParseResult) {
// Ignore any error here, we assume it will handled in another place.
llvm::consumeError(MLConfigParseResult.takeError());

// Ignore any error here, we assume it will handled in another place.
if (llvm::errorToBool(MLConfigParseResult.takeError())) {
// We might get a parsing error if rv32e in the list, we could just skip
// that and process the rest of multi-lib configs.
Skip = true;
Expand Down

0 comments on commit 5c27e00

Please sign in to comment.