[all-commits] [llvm/llvm-project] 7e3ea5: [clang-tidy] modernize-deprecated-headers check sh...
Balazs Benics via All-commits
all-commits at lists.llvm.org
Fri May 13 07:54:43 PDT 2022
Branch: refs/heads/main
Home: https://github.com/llvm/llvm-project
Commit: 7e3ea55da88a9d7feaa22f29d51f89fd0152a189
https://github.com/llvm/llvm-project/commit/7e3ea55da88a9d7feaa22f29d51f89fd0152a189
Author: Balazs Benics <balazs.benics at sigmatechnology.se>
Date: 2022-05-13 (Fri, 13 May 2022)
Changed paths:
M clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.cpp
M clang-tools-extra/clang-tidy/modernize/DeprecatedHeadersCheck.h
M clang-tools-extra/docs/ReleaseNotes.rst
A clang-tools-extra/test/clang-tidy/checkers/Inputs/modernize-deprecated-headers/mylib.h
A clang-tools-extra/test/clang-tidy/checkers/modernize-deprecated-headers-extern-c.cpp
Log Message:
-----------
[clang-tidy] modernize-deprecated-headers check should respect extern "C" blocks
The check should not report includes wrapped by `extern "C" { ... }` blocks,
such as:
```lang=C++
#ifdef __cplusplus
extern "C" {
#endif
#include "assert.h"
#ifdef __cplusplus
}
#endif
```
This pattern comes up sometimes in header files designed to be consumed
by both C and C++ source files.
The check now reports false reports when the header file is consumed by
a C++ translation unit.
In this change, I'm not emitting the reports immediately from the
`PPCallback`, rather aggregating them for further processing.
After all preprocessing is done, the matcher will be called on the
`TranslationUnitDecl`, ensuring that the check callback is called only
once.
Within that callback, I'm recursively visiting each decls, looking for
`LinkageSpecDecls` which represent the `extern "C"` specifier.
After this, I'm dropping all the reports coming from inside of it.
After the visitation is done, I'm emitting the reports I'm left with.
For performance reasons, I'm sorting the `IncludeMarkers` by their
corresponding locations.
This makes the scan `O(log(N)` when looking up the `IncludeMarkers`
affected by the given `extern "C"` block. For this, I'm using
`lower_bound()` and `upper_bound()`.
Reviewed By: whisperity
Differential Revision: https://reviews.llvm.org/D125209
More information about the All-commits
mailing list