-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[Driver][Fuchsia] Avoid "argument unused" warnings #118416
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
Conversation
There should not be an error or warning reported for using redundant options to control what goes into the link. For example, -nolibc -nostdlib.
@llvm/pr-subscribers-clang Author: Roland McGrath (frobtech) ChangesThere should not be an error or warning reported for using Full diff: https://github.com/llvm/llvm-project/pull/118416.diff 2 Files Affected:
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:"
|
@llvm/pr-subscribers-clang-driver Author: Roland McGrath (frobtech) ChangesThere should not be an error or warning reported for using Full diff: https://github.com/llvm/llvm-project/pull/118416.diff 2 Files Affected:
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:"
|
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.
LGTM.
There should not be an error or warning reported for using
redundant options to control what goes into the link. For
example, -nolibc -nostdlib.