This is an archive of the discontinued LLVM Phabricator instance.

[Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`
ClosedPublic

Authored by akyrtzi on Sep 11 2022, 10:20 AM.

Diff Detail

Event Timeline

akyrtzi created this revision.Sep 11 2022, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2022, 10:20 AM
akyrtzi requested review of this revision.Sep 11 2022, 10:20 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 11 2022, 10:20 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Could you explain why this is necessary and even correct? I'd expect Clang to give an error when seeing ## in this position, and I'd expect the scanner to do the same.

Could you explain why this is necessary and even correct? I'd expect Clang to give an error when seeing ## in this position, and I'd expect the scanner to do the same.

## is lexed as tok::hashhash; it is ignored by the preprocessor (it is not treated as the start of a preprocessor directive) and passed on to the parser to interpret, like any other token.

akyrtzi updated this revision to Diff 459888.Sep 13 2022, 3:04 PM

Add comment to clarify why we skip if tok::hashhash is encountered.

Could you explain why this is necessary and even correct? I'd expect Clang to give an error when seeing ## in this position, and I'd expect the scanner to do the same.

## is lexed as tok::hashhash; it is ignored by the preprocessor (it is not treated as the start of a preprocessor directive) and passed on to the parser to interpret, like any other token.

@jansvoboda11 I've added a comment in code to make it clear why it skips.

jansvoboda11 accepted this revision.Sep 13 2022, 3:14 PM

Thank you! LGTM.

This revision is now accepted and ready to land.Sep 13 2022, 3:14 PM