[clang] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` (PR #98607)

via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 12 02:37:24 PDT 2024


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang

@llvm/pr-subscribers-clang-driver

Author: Dmitriy Chestnykh (chestnykh)

<details>
<summary>Changes</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

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


2 Files Affected:

- (modified) clang/lib/Driver/ToolChains/Clang.cpp (-4) 
- (added) clang/test/Driver/warn-fsyntax-only-c-S.c (+9) 


``````````diff
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]

``````````

</details>


https://github.com/llvm/llvm-project/pull/98607


More information about the cfe-commits mailing list