https://github.com/frobtech updated https://github.com/llvm/llvm-project/pull/118416
>From 5a039fa6003a7612ddc6603192a121d92d3903cc Mon Sep 17 00:00:00 2001 From: Roland McGrath <mcgra...@google.com> Date: Mon, 2 Dec 2024 13:33:47 -0800 Subject: [PATCH] [Driver][Fuchsia] Avoid "argument unused" warnings There should not be an error or warning reported for using redundant options to control what goes into the link. For example, -nolibc -nostdlib. --- clang/lib/Driver/ToolChains/Fuchsia.cpp | 30 ++++++++++++------------- clang/test/Driver/fuchsia.c | 6 +++++ 2 files changed, 21 insertions(+), 15 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Fuchsia.cpp b/clang/lib/Driver/ToolChains/Fuchsia.cpp index 72accbff4a3bf2..c2badc80a7b452 100644 --- a/clang/lib/Driver/ToolChains/Fuchsia.cpp +++ b/clang/lib/Driver/ToolChains/Fuchsia.cpp @@ -156,6 +156,12 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs); AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA); + // Sample these options first so they are claimed even under -nostdlib et al. + bool NoLibc = Args.hasArg(options::OPT_nolibc); + bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && + !Args.hasArg(options::OPT_static); + bool Pthreads = Args.hasArg(options::OPT_pthread, options::OPT_pthreads); + bool SplitStack = Args.hasArg(options::OPT_fsplit_stack); if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs, options::OPT_r)) { if (Args.hasArg(options::OPT_static)) @@ -163,8 +169,6 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, if (D.CCCIsCXX()) { if (ToolChain.ShouldLinkCXXStdlib(Args)) { - bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) && - !Args.hasArg(options::OPT_static); CmdArgs.push_back("--push-state"); CmdArgs.push_back("--as-needed"); if (OnlyLibstdcxxStatic) @@ -188,14 +192,13 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA, AddRunTimeLibs(ToolChain, D, CmdArgs, Args); - if (Args.hasArg(options::OPT_pthread) || - Args.hasArg(options::OPT_pthreads)) + if (Pthreads) CmdArgs.push_back("-lpthread"); - if (Args.hasArg(options::OPT_fsplit_stack)) + if (SplitStack) CmdArgs.push_back("--wrap=pthread_create"); - if (!Args.hasArg(options::OPT_nolibc)) + if (!NoLibc) CmdArgs.push_back("-lc"); } @@ -229,7 +232,7 @@ void fuchsia::StaticLibTool::ConstructJob(Compilation &C, const JobAction &JA, for (const auto &II : Inputs) { if (II.isFilename()) { - CmdArgs.push_back(II.getFilename()); + CmdArgs.push_back(II.getFilename()); } } @@ -343,16 +346,14 @@ std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args, return Triple.str(); } -Tool *Fuchsia::buildLinker() const { - return new tools::fuchsia::Linker(*this); -} +Tool *Fuchsia::buildLinker() const { return new tools::fuchsia::Linker(*this); } Tool *Fuchsia::buildStaticLibTool() const { return new tools::fuchsia::StaticLibTool(*this); } -ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType( - const ArgList &Args) const { +ToolChain::RuntimeLibType +Fuchsia::GetRuntimeLibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) { StringRef Value = A->getValue(); if (Value != "compiler-rt") @@ -363,13 +364,12 @@ ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType( return ToolChain::RLT_CompilerRT; } -ToolChain::CXXStdlibType -Fuchsia::GetCXXStdlibType(const ArgList &Args) const { +ToolChain::CXXStdlibType Fuchsia::GetCXXStdlibType(const ArgList &Args) const { if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) { StringRef Value = A->getValue(); if (Value != "libc++") getDriver().Diag(diag::err_drv_invalid_stdlib_name) - << A->getAsString(Args); + << A->getAsString(Args); } return ToolChain::CST_Libcxx; diff --git a/clang/test/Driver/fuchsia.c b/clang/test/Driver/fuchsia.c index 83dee16981690a..cf92f85040901c 100644 --- a/clang/test/Driver/fuchsia.c +++ b/clang/test/Driver/fuchsia.c @@ -297,3 +297,9 @@ // RUN: %clang --target=riscv64-unknown-fuchsia -mno-relax -### %s 2>&1 \ // RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s // RISCV64-FLAGS: "-X" "--no-relax" + +// RUN: %clang -### %s --target=x86_64-unknown-fuchsia 2>&1 \ +// RUN: -nostdlib -nolibc \ +// RUN: | FileCheck %s -check-prefix=CHECK-NOSTDLIB-NOLIBC +// CHECK-NOSTDLIB-NOLIBC-NOT: "warning:" +// CHECK-NOSTDLIB-NOLIBC-NOT: "error:" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits