This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] fix crash involving invalid preprocessor line
ClosedPublic

Authored by krasimir on Aug 8 2019, 4:44 AM.

Details

Summary

This (invalid) fragment is crashing clang-format:

#if 1
int x;
#elif
int y;
#endif

The reason being that the parser expects a token after #elif, and the
subsequent parsing of the next line does not check if CurrentToken is null.

Diff Detail

Repository
rL LLVM

Event Timeline

krasimir created this revision.Aug 8 2019, 4:44 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2019, 4:44 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
gribozavr accepted this revision.Aug 8 2019, 4:51 AM
gribozavr added inline comments.
unittests/Format/FormatTest.cpp
3090 ↗(On Diff #214113)

// #elif directive without a condition. -- to follow the existing comment format in other tests.

This revision is now accepted and ready to land.Aug 8 2019, 4:51 AM
krasimir updated this revision to Diff 214115.Aug 8 2019, 4:52 AM
krasimir marked an inline comment as done.
  • Apply review comments
krasimir marked an inline comment as done.Aug 8 2019, 4:53 AM
krasimir added inline comments.
unittests/Format/FormatTest.cpp
3090 ↗(On Diff #214113)

done

This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptAug 8 2019, 4:55 AM