This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix how ReadMacroParameterList handles comments in macro parameter-list when in -CC mode
ClosedPublic

Authored by shafik on Feb 21 2023, 11:48 AM.

Details

Summary

Currently when in -CC mode when processing a function like macro ReadMacroParameterList(...) does not handle the case where there is a comment embedded in the parameter-list.

Instead of using LexUnexpandedToken(...) I switched to using LexUnexpandedNonComment(...) which eats comments while lexing.

Fixes: https://github.com/llvm/llvm-project/issues/60887

Diff Detail

Event Timeline

shafik created this revision.Feb 21 2023, 11:48 AM
Herald added a project: Restricted Project. · View Herald TranscriptFeb 21 2023, 11:48 AM
shafik requested review of this revision.Feb 21 2023, 11:48 AM

Based on the error message we had, it seems like this previous behavior was intentional. Are we sure comments SHOULD be allowed here? @tahonermann / @cor3ntin are the LEX code owners.

This looks good to me.
Comments are allowed anywhere between token, anywhere whitespace would be.

It appears LexUnexpandedToken gets used multiple times in this function.

The following example demonstrates an error with each call not being LexUnexpandedNonComment:

/* no errors with comments removed */
#define A(.../**/)
#define B(x/**/)
#define C(x.../**/)

https://godbolt.org/z/Y6fGb59qb

Offending code is on lines 2663, 2697, and 2713, respectively.

shafik updated this revision to Diff 506211.Mar 17 2023, 3:33 PM
  • Switched to LexUnexpandedNonComment in more places
  • Extended test suite to cover the new cases uncovered in the comments
cor3ntin added a comment.EditedMar 29 2023, 9:50 AM

Sorry for the late review.
Can you add a release note mentioning the fixed issue?
Otherwise LGTM

shafik updated this revision to Diff 509795.Mar 30 2023, 1:12 PM
  • Add release notes.
cor3ntin accepted this revision.Mar 30 2023, 1:13 PM

Thanks!

This revision is now accepted and ready to land.Mar 30 2023, 1:13 PM
This revision was landed with ongoing or failed builds.Mar 30 2023, 1:38 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 30 2023, 1:38 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript