https://github.com/chestnykh created https://github.com/llvm/llvm-project/pull/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 >From ae43fc67b7d9db848ec8c4ecbcab1db6af7fcb01 Mon Sep 17 00:00:00 2001 From: Dmitry Chestnykh <dm.chestn...@gmail.com> Date: Fri, 12 Jul 2024 12:25:16 +0300 Subject: [PATCH] [Clang][Driver] Warn about `-c/-S` with `-fsyntax-only` 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 --- clang/lib/Driver/ToolChains/Clang.cpp | 4 ---- clang/test/Driver/warn-fsyntax-only-c-S.c | 9 +++++++++ 2 files changed, 9 insertions(+), 4 deletions(-) create mode 100644 clang/test/Driver/warn-fsyntax-only-c-S.c 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] _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits