Allow getRawCommentForDecl to find comments in macros
authorDana Jansens <danakj@orodu.net>
Thu, 26 Jan 2023 08:53:59 +0000 (09:53 +0100)
committerDmitri Gribenko <gribozavr@gmail.com>
Thu, 26 Jan 2023 09:12:57 +0000 (10:12 +0100)
commit8bb54da5da3194b71b54f70c6cc55485cf2623b0
treec936246b940e3fcde3acd55061a96e899790383b
parentba43f3e857390932fede4aedf3e57d8f3787e804
Allow getRawCommentForDecl to find comments in macros

The key part of getRawCommentForDecl() required to find a comment
is determining where to look for it. The location of the decl
itself is usually right, except when macros get involved. The
comment in the macro is stored in RawCommentList at the spelling
location of the decl, not at the place where the decl comes into
being as the macro is instantiated.

getDeclLocForCommentSearch() already contained to branches to try
handle comments inside macros, and we are able to replace them
and handle more cases as well, by returning the spelling location
of the decl's begin location. That is:
  SourceMgr.getSpellingLoc(D->getBeginLoc())

Reviewed By: gribozavr2

Differential Revision: https://reviews.llvm.org/D142560
clang/lib/AST/ASTContext.cpp
clang/test/Index/annotate-comments-objc.m