Feature Request: A well-defined preprocessor symbol to identify Clang analysis
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
Clang-Tidy defines the `__clang_analyzer__` macro to make it possible for the preprocessor to detect when the code is being analyzed:
https://reviews.llvm.org/D46325
https://reviews.llvm.org/D68093
https://github.com/llvm/llvm-project/blob/llvmorg-21.1.8/clang-tools-extra/clang-tidy/ClangTidy.cpp#L591
This works as expected when running the `clang-tidy` tool from the commandline, but as far as I can see, it doesn't work when run by clangd.
I guess clangd doesn't go through the initialization in `ClangTidy.cpp` but instead does its own thing when running the analyzers and there doesn't do the `SetUpStaticAnalyzer = true` that ClangTidy.cpp does to get `__clang_analyzer__` defined. I assume that this is a bug.
Contributor guide
Research direction
The issue points to clang-tools-extra/clang-tidy/ClangTidy.cpp around line 591 and the SetUpStaticAnalyzer initialization. Compare that command-line setup with clangd's analyzer path to determine where the preprocessor symbol is omitted. Done means clangd analysis consistently exposes the requested symbol, with behavior aligned with clang-tidy.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, tooling
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100