This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Don't skip PP lines if original line was a PP line when trying to merge lines
ClosedPublic

Authored by aeubanks on Apr 19 2022, 1:05 PM.

Details

Summary

Fixes a crash introduced in D123737 where LastNonComment would be null.

Diff Detail

Event Timeline

aeubanks created this revision.Apr 19 2022, 1:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 1:05 PM
aeubanks requested review of this revision.Apr 19 2022, 1:05 PM
Herald added a project: Restricted Project. · View Herald TranscriptApr 19 2022, 1:05 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
aeubanks added inline comments.Apr 19 2022, 1:06 PM
clang/unittests/Format/FormatTest.cpp
13397

not sure if you'd like a better test, this was the reduced test case I got that still caused a crash

curdeius accepted this revision.Apr 19 2022, 10:49 PM

LGTM.

clang/unittests/Format/FormatTest.cpp
13397

That's ok for me.

This revision is now accepted and ready to land.Apr 19 2022, 10:49 PM
owenpan added inline comments.Apr 20 2022, 1:59 AM
clang/lib/Format/UnwrappedLineFormatter.cpp
309–316

Or simply return before the for loop if TheLine->InPPDirective is true?

aeubanks updated this revision to Diff 423923.Apr 20 2022, 8:42 AM

take suggestion

clang/lib/Format/UnwrappedLineFormatter.cpp
309–316

I'm not 100% sure how TheLine->Level works in the presence of macros (e.g. a function that's fully defined in a macro), would we want to also search for (*J)->Level < TheLine->Level in that case?

either way, I've taken your suggestion because I'd like to get this crash fix landed

This revision was landed with ongoing or failed builds.Apr 20 2022, 8:43 AM
This revision was automatically updated to reflect the committed changes.