Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
#include "../GlobList.h"
#include "clang/Tooling/CommonOptionsParser.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/InitLLVM.h"
#include "llvm/Support/PluginLoader.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Signals.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/WithColor.h"
#include "llvm/TargetParser/Host.h"
#include <optional>

using namespace clang::tooling;
Expand Down Expand Up @@ -553,6 +555,21 @@ static llvm::IntrusiveRefCntPtr<vfs::OverlayFileSystem> createBaseFS() {

int clangTidyMain(int argc, const char **argv) {
llvm::InitLLVM X(argc, argv);
SmallVector<const char *> Args{argv, argv + argc};

// expand parameters file to argc and argv.
llvm::BumpPtrAllocator Alloc;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add a one-line comment describing what this block of code does/is meant for? Even better, can it be put into its own function?

Copy link
Contributor Author

@HerrCai0907 HerrCai0907 Dec 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

extract to another function is less benefit because variable lifetime issue. The allocator must have same lifetime with argc
and argv.

llvm::cl::TokenizerCallback Tokenizer =
llvm::Triple(llvm::sys::getProcessTriple()).isOSWindows()
? llvm::cl::TokenizeWindowsCommandLine
: llvm::cl::TokenizeGNUCommandLine;
llvm::cl::ExpansionContext ECtx(Alloc, Tokenizer);
if (llvm::Error Err = ECtx.expandResponseFiles(Args)) {
llvm::WithColor::error() << llvm::toString(std::move(Err)) << "\n";
return 1;
}
argc = static_cast<int>(Args.size());
argv = Args.data();

// Enable help for -load option, if plugins are enabled.
if (cl::Option *LoadOpt = cl::getRegisteredOptions().lookup("load"))
Expand Down
2 changes: 2 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ Improvements to clang-tidy
- Improved :program:`run-clang-tidy.py` script. Fixed minor shutdown noise
happening on certain platforms when interrupting the script.

- Improved :program:`clang-tidy` by accepting parameters file in command line.

- Removed :program:`clang-tidy`'s global options for most of checks. All options
are changed to local options except `IncludeStyle`, `StrictMode` and
`IgnoreMacros`.
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/docs/clang-tidy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ compilation options on the command line after ``--``:

$ clang-tidy test.cpp -- -Imy_project/include -DMY_DEFINES ...

If there are too many options to specify on the command line, you can store them
in a parameter file, and use :program:`clang-tidy` with parameters file:

.. code-block:: console

$ clang-tidy @parameters_file

:program:`clang-tidy` has its own checks and can also run Clang Static Analyzer
checks. Each check has a name and the checks to run can be chosen using the
``-checks=`` option, which specifies a comma-separated list of positive and
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-checks='-*,llvm-namespace-comment'
--warnings-as-errors=llvm-namespace-comment
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// RUN: echo @%t.param > %t.param && not clang-tidy %s @%t.param -- 2>&1 | FileCheck %s

// CHECK: recursive expansion of
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// RUN: not clang-tidy %s @%S/Inputs/param/parameters.txt -- | FileCheck %s

namespace i {
}
// CHECK: error: namespace 'i' not terminated with a closing comment [llvm-namespace-comment,-warnings-as-errors]
Loading