This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix assertion failure/crash with `AllowShortFunctionsOnASingleLine: Inline/InlineOnly`.
ClosedPublic

Authored by curdeius on Mar 3 2022, 6:39 AM.

Details

Summary

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

When handling AllowShortFunctionsOnASingleLine, we were searching for the last line with a smaller level than the current line. The search was incorrect when the first line had the same level as the current one. This led to an unsatisfied assumption about the existence of a brace (non-comment token).

Diff Detail

Event Timeline

curdeius created this revision.Mar 3 2022, 6:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 6:39 AM
curdeius requested review of this revision.Mar 3 2022, 6:39 AM
Herald added a project: Restricted Project. · View Herald TranscriptMar 3 2022, 6:39 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
This revision is now accepted and ready to land.Mar 3 2022, 11:48 AM
owenpan added inline comments.Mar 3 2022, 5:16 PM
clang/lib/Format/UnwrappedLineFormatter.cpp
313

To be safe?

curdeius added inline comments.Mar 3 2022, 11:50 PM
clang/lib/Format/UnwrappedLineFormatter.cpp
313

Good idea. Will do.
Any idea how to provoke this (if at all possible)?

owenpan added inline comments.Mar 4 2022, 1:10 AM
clang/lib/Format/UnwrappedLineFormatter.cpp
313

I can't think of a valid C++ example that would trigger this.

curdeius updated this revision to Diff 413380.Mar 7 2022, 1:49 AM

Safer condition.

curdeius marked 2 inline comments as done.Mar 7 2022, 1:50 AM
owenpan accepted this revision.Mar 7 2022, 2:00 AM
This revision was automatically updated to reflect the committed changes.