Skip to content

Commit

Permalink
[Tooling] -fsyntax-only adjuster: remove -c and -S
Browse files Browse the repository at this point in the history
compile_commands.json entries often have -c. When adding -fsyntax-only,
we should remove -c to prevent the following warning:

```
% clang -c -fsyntax-only a.c
clang: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
```

Previously, -c and -S were inappropriately claimed in
`addPGOAndCoverageFlags` (see the workaround added by commit
a07b135). Now the workaround have been
removed (#98607). (clangDriver reports a -Wunused-command-line-argument
diagnostic for each unclaimed option.)

Fix #100909

Pull Request: #101103
  • Loading branch information
MaskRay authored Jul 30, 2024
1 parent c95abe9 commit d69d981
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
5 changes: 3 additions & 2 deletions clang/lib/Tooling/ArgumentsAdjusters.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,11 @@ ArgumentsAdjuster getClangSyntaxOnlyAdjuster() {
}))
continue;

if (!Arg.starts_with("-fcolor-diagnostics") &&
if (Arg != "-c" && Arg != "-S" &&
!Arg.starts_with("-fcolor-diagnostics") &&
!Arg.starts_with("-fdiagnostics-color"))
AdjustedArgs.push_back(Args[i]);
// If we strip a color option, make sure we strip any preceeding `-Xclang`
// If we strip an option, make sure we strip any preceeding `-Xclang`
// option as well.
// FIXME: This should be added to most argument adjusters!
else if (!AdjustedArgs.empty() && AdjustedArgs.back() == "-Xclang")
Expand Down
4 changes: 3 additions & 1 deletion clang/test/Tooling/clang-check-extra-arg.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// RUN: clang-check "%s" -extra-arg=-Wunimplemented-warning -extra-arg-before=-Wunimplemented-warning-before -- -c 2>&1 | FileCheck %s
/// Check we do not report "argument unused during compilation: '-c'"
// RUN: clang-check "%s" -extra-arg=-Wunimplemented-warning -extra-arg-before=-Wunimplemented-warning-before -- -c 2>&1 | FileCheck %s --implicit-check-not='argument unused'
// RUN: clang-check "%s" -extra-arg=-Wunimplemented-warning -extra-arg-before=-Wunimplemented-warning-before -- -S -Xclang -S 2>&1 | FileCheck %s --implicit-check-not='argument unused'

// CHECK: unknown warning option '-Wunimplemented-warning-before'
// CHECK: unknown warning option '-Wunimplemented-warning'
Expand Down

0 comments on commit d69d981

Please sign in to comment.