Skip to content

[Tooling] -fsyntax-only adjuster: remove -c and -S #101103

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

Merged

Conversation

MaskRay
Copy link
Member

@MaskRay MaskRay commented Jul 30, 2024

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

Created using spr 1.3.5-bogner
@llvmbot llvmbot added the clang Clang issues not falling into any other category label Jul 30, 2024
@MaskRay MaskRay requested a review from kazutakahirata July 30, 2024 00:02
@llvmbot
Copy link
Member

llvmbot commented Jul 30, 2024

@llvm/pr-subscribers-clang

Author: Fangrui Song (MaskRay)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/101103.diff

2 Files Affected:

  • (modified) clang/lib/Tooling/ArgumentsAdjusters.cpp (+3-2)
  • (modified) clang/test/Tooling/clang-check-extra-arg.cpp (+3-1)
diff --git a/clang/lib/Tooling/ArgumentsAdjusters.cpp b/clang/lib/Tooling/ArgumentsAdjusters.cpp
index df4c74205b087..d01c57ee69c00 100644
--- a/clang/lib/Tooling/ArgumentsAdjusters.cpp
+++ b/clang/lib/Tooling/ArgumentsAdjusters.cpp
@@ -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")
diff --git a/clang/test/Tooling/clang-check-extra-arg.cpp b/clang/test/Tooling/clang-check-extra-arg.cpp
index df5fb930eedcd..488497edd4e81 100644
--- a/clang/test/Tooling/clang-check-extra-arg.cpp
+++ b/clang/test/Tooling/clang-check-extra-arg.cpp
@@ -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'

Copy link
Contributor

@chestnykh chestnykh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@MaskRay MaskRay merged commit d69d981 into main Jul 30, 2024
9 checks passed
@MaskRay MaskRay deleted the users/MaskRay/spr/tooling-fsyntax-only-adjuster-remove-c-and-s branch July 30, 2024 17:13
bherrera pushed a commit to misttech/mist-os that referenced this pull request Sep 8, 2024
…uppress warnings from -Wunused-command-line-argument

After llvm/llvm-project#101103, clang will no
longer accept mixing `-S` and `-c`. An upstream discussion on shows that
this was intentional, and is unlikely to be reverted:
llvm/llvm-project#104347. It also does not
appear to be possible to remove the `-c` option from the compiler
command. As a compromise, we opt out of the option warning so that
-Werror will continue to work.

Original-Fixed: 359934302
Original-Bug: 360223478
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/Vulkan-Loader/+/1101677
Original-Revision: 710b06e7ff8e672b7359489fe4906f705c2761d4
GitOrigin-RevId: fbf6944d66d8a02abda9b9be33273474892cf8ca
Roller-URL: https://ci.chromium.org/b/8737682620244722209
CQ-Do-Not-Cancel-Tryjobs: true
Change-Id: Id30dc4ede3d83fecd4d6407cd4927f9520231030
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1113304
bherrera pushed a commit to misttech/integration that referenced this pull request Sep 8, 2024
…warnings from -Wunused-command-line-argument

After llvm/llvm-project#101103, clang will no
longer accept mixing `-S` and `-c`. An upstream discussion on shows that
this was intentional, and is unlikely to be reverted:
llvm/llvm-project#104347. It also does not
appear to be possible to remove the `-c` option from the compiler
command. As a compromise, we opt out of the option warning so that
-Werror will continue to work.

Original-Fixed: 359934302
Original-Bug: 360223478
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/Vulkan-Loader/+/1101677
Original-Revision: 710b06e7ff8e672b7359489fe4906f705c2761d4
GitOrigin-RevId: fbf6944d66d8a02abda9b9be33273474892cf8ca
Change-Id: Ib5b0e17ccf55c9746f6b9b126a93bbfbe8ab0f65
bherrera pushed a commit to misttech/integration that referenced this pull request Sep 8, 2024
…ang][VulkanLoader] Suppress warnings from -Wunused-command-line-argument

After llvm/llvm-project#101103, clang will no
longer accept mixing `-S` and `-c`. An upstream discussion on shows that
this was intentional, and is unlikely to be reverted:
llvm/llvm-project#104347. It also does not
appear to be possible to remove the `-c` option from the compiler
command. As a compromise, we opt out of the option warning so that
-Werror will continue to work.

Original-Fixed: 359934302
Original-Bug: 360223478
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/third_party/Vulkan-Loader/+/1101677
Original-Revision: 710b06e7ff8e672b7359489fe4906f705c2761d4
GitOrigin-RevId: 33e2ce9b6ea925b58f20b89d10d8f3ef8a838e0d
Original-Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1113304
Original-Revision: 8ec9fa67ddc9f24e3d859725e46833f871e58a34
Change-Id: I73cb9e794d9c8ae6227ca592679a816b1189961b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[clang-tidy 20] warning: argument unused during compilation: '-c' when using compilation database
3 participants