[llvm] 86b3f85 - [RISCV] Used Twine concatenation instead of format strings RISCVISAInfo.cpp. NFC
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Sun Jan 28 20:04:14 PST 2024
Author: Craig Topper
Date: 2024-01-28T20:03:53-08:00
New Revision: 86b3f8518f21532297e0aad0c6aea95c66389fc9
URL: https://github.com/llvm/llvm-project/commit/86b3f8518f21532297e0aad0c6aea95c66389fc9
DIFF: https://github.com/llvm/llvm-project/commit/86b3f8518f21532297e0aad0c6aea95c66389fc9.diff
LOG: [RISCV] Used Twine concatenation instead of format strings RISCVISAInfo.cpp. NFC
We were converting several StringRefs to std::strings then to
char * so we could pass as %s to a format string. Use the Twine
signature of createStringError instead.
Added:
Modified:
llvm/lib/Support/RISCVISAInfo.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/RISCVISAInfo.cpp b/llvm/lib/Support/RISCVISAInfo.cpp
index a359e6eefa8f1d1..9a716f7aff1cc94 100644
--- a/llvm/lib/Support/RISCVISAInfo.cpp
+++ b/llvm/lib/Support/RISCVISAInfo.cpp
@@ -550,28 +550,25 @@ static Error getExtensionVersion(StringRef Ext, StringRef In, unsigned &Major,
// Expected multi-character extension with version number to have no
// subsequent characters (i.e. must either end string or be followed by
// an underscore).
- if (Ext.size() > 1 && In.size()) {
- std::string Error =
- "multi-character extensions must be separated by underscores";
- return createStringError(errc::invalid_argument, Error);
- }
+ if (Ext.size() > 1 && In.size())
+ return createStringError(
+ errc::invalid_argument,
+ "multi-character extensions must be separated by underscores");
// If experimental extension, require use of current version number
if (auto ExperimentalExtension = isExperimentalExtension(Ext)) {
- if (!EnableExperimentalExtension) {
- std::string Error = "requires '-menable-experimental-extensions' for "
- "experimental extension '" +
- Ext.str() + "'";
- return createStringError(errc::invalid_argument, Error);
- }
+ if (!EnableExperimentalExtension)
+ return createStringError(errc::invalid_argument,
+ "requires '-menable-experimental-extensions' "
+ "for experimental extension '" +
+ Ext + "'");
if (ExperimentalExtensionVersionCheck &&
- (MajorStr.empty() && MinorStr.empty())) {
- std::string Error =
- "experimental extension requires explicit version number `" +
- Ext.str() + "`";
- return createStringError(errc::invalid_argument, Error);
- }
+ (MajorStr.empty() && MinorStr.empty()))
+ return createStringError(
+ errc::invalid_argument,
+ "experimental extension requires explicit version number `" + Ext +
+ "`");
auto SupportedVers = *ExperimentalExtension;
if (ExperimentalExtensionVersionCheck &&
@@ -826,12 +823,13 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
if (StdExts.contains(C)) {
return createStringError(
errc::invalid_argument,
- "standard user-level extension not given in canonical order '%c'",
- C);
+ "standard user-level extension not given in canonical order '" +
+ Twine(C) + "'");
}
return createStringError(errc::invalid_argument,
- "invalid standard user-level extension '%c'", C);
+ "invalid standard user-level extension '" +
+ Twine(C) + "'");
}
// Move to next char to prevent repeated letter.
@@ -860,8 +858,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
continue;
}
return createStringError(errc::invalid_argument,
- "unsupported standard user-level extension '%c'",
- C);
+ "unsupported standard user-level extension '" +
+ Twine(C) + "'");
}
ISAInfo->addExtension(StringRef(&C, 1), {Major, Minor});
@@ -905,11 +903,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
"invalid extension prefix '" + Ext + "'");
}
- if (!IgnoreUnknown && Name.size() == Type.size()) {
+ if (!IgnoreUnknown && Name.size() == Type.size())
return createStringError(errc::invalid_argument,
- "%s name missing after '%s'",
- Desc.str().c_str(), Type.str().c_str());
- }
+ Desc + " name missing after '" + Type + "'");
unsigned Major, Minor, ConsumeLength;
if (auto E = getExtensionVersion(Name, Vers, Major, Minor, ConsumeLength,
@@ -923,10 +919,9 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
}
// Check if duplicated extension.
- if (!IgnoreUnknown && llvm::is_contained(AllExts, Name)) {
- return createStringError(errc::invalid_argument, "duplicated %s '%s'",
- Desc.str().c_str(), Name.str().c_str());
- }
+ if (!IgnoreUnknown && llvm::is_contained(AllExts, Name))
+ return createStringError(errc::invalid_argument,
+ "duplicated " + Desc + " '" + Name + "'");
if (IgnoreUnknown && !isSupportedExtension(Name))
continue;
@@ -941,8 +936,8 @@ RISCVISAInfo::parseArchString(StringRef Arch, bool EnableExperimentalExtension,
for (auto Ext : AllExts) {
if (!isSupportedExtension(Ext)) {
StringRef Desc = getExtensionTypeDesc(getExtensionType(Ext));
- return createStringError(errc::invalid_argument, "unsupported %s '%s'",
- Desc.str().c_str(), Ext.str().c_str());
+ return createStringError(errc::invalid_argument,
+ "unsupported " + Desc + " '" + Ext + "'");
}
}
More information about the llvm-commits
mailing list