-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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
[LinkerWrapper][NFC] Simplify StringErrors #96650
Conversation
Summary: The StringError class has a specialized method that creates the inconvertible error code for you. It's much easier to read this way.
@llvm/pr-subscribers-clang Author: Joseph Huber (jhuber6) ChangesSummary: Full diff: https://github.com/llvm/llvm-project/pull/96650.diff 1 Files Affected:
diff --git a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
index cdfe8cfbd9379..9027076119cf9 100644
--- a/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
+++ b/clang/tools/clang-linker-wrapper/ClangLinkerWrapper.cpp
@@ -224,9 +224,8 @@ Error executeCommands(StringRef ExecutablePath, ArrayRef<StringRef> Args) {
if (!DryRun)
if (sys::ExecuteAndWait(ExecutablePath, Args))
- return createStringError(inconvertibleErrorCode(),
- "'" + sys::path::filename(ExecutablePath) + "'" +
- " failed");
+ return createStringError(
+ "'%s' failed", sys::path::filename(ExecutablePath).str().c_str());
return Error::success();
}
@@ -259,7 +258,6 @@ Error relocateOffloadSection(const ArgList &Args, StringRef Output) {
Args.getLastArgValue(OPT_host_triple_EQ, sys::getDefaultTargetTriple()));
if (Triple.isOSWindows())
return createStringError(
- inconvertibleErrorCode(),
"Relocatable linking is not supported on COFF targets");
Expected<std::string> ObjcopyPath =
@@ -272,8 +270,7 @@ Error relocateOffloadSection(const ArgList &Args, StringRef Output) {
auto BufferOrErr = DryRun ? MemoryBuffer::getMemBuffer("")
: MemoryBuffer::getFileOrSTDIN(Output);
if (!BufferOrErr)
- return createStringError(inconvertibleErrorCode(), "Failed to open %s",
- Output.str().c_str());
+ return createStringError("Failed to open %s", Output.str().c_str());
std::string Suffix = "_" + getHash((*BufferOrErr)->getBuffer());
SmallVector<StringRef> ObjcopyArgs = {
@@ -492,8 +489,7 @@ Expected<StringRef> clang(ArrayRef<StringRef> InputFiles, const ArgList &Args) {
file_magic Magic;
if (auto EC = identify_magic(Arg->getValue(), Magic))
- return createStringError(inconvertibleErrorCode(),
- "Failed to open %s", Arg->getValue());
+ return createStringError("Failed to open %s", Arg->getValue());
if (Magic != file_magic::archive &&
Magic != file_magic::elf_shared_object)
continue;
@@ -568,9 +564,8 @@ Expected<StringRef> linkDevice(ArrayRef<StringRef> InputFiles,
case Triple::systemz:
return generic::clang(InputFiles, Args);
default:
- return createStringError(inconvertibleErrorCode(),
- Triple.getArchName() +
- " linking is not supported");
+ return createStringError(Triple.getArchName() +
+ " linking is not supported");
}
}
@@ -881,15 +876,13 @@ Error linkBitcodeFiles(SmallVectorImpl<OffloadFile> &InputFiles,
return Err;
if (LTOError)
- return createStringError(inconvertibleErrorCode(),
- "Errors encountered inside the LTO pipeline.");
+ return createStringError("Errors encountered inside the LTO pipeline.");
// If we are embedding bitcode we only need the intermediate output.
bool SingleOutput = Files.size() == 1;
if (Args.hasArg(OPT_embed_bitcode)) {
if (BitcodeOutput.size() != 1 || !SingleOutput)
- return createStringError(inconvertibleErrorCode(),
- "Cannot embed bitcode with multiple files.");
+ return createStringError("Cannot embed bitcode with multiple files.");
OutputFiles.push_back(Args.MakeArgString(BitcodeOutput.front()));
return Error::success();
}
@@ -936,7 +929,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
std::string Msg;
const Target *T = TargetRegistry::lookupTarget(M.getTargetTriple(), Msg);
if (!T)
- return createStringError(inconvertibleErrorCode(), Msg);
+ return createStringError(Msg);
auto Options =
codegen::InitTargetOptionsFromCodeGenFlags(Triple(M.getTargetTriple()));
@@ -966,8 +959,7 @@ Expected<StringRef> compileModule(Module &M, OffloadKind Kind) {
CodeGenPasses.add(new TargetLibraryInfoWrapperPass(TLII));
if (TM->addPassesToEmitFile(CodeGenPasses, *OS, nullptr,
CodeGenFileType::ObjectFile))
- return createStringError(inconvertibleErrorCode(),
- "Failed to execute host backend");
+ return createStringError("Failed to execute host backend");
CodeGenPasses.run(M);
return *TempFileOrErr;
@@ -1012,9 +1004,8 @@ wrapDeviceImages(ArrayRef<std::unique_ptr<MemoryBuffer>> Buffers,
return std::move(Err);
break;
default:
- return createStringError(inconvertibleErrorCode(),
- getOffloadKindName(Kind) +
- " wrapping is not supported");
+ return createStringError(getOffloadKindName(Kind) +
+ " wrapping is not supported");
}
if (Args.hasArg(OPT_print_wrapped_module))
@@ -1109,9 +1100,8 @@ bundleLinkedOutput(ArrayRef<OffloadingImage> Images, const ArgList &Args,
case OFK_HIP:
return bundleHIP(Images, Args);
default:
- return createStringError(inconvertibleErrorCode(),
- getOffloadKindName(Kind) +
- " bundling is not supported");
+ return createStringError(getOffloadKindName(Kind) +
+ " bundling is not supported");
}
}
@@ -1209,7 +1199,7 @@ Expected<SmallVector<StringRef>> linkAndWrapDeviceFiles(
StringSaver Saver(Alloc);
auto BaseArgs =
Tbl.parseArgs(Argc, Argv, OPT_INVALID, Saver, [](StringRef Err) {
- reportError(createStringError(inconvertibleErrorCode(), Err));
+ reportError(createStringError(Err));
});
auto LinkerArgs = getLinkerArgs(Input, BaseArgs);
@@ -1510,9 +1500,8 @@ getDeviceInput(const ArgList &Args) {
: std::string(Arg->getValue());
if (!Filename && Arg->getOption().matches(OPT_library))
- reportError(createStringError(inconvertibleErrorCode(),
- "unable to find library -l%s",
- Arg->getValue()));
+ reportError(
+ createStringError("unable to find library -l%s", Arg->getValue()));
if (!Filename || !sys::fs::exists(*Filename) ||
sys::fs::is_directory(*Filename))
@@ -1646,7 +1635,7 @@ int main(int Argc, char **Argv) {
BumpPtrAllocator Alloc;
StringSaver Saver(Alloc);
auto Args = Tbl.parseArgs(Argc, Argv, OPT_INVALID, Saver, [&](StringRef Err) {
- reportError(createStringError(inconvertibleErrorCode(), Err));
+ reportError(createStringError(Err));
});
if (Args.hasArg(OPT_help) || Args.hasArg(OPT_help_hidden)) {
@@ -1691,9 +1680,9 @@ int main(int Argc, char **Argv) {
if (auto *Arg = Args.getLastArg(OPT_wrapper_jobs)) {
unsigned Threads = 0;
if (!llvm::to_integer(Arg->getValue(), Threads) || Threads == 0)
- reportError(createStringError(
- inconvertibleErrorCode(), "%s: expected a positive integer, got '%s'",
- Arg->getSpelling().data(), Arg->getValue()));
+ reportError(createStringError("%s: expected a positive integer, got '%s'",
+ Arg->getSpelling().data(),
+ Arg->getValue()));
parallel::strategy = hardware_concurrency(Threads);
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG and good to know we have format support :-)
Summary: The StringError class has a specialized method that creates the inconvertible error code for you. It's much easier to read this way.
Summary:
The StringError class has a specialized method that creates the
inconvertible error code for you. It's much easier to read this way.