This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Improve detection of parameter declarations in K&R C
ClosedPublic

Authored by owenpan on Aug 15 2021, 2:50 PM.

Details

Summary

Clean up the detection of parameter declarations in K&R C function definitions. Also make it more precise by requiring the second token after the r_paren to be either a star or keyword/identifier.

Diff Detail

Event Timeline

owenpan requested review of this revision.Aug 15 2021, 2:50 PM
owenpan created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptAug 15 2021, 2:50 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript
owenpan updated this revision to Diff 366541.Aug 15 2021, 7:30 PM

Simplified the code slightly.

clang/lib/Format/UnwrappedLineParser.cpp
1025

should we have test cases showing these examples?

1029

Can you add unit tests for these cases?

1397

Can't next be null once again?

owenpan added inline comments.Aug 16 2021, 1:29 AM
clang/lib/Format/UnwrappedLineParser.cpp
1025

Probably not unless we are to include a test case for every keyword. I can add them if you insist.

1029

I think the existing test cases already cover this, which is a subset of the previous cases (the second token can be anything but tok::l_paren and tok::semi)?

1397

No because FormatTok is not tok::eof. If AllTokens[Position] is null, it would be an internal error, which is asserted at the top of isC78ParameterDecl().

This revision is now accepted and ready to land.Aug 18 2021, 4:53 AM

@owenpan Can we push all these commits to 13 RC2 via https://bugs.llvm.org/show_bug.cgi?id=51470

We need to mark the commits we want to cherry pick I think.

@owenpan Can we push all these commits to 13 RC2 via https://bugs.llvm.org/show_bug.cgi?id=51470

We need to mark the commits we want to cherry pick I think.

Thanks! Updated 51470. Let me know if there is anything else for me to do.