zeyi2 wrote:

> Could you give please some high-level overview/description of what is 
> happening here?

> but I hope you can provide more introduction for this functions

Sure, here is a writeup of the whole PR :)

# The purpose of this PR

**TL;DR: Simplify the way we test headers.**

In the current implementation of `check_clang_tidy.py`, to check header files, 
we need to:
- Create a temp dir: `RUN: mkdir -p %t.dir`.
- Copy all the headers into that dir: `cp %S/.... %t.dir/....`.
- Run `clang-tidy` to apply the fixes over these copied files.
- Use `FileCheck` to verify that fixes are correct.

The procedure is a bit complicated and confusing. And not having a simple way 
to test headers has introduced some issues in `clang-tidy` codebase:

- Test coverage: Some testcases inside headers are not being run.
- Test correctness: Some testcases inside headers seem to be incorrect/broken .
  - #173530
- Bad user experience: Users may expect this script to check headers by default.
  - #172391 
  - #133515

# How this PR fixes the issue

**TL;DR: Introduce a new argument called `-check-header` to specify the headers 
to be checked.**

More specifically:

1. Create a temporary directory (`%t.headers`) and copies the specified headers 
there.
2. Removes `// CHECK-...` lines from the header copies (just like it does for 
the main file) to prevent self-matching.
3. Runs `clang-tidy` on the main file [1]. Since we include the temporary 
headers via `-I`, `clang-tidy` automatically applies any fixes directly to the 
header copies in the temporary directory.
4. Verification:
    * It separates the fixes and diagnostics for the main file from those for 
the headers.
    * It runs `FileCheck` on the header copy using the header's own diagnostics.
    * It runs `FileCheck` on the main file using the main file's diagnostics.

[1] If I understand correctly, `clang-tidy` emits diagnostics for the main file 
and all included headers into a single mixed output stream. So that's the main 
reason we need to split them.

# The implementation

Please refer to the comments below:

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

Reply via email to