https://github.com/felix642 updated 
https://github.com/llvm/llvm-project/pull/164344

From 0e58783439b4121aa2829e1d5c5974a4eea92df1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Mon, 7 Oct 2024 19:22:44 -0400
Subject: [PATCH 1/6] [clang-tidy] New option to remove arguments from the
 command line

When using clang-tidy from a compilation database, some options might not be
recognized by clang if the compilation database was generated for another 
compiler.
This forces the user to add conditional code in their CMakeLists.txt to remove
those arguments when using clang-tidy.
A new option was added to the .clang-tidy config to remove
those unknown flags without the need to generate a second 
compilation_commands.json

Fixes #108455
---
 clang-tools-extra/clang-tidy/ClangTidy.cpp    | 24 +++++++++++++++++++
 .../clang-tidy/ClangTidyOptions.cpp           |  5 ++++
 .../clang-tidy/ClangTidyOptions.h             |  4 ++++
 clang-tools-extra/docs/ReleaseNotes.rst       |  4 ++++
 clang-tools-extra/docs/clang-tidy/index.rst   |  3 +++
 .../compilation-args-to-ignore.cpp            |  9 +++++++
 6 files changed, 49 insertions(+)
 create mode 100644 
clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 7e18f3806a143..dda34fa190b3b 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -581,6 +581,30 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
         return AdjustedArgs;
       };
 
+  // Remove unwanted arguments passed to the compiler
+  ArgumentsAdjuster CompilationArgsToIgnore =
+      [&Context](const CommandLineArguments &Args, StringRef Filename) {
+        ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
+        CommandLineArguments AdjustedArgs = Args;
+
+        if (Opts.CompilationArgsToRemoveRegex) {
+          for (StringRef ArgToIgnore : *Opts.CompilationArgsToRemoveRegex) {
+            llvm::Regex ArgToIgnoreRegex(ArgToIgnore);
+            AdjustedArgs.erase(
+                std::remove_if(AdjustedArgs.begin(), AdjustedArgs.end(),
+                               [&](llvm::StringRef Arg) {
+                                 return Arg.starts_with("-") &&
+                                        Arg != "-fsyntax-only" &&
+                                        ArgToIgnoreRegex.match(Arg);
+                               }),
+                AdjustedArgs.end());
+          }
+        }
+
+        return AdjustedArgs;
+      };
+
+  Tool.appendArgumentsAdjuster(CompilationArgsToIgnore);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
   Context.setEnableProfiling(EnableCheckProfile);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index 21455db7c7e7b..ac274570652f4 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -227,6 +227,8 @@ template <> struct MappingTraits<ClangTidyOptions> {
                    Options.ExcludeHeaderFilterRegex);
     IO.mapOptional("FormatStyle", Options.FormatStyle);
     IO.mapOptional("User", Options.User);
+    IO.mapOptional("CompilationArgsToRemoveRegex",
+                   Options.CompilationArgsToRemoveRegex);
     IO.mapOptional("CheckOptions", Options.CheckOptions);
     IO.mapOptional("ExtraArgs", Options.ExtraArgs);
     IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
@@ -252,6 +254,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   Options.SystemHeaders = false;
   Options.FormatStyle = "none";
   Options.User = std::nullopt;
+  Options.CompilationArgsToRemoveRegex = std::nullopt;
   for (const ClangTidyModuleRegistry::entry &Module :
        ClangTidyModuleRegistry::entries())
     Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
@@ -292,6 +295,8 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const 
ClangTidyOptions &Other,
   overrideValue(SystemHeaders, Other.SystemHeaders);
   overrideValue(FormatStyle, Other.FormatStyle);
   overrideValue(User, Other.User);
+  overrideValue(CompilationArgsToRemoveRegex,
+                Other.CompilationArgsToRemoveRegex);
   overrideValue(UseColor, Other.UseColor);
   mergeVectors(ExtraArgs, Other.ExtraArgs);
   mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 2aae92f1d9eb3..e1a52d8d74aa9 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -112,6 +112,10 @@ struct ClangTidyOptions {
   /// comments in the relevant check.
   std::optional<std::string> User;
 
+  /// \brief Remove command line arguments sent to the compiler matching this
+  /// regex.
+  std::optional<std::vector<std::string>> CompilationArgsToRemoveRegex;
+
   /// Helper structure for storing option value with priority of the value.
   struct ClangTidyValue {
     ClangTidyValue() = default;
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 8a0151f567c24..22ad14c8711b4 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,10 +167,14 @@ Improvements to clang-tidy
   scripts by adding the `-hide-progress` option to suppress progress and
   informational messages.
 
+- Improved :program:`clang-tidy` by adding the option `RemovedArgs`
+  to remove arguments sent to the compiler when invoking clang-tidy.
+
 - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
   moved to the ``fuchsia`` module instead. The ``zircon`` module will be 
removed
   in the 24th release.
 
+
 New checks
 ^^^^^^^^^^
 
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index bd2c40e948f34..4f3ccb4fc5dc8 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -329,6 +329,8 @@ An overview of all the command-line options:
                                    example, to place the correct user name in
                                    TODO() comments in the relevant check.
     WarningsAsErrors             - Same as '--warnings-as-errors'.
+    CompilationArgsToRemoveRegex - List of arguments to remove from the command
+                                   line sent to the compiler.
 
     The effective configuration can be inspected using --dump-config:
 
@@ -338,6 +340,7 @@ An overview of all the command-line options:
       WarningsAsErrors:    ''
       HeaderFileExtensions:         ['', 'h','hh','hpp','hxx']
       ImplementationFileExtensions: ['c','cc','cpp','cxx']
+      CompilationArgsToRemoveRegex: ['-Werror', '-f.*']
       HeaderFilterRegex:   ''
       FormatStyle:         none
       InheritParentConfig: true
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
 
b/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
new file mode 100644
index 0000000000000..33a42d416e75a
--- /dev/null
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
@@ -0,0 +1,9 @@
+// RUN: not clang-tidy %s -- -fnot-an-option | FileCheck %s 
-check-prefix=INVALID-A
+// RUN: clang-tidy %s --config="{CompilationArgsToRemoveRegex: 
['-fnot-an-option']}" -- -fnot-an-option
+// RUN: not clang-tidy %s --config="{CompilationArgsToRemoveRegex: ['-f.*']}" 
-- -fnot-an-option -invalid-option | FileCheck %s -check-prefix=INVALID-B
+// RUN: clang-tidy %s --config="{CompilationArgsToRemoveRegex: ['-f.*', 
'-invalid-option']}" -- -fnot-an-option -fnot-another-option -finvalid-option 
-invalid-option
+// RUN: not clang-tidy %s --config="{CompilationArgsToRemoveRegex: 
['\$invalid-option']}" -- -finvalid-option | FileCheck %s 
-check-prefix=INVALID-C
+
+// INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
+// INVALID-B: error: unknown argument: '-invalid-option' 
[clang-diagnostic-error]
+// INVALID-C: error: unknown argument: '-finvalid-option' 
[clang-diagnostic-error]
\ No newline at end of file

From d9a64e6ea9b9998c748ce797ff0c7d4f2d723bc9 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Sat, 2 Nov 2024 12:16:34 -0400
Subject: [PATCH 2/6] fixup! [clang-tidy] New option to remove arguments from
 the command line

Improved Release Notes
---
 clang-tools-extra/docs/ReleaseNotes.rst | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 22ad14c8711b4..bc986f916bf6b 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -132,7 +132,12 @@ Improvements to clang-tidy
   when run over C files. If ``-std`` is not specified, it defaults to
   ``c99-or-later``.
 
+<<<<<<< HEAD
 - :program:`clang-tidy` no longer attempts to analyze code from system headers
+=======
+<<<<<<< HEAD
+- :program:`clang-tidy` no longer attemps to analyze code from system headers
+>>>>>>> 64f91e7543e8 (fixup! [clang-tidy] New option to remove arguments from 
the command line)
   by default, greatly improving performance. This behavior is disabled if the
   `SystemHeaders` option is enabled.
 
@@ -167,8 +172,9 @@ Improvements to clang-tidy
   scripts by adding the `-hide-progress` option to suppress progress and
   informational messages.
 
-- Improved :program:`clang-tidy` by adding the option `RemovedArgs`
-  to remove arguments sent to the compiler when invoking clang-tidy.
+- Improved :program:`clang-tidy` by adding the option 
+  :option:`RemovedArgs` to remove arguments sent to the 
+  compiler when invoking clang-tidy.
 
 - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
   moved to the ``fuchsia`` module instead. The ``zircon`` module will be 
removed

From f2c15c6402a0256fa06bfe81babc1b52a83b6f41 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Mon, 20 Oct 2025 19:43:19 -0400
Subject: [PATCH 3/6] fixup! [clang-tidy] New option to remove arguments from
 the command line

Removed Regex Support
---
 clang-tools-extra/clang-tidy/ClangTidy.cpp    | 20 +++++++------------
 .../clang-tidy/ClangTidyOptions.cpp           |  8 +++-----
 .../clang-tidy/ClangTidyOptions.h             |  2 +-
 clang-tools-extra/docs/ReleaseNotes.rst       |  5 -----
 clang-tools-extra/docs/clang-tidy/index.rst   |  8 +++++---
 .../compilation-args-to-ignore.cpp            | 10 +++-------
 6 files changed, 19 insertions(+), 34 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index dda34fa190b3b..6e91e0a254c0f 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -582,29 +582,23 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
       };
 
   // Remove unwanted arguments passed to the compiler
-  ArgumentsAdjuster CompilationArgsToIgnore =
+  ArgumentsAdjuster CompilationArgsToRemove =
       [&Context](const CommandLineArguments &Args, StringRef Filename) {
         ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
         CommandLineArguments AdjustedArgs = Args;
 
-        if (Opts.CompilationArgsToRemoveRegex) {
-          for (StringRef ArgToIgnore : *Opts.CompilationArgsToRemoveRegex) {
-            llvm::Regex ArgToIgnoreRegex(ArgToIgnore);
-            AdjustedArgs.erase(
-                std::remove_if(AdjustedArgs.begin(), AdjustedArgs.end(),
-                               [&](llvm::StringRef Arg) {
-                                 return Arg.starts_with("-") &&
-                                        Arg != "-fsyntax-only" &&
-                                        ArgToIgnoreRegex.match(Arg);
-                               }),
-                AdjustedArgs.end());
+        if (Opts.RemovedArgs) {
+          for (StringRef ArgToIgnore : *Opts.RemovedArgs) {
+            AdjustedArgs.erase(std::remove(AdjustedArgs.begin(),
+                                           AdjustedArgs.end(), ArgToIgnore),
+                               AdjustedArgs.end());
           }
         }
 
         return AdjustedArgs;
       };
 
-  Tool.appendArgumentsAdjuster(CompilationArgsToIgnore);
+  Tool.appendArgumentsAdjuster(CompilationArgsToRemove);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
   Context.setEnableProfiling(EnableCheckProfile);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index ac274570652f4..cca32f013b4a1 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -227,8 +227,7 @@ template <> struct MappingTraits<ClangTidyOptions> {
                    Options.ExcludeHeaderFilterRegex);
     IO.mapOptional("FormatStyle", Options.FormatStyle);
     IO.mapOptional("User", Options.User);
-    IO.mapOptional("CompilationArgsToRemoveRegex",
-                   Options.CompilationArgsToRemoveRegex);
+    IO.mapOptional("RemovedArgs", Options.RemovedArgs);
     IO.mapOptional("CheckOptions", Options.CheckOptions);
     IO.mapOptional("ExtraArgs", Options.ExtraArgs);
     IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
@@ -254,7 +253,7 @@ ClangTidyOptions ClangTidyOptions::getDefaults() {
   Options.SystemHeaders = false;
   Options.FormatStyle = "none";
   Options.User = std::nullopt;
-  Options.CompilationArgsToRemoveRegex = std::nullopt;
+  Options.RemovedArgs = std::nullopt;
   for (const ClangTidyModuleRegistry::entry &Module :
        ClangTidyModuleRegistry::entries())
     Options.mergeWith(Module.instantiate()->getModuleOptions(), 0);
@@ -295,8 +294,7 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const 
ClangTidyOptions &Other,
   overrideValue(SystemHeaders, Other.SystemHeaders);
   overrideValue(FormatStyle, Other.FormatStyle);
   overrideValue(User, Other.User);
-  overrideValue(CompilationArgsToRemoveRegex,
-                Other.CompilationArgsToRemoveRegex);
+  mergeVectors(RemovedArgs, Other.RemovedArgs);
   overrideValue(UseColor, Other.UseColor);
   mergeVectors(ExtraArgs, Other.ExtraArgs);
   mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index e1a52d8d74aa9..989b1c651c830 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -114,7 +114,7 @@ struct ClangTidyOptions {
 
   /// \brief Remove command line arguments sent to the compiler matching this
   /// regex.
-  std::optional<std::vector<std::string>> CompilationArgsToRemoveRegex;
+  std::optional<std::vector<std::string>> RemovedArgs;
 
   /// Helper structure for storing option value with priority of the value.
   struct ClangTidyValue {
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index bc986f916bf6b..9d84ec64fe9c7 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -132,12 +132,7 @@ Improvements to clang-tidy
   when run over C files. If ``-std`` is not specified, it defaults to
   ``c99-or-later``.
 
-<<<<<<< HEAD
 - :program:`clang-tidy` no longer attempts to analyze code from system headers
-=======
-<<<<<<< HEAD
-- :program:`clang-tidy` no longer attemps to analyze code from system headers
->>>>>>> 64f91e7543e8 (fixup! [clang-tidy] New option to remove arguments from 
the command line)
   by default, greatly improving performance. This behavior is disabled if the
   `SystemHeaders` option is enabled.
 
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index 4f3ccb4fc5dc8..43142c9121716 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -329,8 +329,10 @@ An overview of all the command-line options:
                                    example, to place the correct user name in
                                    TODO() comments in the relevant check.
     WarningsAsErrors             - Same as '--warnings-as-errors'.
-    CompilationArgsToRemoveRegex - List of arguments to remove from the command
-                                   line sent to the compiler.
+    RemovedArgs                  - List of arguments to remove from the command
+                                   line sent to the compiler. Please note that 
+                                   removing arguments from the command line 
+                                   might lead to false positive or negatives. 
 
     The effective configuration can be inspected using --dump-config:
 
@@ -340,7 +342,7 @@ An overview of all the command-line options:
       WarningsAsErrors:    ''
       HeaderFileExtensions:         ['', 'h','hh','hpp','hxx']
       ImplementationFileExtensions: ['c','cc','cpp','cxx']
-      CompilationArgsToRemoveRegex: ['-Werror', '-f.*']
+      RemovedArgs: ['-Werror']
       HeaderFilterRegex:   ''
       FormatStyle:         none
       InheritParentConfig: true
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
 
b/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
index 33a42d416e75a..9a042dedce3a4 100644
--- 
a/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
+++ 
b/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
@@ -1,9 +1,5 @@
 // RUN: not clang-tidy %s -- -fnot-an-option | FileCheck %s 
-check-prefix=INVALID-A
-// RUN: clang-tidy %s --config="{CompilationArgsToRemoveRegex: 
['-fnot-an-option']}" -- -fnot-an-option
-// RUN: not clang-tidy %s --config="{CompilationArgsToRemoveRegex: ['-f.*']}" 
-- -fnot-an-option -invalid-option | FileCheck %s -check-prefix=INVALID-B
-// RUN: clang-tidy %s --config="{CompilationArgsToRemoveRegex: ['-f.*', 
'-invalid-option']}" -- -fnot-an-option -fnot-another-option -finvalid-option 
-invalid-option
-// RUN: not clang-tidy %s --config="{CompilationArgsToRemoveRegex: 
['\$invalid-option']}" -- -finvalid-option | FileCheck %s 
-check-prefix=INVALID-C
+// RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-an-option']}" -- 
-fnot-an-option
+// RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-another-option', 
'-fnot-an-option']}" -- -fnot-an-option -fnot-another-option
 
-// INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
-// INVALID-B: error: unknown argument: '-invalid-option' 
[clang-diagnostic-error]
-// INVALID-C: error: unknown argument: '-finvalid-option' 
[clang-diagnostic-error]
\ No newline at end of file
+// INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
\ No newline at end of file

From 452eecdd76e67c730a2f3062f680060ac5522ea5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Mon, 20 Oct 2025 20:26:17 -0400
Subject: [PATCH 4/6] fixup! fixup! [clang-tidy] New option to remove arguments
 from the command line

Documentation issues
---
 clang-tools-extra/docs/ReleaseNotes.rst | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 9d84ec64fe9c7..59046b6f4c28e 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,15 +167,13 @@ Improvements to clang-tidy
   scripts by adding the `-hide-progress` option to suppress progress and
   informational messages.
 
-- Improved :program:`clang-tidy` by adding the option 
-  :option:`RemovedArgs` to remove arguments sent to the 
-  compiler when invoking clang-tidy.
+- Improved :program:`clang-tidy` by adding the option `RemovedArgs` to remove
+  arguments sent to the compiler when invoking clang-tidy.
 
 - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
   moved to the ``fuchsia`` module instead. The ``zircon`` module will be 
removed
   in the 24th release.
 
-
 New checks
 ^^^^^^^^^^
 

From 69b7c433f912b080edfaf8e83cd725bb9c7dd477 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Sat, 25 Oct 2025 16:29:35 -0400
Subject: [PATCH 5/6] fixup! fixup! [clang-tidy] New option to remove arguments
 from the command line

Code review
---
 clang-tools-extra/clang-tidy/ClangTidy.cpp          |  8 ++++----
 clang-tools-extra/clang-tidy/ClangTidyOptions.cpp   |  4 ++--
 clang-tools-extra/clang-tidy/ClangTidyOptions.h     |  3 +--
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 13 +++++++++++++
 clang-tools-extra/docs/ReleaseNotes.rst             |  2 +-
 clang-tools-extra/docs/clang-tidy/index.rst         | 10 ++++++----
 .../infrastructure/invalid-command-line.cpp         |  2 +-
 ...pilation-args-to-ignore.cpp => removed-args.cpp} |  4 +++-
 8 files changed, 31 insertions(+), 15 deletions(-)
 rename 
clang-tools-extra/test/clang-tidy/infrastructure/{compilation-args-to-ignore.cpp
 => removed-args.cpp} (60%)

diff --git a/clang-tools-extra/clang-tidy/ClangTidy.cpp 
b/clang-tools-extra/clang-tidy/ClangTidy.cpp
index 6e91e0a254c0f..a0ebaa72ff6fd 100644
--- a/clang-tools-extra/clang-tidy/ClangTidy.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidy.cpp
@@ -582,15 +582,15 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
       };
 
   // Remove unwanted arguments passed to the compiler
-  ArgumentsAdjuster CompilationArgsToRemove =
+  ArgumentsAdjuster PerFileArgumentRemover =
       [&Context](const CommandLineArguments &Args, StringRef Filename) {
         ClangTidyOptions Opts = Context.getOptionsForFile(Filename);
         CommandLineArguments AdjustedArgs = Args;
 
         if (Opts.RemovedArgs) {
-          for (StringRef ArgToIgnore : *Opts.RemovedArgs) {
+          for (StringRef ArgToRemove : *Opts.RemovedArgs) {
             AdjustedArgs.erase(std::remove(AdjustedArgs.begin(),
-                                           AdjustedArgs.end(), ArgToIgnore),
+                                           AdjustedArgs.end(), ArgToRemove),
                                AdjustedArgs.end());
           }
         }
@@ -598,7 +598,7 @@ runClangTidy(clang::tidy::ClangTidyContext &Context,
         return AdjustedArgs;
       };
 
-  Tool.appendArgumentsAdjuster(CompilationArgsToRemove);
+  Tool.appendArgumentsAdjuster(PerFileArgumentRemover);
   Tool.appendArgumentsAdjuster(PerFileExtraArgumentsInserter);
   Tool.appendArgumentsAdjuster(getStripPluginsAdjuster());
   Context.setEnableProfiling(EnableCheckProfile);
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
index cca32f013b4a1..1673134e135ca 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.cpp
@@ -227,10 +227,10 @@ template <> struct MappingTraits<ClangTidyOptions> {
                    Options.ExcludeHeaderFilterRegex);
     IO.mapOptional("FormatStyle", Options.FormatStyle);
     IO.mapOptional("User", Options.User);
-    IO.mapOptional("RemovedArgs", Options.RemovedArgs);
     IO.mapOptional("CheckOptions", Options.CheckOptions);
     IO.mapOptional("ExtraArgs", Options.ExtraArgs);
     IO.mapOptional("ExtraArgsBefore", Options.ExtraArgsBefore);
+    IO.mapOptional("RemovedArgs", Options.RemovedArgs);
     IO.mapOptional("InheritParentConfig", Options.InheritParentConfig);
     IO.mapOptional("UseColor", Options.UseColor);
     IO.mapOptional("SystemHeaders", Options.SystemHeaders);
@@ -294,10 +294,10 @@ ClangTidyOptions &ClangTidyOptions::mergeWith(const 
ClangTidyOptions &Other,
   overrideValue(SystemHeaders, Other.SystemHeaders);
   overrideValue(FormatStyle, Other.FormatStyle);
   overrideValue(User, Other.User);
-  mergeVectors(RemovedArgs, Other.RemovedArgs);
   overrideValue(UseColor, Other.UseColor);
   mergeVectors(ExtraArgs, Other.ExtraArgs);
   mergeVectors(ExtraArgsBefore, Other.ExtraArgsBefore);
+  mergeVectors(RemovedArgs, Other.RemovedArgs);
   // FIXME: how to handle duplicate names check?
   mergeVectors(CustomChecks, Other.CustomChecks);
   for (const auto &KeyValue : Other.CheckOptions) {
diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 989b1c651c830..3e2cd3948ac65 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -112,8 +112,7 @@ struct ClangTidyOptions {
   /// comments in the relevant check.
   std::optional<std::string> User;
 
-  /// \brief Remove command line arguments sent to the compiler matching this
-  /// regex.
+  /// \brief Remove command line arguments sent to the compiler matching this.
   std::optional<std::vector<std::string>> RemovedArgs;
 
   /// Helper structure for storing option value with priority of the value.
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 64157f530b8c0..1d566df1d1324 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -18,6 +18,7 @@
 #include "../ClangTidy.h"
 #include "../ClangTidyForceLinker.h"
 #include "../GlobList.h"
+#include "../utils/OptionsUtils.h"
 #include "clang/Tooling/CommonOptionsParser.h"
 #include "llvm/ADT/StringSet.h"
 #include "llvm/Support/CommandLine.h"
@@ -355,6 +356,16 @@ see 
https://clang.llvm.org/extra/clang-tidy/QueryBasedCustomChecks.html.
                                               cl::init(false),
                                               cl::cat(ClangTidyCategory));
 
+static cl::list<std::string> RemovedArgs("removed-arg", desc(R"(
+List of arguments to remove from the command
+                                   line sent to the compiler. Please note that
+                                   removing arguments might change the semantic
+                                   of the analzed code, possibly leading to
+                                   compiler errors, false positives or
+                                   false negatives. This option is applied 
+                                   before --extra-arg and 
--extra-arg-before)"),
+                                         cl::cat(ClangTidyCategory));
+
 namespace clang::tidy {
 
 static void printStats(const ClangTidyStats &Stats) {
@@ -421,6 +432,8 @@ 
createOptionsProvider(llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS) {
     OverrideOptions.FormatStyle = FormatStyle;
   if (UseColor.getNumOccurrences() > 0)
     OverrideOptions.UseColor = UseColor;
+  if (RemovedArgs.getNumOccurrences() > 0)
+    OverrideOptions.RemovedArgs = RemovedArgs;
 
   auto LoadConfig =
       [&](StringRef Configuration,
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 59046b6f4c28e..3de8d3004f57d 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -168,7 +168,7 @@ Improvements to clang-tidy
   informational messages.
 
 - Improved :program:`clang-tidy` by adding the option `RemovedArgs` to remove
-  arguments sent to the compiler when invoking clang-tidy.
+  arguments sent to the compiler when invoking Clang-Tidy.
 
 - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
   moved to the ``fuchsia`` module instead. The ``zircon`` module will be 
removed
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index 43142c9121716..301466da896fb 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -330,9 +330,12 @@ An overview of all the command-line options:
                                    TODO() comments in the relevant check.
     WarningsAsErrors             - Same as '--warnings-as-errors'.
     RemovedArgs                  - List of arguments to remove from the command
-                                   line sent to the compiler. Please note that 
-                                   removing arguments from the command line 
-                                   might lead to false positive or negatives. 
+                                   line sent to the compiler. Please note that
+                                   removing arguments might change the semantic
+                                   of the analzed code, possibly leading to
+                                   compiler errors, false positives or
+                                   false negatives. This option is applied 
+                                   before --extra-arg and --extra-arg-before
 
     The effective configuration can be inspected using --dump-config:
 
@@ -342,7 +345,6 @@ An overview of all the command-line options:
       WarningsAsErrors:    ''
       HeaderFileExtensions:         ['', 'h','hh','hpp','hxx']
       ImplementationFileExtensions: ['c','cc','cpp','cxx']
-      RemovedArgs: ['-Werror']
       HeaderFilterRegex:   ''
       FormatStyle:         none
       InheritParentConfig: true
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp
index 4bdca50af32ca..80540411e53e3 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/invalid-command-line.cpp
@@ -1,4 +1,4 @@
 // RUN: not clang-tidy --invalid-arg 2>&1 | FileCheck %s
 
 // CHECK: error: clang-tidy{{(\.exe)?}}: Unknown command line argument 
'--invalid-arg'.  Try: '{{.*}}clang-tidy{{(\.exe)?}} --help'
-// CHECK-NEXT: clang-tidy{{(\.exe)?}}: Did you mean '--extra-arg'?
+// CHECK-NEXT: clang-tidy{{(\.exe)?}}: Did you mean '--removed-arg'?
diff --git 
a/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
 b/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
similarity index 60%
rename from 
clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
rename to clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
index 9a042dedce3a4..a3973142597d0 100644
--- 
a/clang-tools-extra/test/clang-tidy/infrastructure/compilation-args-to-ignore.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
@@ -1,5 +1,7 @@
 // RUN: not clang-tidy %s -- -fnot-an-option | FileCheck %s 
-check-prefix=INVALID-A
 // RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-an-option']}" -- 
-fnot-an-option
 // RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-another-option', 
'-fnot-an-option']}" -- -fnot-an-option -fnot-another-option
+// RUN clang-tidy %s --removed-arg="-fnot-an-option" -- -fnot-an-option 
-fnot-another-option | FileCheck %s -check-prefix=INVALID-B
 
-// INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
\ No newline at end of file
+// INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
+// INVALID-B: error: unknown argument: '-fnot-another-option' 
[clang-diagnostic-error]

From aa6b48f2b40ed601998cbc408e4bec180404b489 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?F=C3=A9lix-Antoine=20Constantin?=
 <[email protected]>
Date: Sun, 2 Nov 2025 10:29:35 -0500
Subject: [PATCH 6/6] Code review

---
 clang-tools-extra/clang-tidy/ClangTidyOptions.h     |  8 ++++----
 clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 13 +++++++------
 .../clang-tidy/tool/clang-tidy-diff.py              |  9 +++++++++
 clang-tools-extra/clang-tidy/tool/run-clang-tidy.py | 12 ++++++++++++
 clang-tools-extra/docs/ReleaseNotes.rst             |  6 ++++--
 clang-tools-extra/docs/clang-tidy/index.rst         |  8 +-------
 .../test/clang-tidy/infrastructure/removed-args.cpp |  2 +-
 7 files changed, 38 insertions(+), 20 deletions(-)

diff --git a/clang-tools-extra/clang-tidy/ClangTidyOptions.h 
b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
index 3e2cd3948ac65..a7a4671fd96e5 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyOptions.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyOptions.h
@@ -85,7 +85,7 @@ struct ClangTidyOptions {
   /// main files will always be displayed.
   std::optional<std::string> HeaderFilterRegex;
 
-  /// \brief Exclude warnings from headers matching this filter, even if they
+  /// Exclude warnings from headers matching this filter, even if they
   /// match \c HeaderFilterRegex.
   std::optional<std::string> ExcludeHeaderFilterRegex;
 
@@ -112,9 +112,6 @@ struct ClangTidyOptions {
   /// comments in the relevant check.
   std::optional<std::string> User;
 
-  /// \brief Remove command line arguments sent to the compiler matching this.
-  std::optional<std::vector<std::string>> RemovedArgs;
-
   /// Helper structure for storing option value with priority of the value.
   struct ClangTidyValue {
     ClangTidyValue() = default;
@@ -154,6 +151,9 @@ struct ClangTidyOptions {
   /// Add extra compilation arguments to the start of the list.
   std::optional<ArgList> ExtraArgsBefore;
 
+  /// Remove command line arguments sent to the compiler matching this.
+  std::optional<std::vector<std::string>> RemovedArgs;
+
   /// Only used in the FileOptionsProvider and ConfigOptionsProvider. If true
   /// and using a FileOptionsProvider, it will take a configuration file in the
   /// parent directory (if any exists) and apply this config file on top of the
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp 
b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 1d566df1d1324..0f0f2799ec786 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -78,6 +78,7 @@ Configuration files:
                                  (if any exists) will be taken and the current
                                  config file will be applied on top of the
                                  parent one.
+  RemovedArgs                  - Same as '--removed-arg'.
   SystemHeaders                - Same as '--system-headers'.
   UseColor                     - Same as '--use-color'.
   User                         - Specifies the name or e-mail of the user
@@ -358,12 +359,12 @@ see 
https://clang.llvm.org/extra/clang-tidy/QueryBasedCustomChecks.html.
 
 static cl::list<std::string> RemovedArgs("removed-arg", desc(R"(
 List of arguments to remove from the command
-                                   line sent to the compiler. Please note that
-                                   removing arguments might change the semantic
-                                   of the analzed code, possibly leading to
-                                   compiler errors, false positives or
-                                   false negatives. This option is applied 
-                                   before --extra-arg and 
--extra-arg-before)"),
+line sent to the compiler. Please note that
+removing arguments might change the semantic
+of the analzed code, possibly leading to
+compiler errors, false positives or
+false negatives. This option is applied 
+before --extra-arg and --extra-arg-before)"),
                                          cl::cat(ClangTidyCategory));
 
 namespace clang::tidy {
diff --git a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py 
b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
index 5daa93dca2a99..c090bdc1151df 100755
--- a/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
+++ b/clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
@@ -228,6 +228,13 @@ def main():
         default=[],
         help="Additional argument to prepend to the compiler " "command line.",
     )
+    parser.add_argument(
+        "-removed-arg",
+        dest="removed_arg",
+        action="append",
+        default=[],
+        help="Arguments to remove from the compiler command line.",
+    )
     parser.add_argument(
         "-quiet",
         action="store_true",
@@ -378,6 +385,8 @@ def main():
         common_clang_tidy_args.append("-extra-arg=%s" % arg)
     for arg in args.extra_arg_before:
         common_clang_tidy_args.append("-extra-arg-before=%s" % arg)
+    for arg in args.removed_arg:
+        common_clang_tidy_args.append("-removed-arg=%s" % arg)
     for plugin in args.plugins:
         common_clang_tidy_args.append("-load=%s" % plugin)
     if args.warnings_as_errors:
diff --git a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py 
b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
index f495f449b5b30..59523fd131185 100755
--- a/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
+++ b/clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
@@ -96,6 +96,7 @@ def get_tidy_invocation(
     allow_enabling_alpha_checkers: bool,
     extra_arg: List[str],
     extra_arg_before: List[str],
+    removed_arg: List[str],
     quiet: bool,
     config_file_path: str,
     config: str,
@@ -135,6 +136,8 @@ def get_tidy_invocation(
         start.append(f"-extra-arg={arg}")
     for arg in extra_arg_before:
         start.append(f"-extra-arg-before={arg}")
+    for arg in removed_arg:
+        start.append(f"-removed-arg={arg}")
     start.append(f"-p={build_path}")
     if quiet:
         start.append("-quiet")
@@ -377,6 +380,7 @@ async def run_tidy(
         args.allow_enabling_alpha_checkers,
         args.extra_arg,
         args.extra_arg_before,
+        args.removed_arg,
         args.quiet,
         args.config_file,
         args.config,
@@ -551,6 +555,13 @@ async def main() -> None:
         default=[],
         help="Additional argument to prepend to the compiler command line.",
     )
+    parser.add_argument(
+        "-removed-arg",
+        dest="removed_arg",
+        action="append",
+        default=[],
+        help="Arguments to remove from the compiler command line.",
+    )
     parser.add_argument(
         "-quiet", action="store_true", help="Run clang-tidy in quiet mode."
     )
@@ -638,6 +649,7 @@ async def main() -> None:
             args.allow_enabling_alpha_checkers,
             args.extra_arg,
             args.extra_arg_before,
+            args.removed_arg,
             args.quiet,
             args.config_file,
             args.config,
diff --git a/clang-tools-extra/docs/ReleaseNotes.rst 
b/clang-tools-extra/docs/ReleaseNotes.rst
index 3de8d3004f57d..8f28df2c35e27 100644
--- a/clang-tools-extra/docs/ReleaseNotes.rst
+++ b/clang-tools-extra/docs/ReleaseNotes.rst
@@ -167,8 +167,10 @@ Improvements to clang-tidy
   scripts by adding the `-hide-progress` option to suppress progress and
   informational messages.
 
-- Improved :program:`clang-tidy` by adding the option `RemovedArgs` to remove
-  arguments sent to the compiler when invoking Clang-Tidy.
+- Improved :program:`clang-tidy` by adding the `--removed-arg` option to remove
+  arguments sent to the compiler when invoking Clang-Tidy. This option was also
+  added to :program:`run-clang-tidy.py` and :program:`clang-tidy-diff.py` and 
+  can be configured in the config file through the `RemovedArgs` option.
 
 - Deprecated the :program:`clang-tidy` ``zircon`` module. All checks have been
   moved to the ``fuchsia`` module instead. The ``zircon`` module will be 
removed
diff --git a/clang-tools-extra/docs/clang-tidy/index.rst 
b/clang-tools-extra/docs/clang-tidy/index.rst
index 301466da896fb..d2c09950e4541 100644
--- a/clang-tools-extra/docs/clang-tidy/index.rst
+++ b/clang-tools-extra/docs/clang-tidy/index.rst
@@ -329,13 +329,7 @@ An overview of all the command-line options:
                                    example, to place the correct user name in
                                    TODO() comments in the relevant check.
     WarningsAsErrors             - Same as '--warnings-as-errors'.
-    RemovedArgs                  - List of arguments to remove from the command
-                                   line sent to the compiler. Please note that
-                                   removing arguments might change the semantic
-                                   of the analzed code, possibly leading to
-                                   compiler errors, false positives or
-                                   false negatives. This option is applied 
-                                   before --extra-arg and --extra-arg-before
+    RemovedArgs                  - Same as '--removed-arg'
 
     The effective configuration can be inspected using --dump-config:
 
diff --git a/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp 
b/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
index a3973142597d0..49429cc4562d3 100644
--- a/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
+++ b/clang-tools-extra/test/clang-tidy/infrastructure/removed-args.cpp
@@ -1,7 +1,7 @@
 // RUN: not clang-tidy %s -- -fnot-an-option | FileCheck %s 
-check-prefix=INVALID-A
 // RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-an-option']}" -- 
-fnot-an-option
 // RUN: clang-tidy %s --config="{RemovedArgs: ['-fnot-another-option', 
'-fnot-an-option']}" -- -fnot-an-option -fnot-another-option
-// RUN clang-tidy %s --removed-arg="-fnot-an-option" -- -fnot-an-option 
-fnot-another-option | FileCheck %s -check-prefix=INVALID-B
+// RUN: not clang-tidy %s --removed-arg="-fnot-an-option" -- -fnot-an-option 
-fnot-another-option | FileCheck %s -check-prefix=INVALID-B
 
 // INVALID-A: error: unknown argument: '-fnot-an-option' 
[clang-diagnostic-error]
 // INVALID-B: error: unknown argument: '-fnot-another-option' 
[clang-diagnostic-error]

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to