[clang] 1efcc53 - [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (#98607)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 22 15:15:57 PDT 2024
Author: Dmitry Chestnykh
Date: 2024-07-23T01:15:53+03:00
New Revision: 1efcc532bab505db079bd3becffe32f742287c71
URL: https://github.com/llvm/llvm-project/commit/1efcc532bab505db079bd3becffe32f742287c71
DIFF: https://github.com/llvm/llvm-project/commit/1efcc532bab505db079bd3becffe32f742287c71.diff
LOG: [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (#98607)
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
Added:
clang/test/Driver/warn-fsyntax-only.c
Modified:
clang/lib/Driver/ToolChains/Clang.cpp
Removed:
################################################################################
diff --git a/clang/lib/Driver/ToolChains/Clang.cpp b/clang/lib/Driver/ToolChains/Clang.cpp
index f240a47504ef6..f881fe8c395f8 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 b/clang/test/Driver/warn-fsyntax-only.c
new file mode 100644
index 0000000000000..b4cf74fc59855
--- /dev/null
+++ b/clang/test/Driver/warn-fsyntax-only.c
@@ -0,0 +1,7 @@
+// RUN: %clang -fsyntax-only -E %s 2>&1 | FileCheck %s --check-prefix=CHECK-PP
+// 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
+
+// CHECK-PP: warning: argument unused during compilation: '-fsyntax-only' [-Wunused-command-line-argument]
+// CHECK-ASM: warning: argument unused during compilation: '-S' [-Wunused-command-line-argument]
+// CHECK-OBJ: warning: argument unused during compilation: '-c' [-Wunused-command-line-argument]
More information about the cfe-commits
mailing list