Skip to content

Commit 09f4c26

Browse files
authored
[Driver][Fuchsia] Avoid "argument unused" warnings (#118416)
There should not be an error or warning reported for using redundant options to control what goes into the link. For example, -nolibc -nostdlib.
1 parent 758107f commit 09f4c26

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

clang/lib/Driver/ToolChains/Fuchsia.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -156,15 +156,19 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
156156
addLinkerCompressDebugSectionsOption(ToolChain, Args, CmdArgs);
157157
AddLinkerInputs(ToolChain, Inputs, Args, CmdArgs, JA);
158158

159+
// Sample these options first so they are claimed even under -nostdlib et al.
160+
bool NoLibc = Args.hasArg(options::OPT_nolibc);
161+
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
162+
!Args.hasArg(options::OPT_static);
163+
bool Pthreads = Args.hasArg(options::OPT_pthread, options::OPT_pthreads);
164+
bool SplitStack = Args.hasArg(options::OPT_fsplit_stack);
159165
if (!Args.hasArg(options::OPT_nostdlib, options::OPT_nodefaultlibs,
160166
options::OPT_r)) {
161167
if (Args.hasArg(options::OPT_static))
162168
CmdArgs.push_back("-Bdynamic");
163169

164170
if (D.CCCIsCXX()) {
165171
if (ToolChain.ShouldLinkCXXStdlib(Args)) {
166-
bool OnlyLibstdcxxStatic = Args.hasArg(options::OPT_static_libstdcxx) &&
167-
!Args.hasArg(options::OPT_static);
168172
CmdArgs.push_back("--push-state");
169173
CmdArgs.push_back("--as-needed");
170174
if (OnlyLibstdcxxStatic)
@@ -188,14 +192,13 @@ void fuchsia::Linker::ConstructJob(Compilation &C, const JobAction &JA,
188192

189193
AddRunTimeLibs(ToolChain, D, CmdArgs, Args);
190194

191-
if (Args.hasArg(options::OPT_pthread) ||
192-
Args.hasArg(options::OPT_pthreads))
195+
if (Pthreads)
193196
CmdArgs.push_back("-lpthread");
194197

195-
if (Args.hasArg(options::OPT_fsplit_stack))
198+
if (SplitStack)
196199
CmdArgs.push_back("--wrap=pthread_create");
197200

198-
if (!Args.hasArg(options::OPT_nolibc))
201+
if (!NoLibc)
199202
CmdArgs.push_back("-lc");
200203
}
201204

@@ -229,7 +232,7 @@ void fuchsia::StaticLibTool::ConstructJob(Compilation &C, const JobAction &JA,
229232

230233
for (const auto &II : Inputs) {
231234
if (II.isFilename()) {
232-
CmdArgs.push_back(II.getFilename());
235+
CmdArgs.push_back(II.getFilename());
233236
}
234237
}
235238

@@ -343,16 +346,14 @@ std::string Fuchsia::ComputeEffectiveClangTriple(const ArgList &Args,
343346
return Triple.str();
344347
}
345348

346-
Tool *Fuchsia::buildLinker() const {
347-
return new tools::fuchsia::Linker(*this);
348-
}
349+
Tool *Fuchsia::buildLinker() const { return new tools::fuchsia::Linker(*this); }
349350

350351
Tool *Fuchsia::buildStaticLibTool() const {
351352
return new tools::fuchsia::StaticLibTool(*this);
352353
}
353354

354-
ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType(
355-
const ArgList &Args) const {
355+
ToolChain::RuntimeLibType
356+
Fuchsia::GetRuntimeLibType(const ArgList &Args) const {
356357
if (Arg *A = Args.getLastArg(clang::driver::options::OPT_rtlib_EQ)) {
357358
StringRef Value = A->getValue();
358359
if (Value != "compiler-rt")
@@ -363,13 +364,12 @@ ToolChain::RuntimeLibType Fuchsia::GetRuntimeLibType(
363364
return ToolChain::RLT_CompilerRT;
364365
}
365366

366-
ToolChain::CXXStdlibType
367-
Fuchsia::GetCXXStdlibType(const ArgList &Args) const {
367+
ToolChain::CXXStdlibType Fuchsia::GetCXXStdlibType(const ArgList &Args) const {
368368
if (Arg *A = Args.getLastArg(options::OPT_stdlib_EQ)) {
369369
StringRef Value = A->getValue();
370370
if (Value != "libc++")
371371
getDriver().Diag(diag::err_drv_invalid_stdlib_name)
372-
<< A->getAsString(Args);
372+
<< A->getAsString(Args);
373373
}
374374

375375
return ToolChain::CST_Libcxx;

clang/test/Driver/fuchsia.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,3 +297,9 @@
297297
// RUN: %clang --target=riscv64-unknown-fuchsia -mno-relax -### %s 2>&1 \
298298
// RUN: | FileCheck -check-prefix=RISCV64-FLAGS %s
299299
// RISCV64-FLAGS: "-X" "--no-relax"
300+
301+
// RUN: %clang -### %s --target=x86_64-unknown-fuchsia 2>&1 \
302+
// RUN: -nostdlib -nolibc \
303+
// RUN: | FileCheck %s -check-prefix=CHECK-NOSTDLIB-NOLIBC
304+
// CHECK-NOSTDLIB-NOLIBC-NOT: "warning:"
305+
// CHECK-NOSTDLIB-NOLIBC-NOT: "error:"

0 commit comments

Comments
 (0)