[clang] [clang-tools-extra] [clang] Don't add documentation comments to the AST if not requested (PR #206363)
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 30 08:25:31 PDT 2026
================
@@ -2703,11 +2705,37 @@ LambdaScopeInfo *Sema::getCurGenericLambda() {
return nullptr;
}
+bool Sema::shouldRetainCommentsFromLexer(SourceLocation Loc) const {
+ if (LangOpts.CommentOpts.ParseAllComments)
+ return true;
+
+ if (LangOpts.CommentOpts.RetainComments)
+ return true;
+
+ // When building a PCH the comments are serialized into the AST file
+ // so downstream consumers like clangd) can retrieve documentation, and the
+ // incremental/REPL front end may query them interactively.
+ if (TUKind != TU_Complete)
+ return true;
+
+ if (PP.isCodeCompletionEnabled())
+ return true;
+
+ // Keep the comment if -Wdocumentation is enabled at its location (checking
+ // the location handles warnings turned on by `#pragma clang diagnostic`).
+ if (!Diags.isIgnored(diag::warn_doc_param_not_found, Loc) ||
----------------
AaronBallman wrote:
We don't have anything like `Diags.areAnyIgnored("-Wdocumentation")` which is the interface I naively think would make sense for this sort of thing.
Actually, I think the current approach here isn't viable. The user could disable one of the diagnostics we're checking for via `#pragma clang diagnostic` but still enable all of the other diagnostics in the same group. So I think we might need to add an interface like `areAnyIgnored` to do this correctly and efficiently...
https://github.com/llvm/llvm-project/pull/206363
More information about the cfe-commits
mailing list