Calling setSeverityForGroup in clang plugins massively slows down clang when using `-fmodule-file`
- Dominant language
- LLVM
- Stars
- 40.5k
- Forks
- 18.7k
- PR merge metrics
- PR metrics pending
Description
I found that for chromium, the following ([source](https://source.chromium.org/chromium/chromium/src/+/main:tools/clang/plugins/UnsafeBuffersPlugin.cpp;l=488-499;drc=cf674e95d5aa7ac95450b02ad999762be9f14322)) in our clang plugin slowed the time to compile an *empty* file from 60ms to 800ms
```c++
class UnsafeBuffersASTConsumer : public clang::ASTConsumer {
UnsafeBuffersASTConsumer(clang::CompilerInstance* instance) {
clang::DiagnosticsEngine& engine = instance_->getDiagnostics();
engine.setSeverityForGroup(clang::diag::Flavor::WarningOrError,
"unsafe-buffer-usage",
clang::diag::Severity::Remark);
}
```
My best guess is that calling `setSeverityForGroup` results in it attempting to read the whole AST file of the files we passed to `-fmodule-file`.
I don't intend to debug this further, as we managed to find a workaround, but I thought I'd post this here in case anyone else ran into a similar issue.
Contributor guide
Research direction
Start with the setSeverityForGroup call in Chromium's tools/clang/plugins/UnsafeBuffersPlugin.cpp at lines 488-499, then reproduce the empty-file compile timing with and without -fmodule-file. Trace whether reading module AST files causes the slowdown; done means identifying and resolving the regression without losing the intended unsafe-buffer-usage severity behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100