-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
[Clang][Driver] Warn about -c/-S
with -fsyntax-only
#98607
Conversation
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-driver Author: Dmitriy Chestnykh (chestnykh) ChangesEmit warning that Full diff: https://github.com/llvm/llvm-project/pull/98607.diff 2 Files Affected:
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index 4a674f67b8e1b..4440725ccd923 100644
--- a/clang/lib/Driver/ToolChains/Clang.cpp
+++ b/clang/lib/Driver/ToolChains/Clang.cpp
@@ -794,10 +794,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C,
Args.hasArg(options::OPT_coverage))
FProfileDir = Args.getLastArg(options::OPT_fprofile_dir);
- // TODO: Don't claim -c/-S to warn about -fsyntax-only -c/-S, -E -c/-S,
- // like we warn about -fsyntax-only -E.
- (void)(Args.hasArg(options::OPT_c) || Args.hasArg(options::OPT_S));
-
// Put the .gcno and .gcda files (if needed) next to the primary output file,
// or fall back to a file in the current directory for `clang -c --coverage
// d/a.c` in the absence of -o.
diff --git a/clang/test/Driver/warn-fsyntax-only-c-S.c b/clang/test/Driver/warn-fsyntax-only-c-S.c
new file mode 100644
index 0000000000000..bb1cd5fd1183c
--- /dev/null
+++ b/clang/test/Driver/warn-fsyntax-only-c-S.c
@@ -0,0 +1,9 @@
+// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM
+// RUN: %clang -fsyntax-only -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-OBJ
+// RUN: %clang -fsyntax-only -S -c %s 2>&1 | FileCheck %s --check-prefix=CHECK-BOTH
+
+// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
+// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
+
+// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
+// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
|
CC: @shafik @ChuanqiXu9 |
Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function
@@ -794,10 +794,6 @@ static void addPGOAndCoverageFlags(const ToolChain &TC, Compilation &C, | |||
Args.hasArg(options::OPT_coverage)) | |||
FProfileDir = Args.getLastArg(options::OPT_fprofile_dir); | |||
|
|||
// TODO: Don't claim -c/-S to warn about -fsyntax-only -c/-S, -E -c/-S, |
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.
Thanks for catching this. I left this in a07b135 to be cleaned up later but I forgot to remove this TODO.
@@ -0,0 +1,9 @@ | |||
// RUN: %clang -fsyntax-only -S %s 2>&1 | FileCheck %s --check-prefix=CHECK-ASM |
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.
Perhaps just warn-fsyntax-only.c
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.
Renamed
// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] | ||
|
||
// CHECK-BOTH: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument] | ||
// CHECK-NEXT: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument] |
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.
CHECK-NEXT is not used by any FileCheck command
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.
I've added -fsyntax-only -E
case. -c -S
i think is like duplication of -c
and -S
test cases
- Rename to warn-fsyntax-only.c - Add `-fsyntax-only -E` testcase - Remove `-c -S` case because we really don't need it
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/144/builds/2918 Here is the relevant piece of the build log for the reference:
|
LLVM Buildbot has detected a new failure on builder Full details are available at: https://lab.llvm.org/buildbot/#/builders/46/builds/2069 Here is the relevant piece of the build log for the reference:
|
@chestnykh Can you take a look at the bot failures and revert if you need time to investigate so we can get the bots back to green? |
…)" This reverts commit 1efcc53.
…0052) Reverts #98607 The test added was failing on some build bots: - https://lab.llvm.org/buildbot/#/builders/144/builds/2918 - https://lab.llvm.org/buildbot/#/builders/46/builds/2069
Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function
…m#100052) Reverts llvm#98607 The test added was failing on some build bots: - https://lab.llvm.org/buildbot/#/builders/144/builds/2918 - https://lab.llvm.org/buildbot/#/builders/46/builds/2069
FWIW, in addition to That sounds like a reasonable thing to do to me, so it's probably fine, but it'd be nice to have that aspect acknowledged as one intended behaviour change as well. |
A command like "cc -c -E" is tautological; the -c is ignored, when we explicitly specify that we want to preprocess only. Since llvm/llvm-project@6461e53 and llvm/llvm-project#98607, Clang now warns about the unused "-c" argument in this case. We already did omit the "-c" argument when preprocessing (with cl.exe) for armasm, but do this for other cases as well.
Summary: Emit warning that `-S` and/or `-c` arguments are not used if `-fsyntax-only` is also passed to clang `addPGOAndCoverageFlags` is not the right place to produce this warning Now `-fsyntax-only -c/-S` combination handles like `-fsyntax-only -E` in `BuildJobs()` driver function Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60251113
…0052) Reverts #98607 The test added was failing on some build bots: - https://lab.llvm.org/buildbot/#/builders/144/builds/2918 - https://lab.llvm.org/buildbot/#/builders/46/builds/2069
Summary: Remove the TODO I left in commit a07b135. We will now warn about `-c/-S` with `-fsyntax-only`. This relands #98607 with a specific target triple. Test Plan: Reviewers: Subscribers: Tasks: Tags: Differential Revision: https://phabricator.intern.facebook.com/D60250579
Thanks for pointing this out. Yes, the warning for |
A command like "cc -c -E" is tautological; the -c is ignored, when we explicitly specify that we want to preprocess only. Since llvm/llvm-project@6461e53 and llvm/llvm-project#98607, Clang now warns about the unused "-c" argument in this case. We already did omit the "-c" argument when preprocessing (with cl.exe) for armasm, but do this for other cases as well.
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
Remove the TODO I left in commit a07b135. We will now warn about `-c/-S` with `-fsyntax-only`. This relands llvm#98607 with a specific target triple.
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 (llvm#98607). (clangDriver reports a -Wunused-command-line-argument diagnostic for each unclaimed option.) Fix llvm#100909 Pull Request: llvm#101103
Emit warning that
-S
and/or-c
arguments are not used if-fsyntax-only
is also passed to clangaddPGOAndCoverageFlags
is not the right placeto produce this warning
Now
-fsyntax-only -c/-S
combination handles like-fsyntax-only -E
inBuildJobs()
driver function