[clang] [clang-tools-extra] [clang] Don't add documentation comments to the AST if not requested (PR #206363)
Prajwal Nadig via cfe-commits
cfe-commits at lists.llvm.org
Wed Jul 1 03:03:29 PDT 2026
================
@@ -74,8 +74,12 @@ Parser::Parser(Preprocessor &pp, Sema &actions, bool skipFunctionBodies)
// destructor.
initializePragmaHandlers();
- CommentSemaHandler.reset(new ActionCommentHandler(actions));
- PP.addCommentHandler(CommentSemaHandler.get());
+ // Only install the comment handler when some consumer may read documentation
+ // comments back.
+ if (actions.shouldRetainCommentsFromLexer(SourceLocation())) {
----------------
snprajwal wrote:
I don't think the lexer would've run at this stage. If `-Wdocumentation` is not passed via the command line, the handler is not installed even if the check may be present through pragmas. We can omit this and unconditionally install the handler here, since we also perform a per-comment check in [`Sema::ActOnComment`](https://github.com/AnonMiraj/llvm-project/blob/b8f65be707737d731896d5ca7f34e73a8df55406/clang/lib/Sema/Sema.cpp#L2737-L2738)
https://github.com/llvm/llvm-project/pull/206363
More information about the cfe-commits
mailing list