[cfe-dev] getRawCommentForDeclNoCacheImpl: linemarkers between between comment and declaration

Michael Zimmermann via cfe-dev cfe-dev at lists.llvm.org
Mon Feb 22 06:32:18 PST 2021


Hi,

when looking for comments attached to a declaration, the
implementation aborts if (among other things) it finds a preprocessor
macro.
The problem with that is that when parsing a preprocessed file there
might be linemarkers like this:
> # 4 "bug.c" 3 4
> static inline
> # 4 "bug.c"
>          void fn(void);
Here, "static inline" was expanded from a macro. GCC seems to add
linemarkers if the macro comes from a system header.

I think that as long as the line markers just update the line
information of the current file and are not entering/leaving a
different file it should be okay to attach the comment to the
declaration.

That might be more complicated though because right now the check is
being done using a simple text search:
> if (Text.find_first_of(";{}#@") != StringRef::npos) {
>   printf("preproc\n");
>   return nullptr;
> }

What do you think?

Thanks
Michael


More information about the cfe-dev mailing list