This is an archive of the discontinued LLVM Phabricator instance.

[clang][lex][minimizer] Ensure whitespace between squashed lines
ClosedPublic

Authored by jansvoboda11 on Feb 8 2022, 4:09 AM.

Details

Summary

The minimizer tries to squash multi-line macro definitions into single line. For that to work, contents of each line need to be separated by a space. Since we always strip leading whitespace on lines of a macro definition, the code currently tries to preserve exactly one space that appeared before the backslash.

This means the following code:

#define FOO(BAR) \
  #BAR           \
  baz

gets minimized into:

#define FOO(BAR) #BAR baz

However, if there are no spaces before the backslash on line 2:

#define FOO(BAR) \
  #BAR\
  baz

no space can be preserved, leading to (most likely) malformed macro definition:

#define FOO(BAR) #BARbaz

This patch makes sure we always put exactly one space at the end of line ending with a backslash.

Diff Detail

Event Timeline

jansvoboda11 requested review of this revision.Feb 8 2022, 4:09 AM
jansvoboda11 created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 8 2022, 4:09 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
arphaman accepted this revision.Feb 8 2022, 12:10 PM

LG, thanks!

This revision is now accepted and ready to land.Feb 8 2022, 12:10 PM