This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] fix alignment w/o binpacked args
ClosedPublic

Authored by cha5on on May 7 2022, 4:07 AM.

Details

Summary

The combination of

  • AlignConsecutiveAssignments.Enabled = true
  • BinPackArguments = false

would result in the first continuation line of a braced-init-list being
improperly indented (missing a shift) when in a continued function call.
Indentation was also wrong for braced-init-lists continuing a
direct-list-initialization. Check for opening braced lists in
continuation and ensure that the correct shift occurs.

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

Diff Detail

Event Timeline

cha5on created this revision.May 7 2022, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2022, 4:07 AM
cha5on requested review of this revision.May 7 2022, 4:07 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 7 2022, 4:07 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
cha5on added a project: Restricted Project.

For me there needs no bug report, but could you comment on the misformatting without the patch?

clang/unittests/Format/FormatTest.cpp
17327

Drop the scope, we don't have that in other tests.

curdeius requested changes to this revision.May 7 2022, 4:49 AM

Thanks for working on this!
Is there a bug report somewhere? If not, may you create one please?

clang/lib/Format/WhitespaceManager.cpp
398

Elide braces please.

clang/unittests/Format/FormatTest.cpp
17359

I don't think you need to create variables, just online the strings.

Also, could you minimize (and possibly split) as much as possible these test cases?

This revision now requires changes to proceed.May 7 2022, 4:49 AM

FYI, I like to have a bug report because people that encounter the same problem (in an older release) can find it easily, and see if/when it was fixed. It also avoid working on the same thing by different people.

cha5on updated this revision to Diff 428262.May 9 2022, 7:16 PM

Update for review

  • Add and link bug report.
  • Remove braces per LLVM style.
  • Shrink down test case and add second case for direct-list-initialization alignment.
cha5on marked 3 inline comments as done.May 9 2022, 7:18 PM
cha5on added inline comments.
clang/unittests/Format/FormatTest.cpp
17359

Shrank this down and added a second testcase for direct-list-initialization.

cha5on edited the summary of this revision. (Show Details)May 9 2022, 7:20 PM

Thanks for creating the bug report. A few more comments.

clang/lib/Format/WhitespaceManager.cpp
374–375

It seems that we set BK_BracedInit only on l_brace, so no need for a redundant check.

394–398

Ditto.

clang/unittests/Format/FormatTest.cpp
17328–17337

Why not just this?

17338–17347

And here.

curdeius requested changes to this revision.May 10 2022, 12:37 AM
This revision now requires changes to proceed.May 10 2022, 12:37 AM
clang/unittests/Format/FormatTest.cpp
17324

I'd drop that, or at least replace it with https://llvm.org/PR55360.

cha5on updated this revision to Diff 429138.May 12 2022, 10:04 PM
cha5on marked 4 inline comments as done.

Update for review.

  • Further simplify testcases.
  • Update issue URL in comment to use llvm.org alias.
clang/lib/Format/WhitespaceManager.cpp
374–375

BK_BracedInit also gets set on r_brace, assuming I'm reading clang/lib/Format/UnwrappedLineParser.cpp correctly. I think we need both to be true to be sure that this is the intended token.

clang/unittests/Format/FormatTest.cpp
17324

Replaced.

17328–17337

I was reading a comment in this file that says that messUp manipulates leading whitespace and thought that meant it wouldn't be appropriate for this. Upon a closer look, it seems to work fine here, so updating to just provide the expected case.

curdeius accepted this revision.May 12 2022, 11:03 PM

LGTM. Tell us if you need help landing this.
Thanks a lot for your contribution!

clang/lib/Format/WhitespaceManager.cpp
374–375

Ok.

This revision is now accepted and ready to land.May 12 2022, 11:03 PM

LGTM. Tell us if you need help landing this.

I don't have commit access, so some help would be great :-)

This revision was automatically updated to reflect the committed changes.