This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix a crash (assertion) in qualifier alignment when matching template closer is null
ClosedPublic

Authored by MyDeveloperDay on Jan 6 2022, 12:24 AM.

Details

Summary

https://github.com/llvm/llvm-project/issues/53008

template <class Id> using A = quantity /**/<kind<Id>, 1>;

the presence of the comment between identifier and template opener seems to be causing the qualifier alignment to fail

Diff Detail

Event Timeline

MyDeveloperDay requested review of this revision.Jan 6 2022, 12:24 AM
MyDeveloperDay created this revision.

The cause is because Next is a comment, not a template opener, handle that case.

curdeius added inline comments.Jan 6 2022, 12:56 AM
clang/unittests/Format/QualifierFixerTest.cpp
830

Could you test with a line comment too?

830

And what about multiple comments? Maybe we need a while loop instead of if?

curdeius added inline comments.Jan 6 2022, 12:57 AM
clang/unittests/Format/QualifierFixerTest.cpp
830

And test with non-empty comments too.

MyDeveloperDay marked 3 inline comments as done.

Use getNextNonComment() which has some const-ness knock ons (but probably not a bad thing)

address the review concerns by adding more tests (which indeed highlighted new failure scenarios! Thanks @curdeius)

curdeius accepted this revision.Jan 6 2022, 5:44 AM

LGTM! Thanks :).

This revision is now accepted and ready to land.Jan 6 2022, 5:44 AM

Just a last thought, you can maybe minimize some of the test cases.
It seems that even:

using X = Y /**/ <>;

reproduces the issue.

Simplify down the test to make it easier to read, keep perhaps slightly duplicated tests to just ensure we have the coverage

Cool. Thanks!

This revision was landed with ongoing or failed builds.Jan 6 2022, 11:46 AM
This revision was automatically updated to reflect the committed changes.