This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Fix misattributing preprocessor directives to macros
ClosedPublic

Authored by jacob-abraham on Oct 6 2022, 10:19 PM.

Details

Summary

This solves the issue I documented at https://github.com/llvm/llvm-project/issues/58214.

Essentially, a case statement inside a macro greedily adds preprocessor lines such as #include to the macro, even if they are not a part of the macro to begin with. Short quick fix. I tried to do it cleanly, but this was my first attempt at patching clang-format so if there is a cleaner/better way to fix this that would be awesome!

Diff Detail

Event Timeline

jacob-abraham created this revision.Oct 6 2022, 10:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 10:19 PM
jacob-abraham requested review of this revision.Oct 6 2022, 10:19 PM
Herald added a project: Restricted Project. · View Herald TranscriptOct 6 2022, 10:19 PM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Added regression test

Fix patch, sorry about that

The clang-format tests are (mainly) in clang/unittests/Format/FormatTest.cpp, please put it there.
You should have a Format-Tests (or similar) build target.

fixed unit tests

HazardyKnusperkeks retitled this revision from Fix clang-format misattributing preprocessor directives to macros to [clang-format] Fix misattributing preprocessor directives to macros.
This revision is now accepted and ready to land.Oct 10 2022, 12:09 AM
owenpan added inline comments.Oct 10 2022, 1:47 AM
clang/unittests/Format/FormatTest.cpp
2986–2990 ↗(On Diff #466386)

We can move it down to take advantage of the shorter ColumnLimit.

3006 ↗(On Diff #466386)

We usually don't append a newline at the end of a test case.

jacob-abraham marked 2 inline comments as done.Oct 10 2022, 8:52 AM

I do not have commit access, can someone make this commit on my behalf? Thank you!

owenpan accepted this revision.Oct 10 2022, 4:18 PM

LGTM.

I do not have commit access, can someone make this commit on my behalf? Thank you!

We need your name and email address for the authorship.

We need your name and email address for the authorship.

Name: Jacob Abraham
Email: jacob.r.abraham@gmail.com

owenpan added inline comments.Oct 10 2022, 7:32 PM
clang/lib/Format/UnwrappedLineFormatter.cpp
654 ↗(On Diff #466522)

Did you run git-clang-format?

This revision was landed with ongoing or failed builds.Oct 10 2022, 7:58 PM
This revision was automatically updated to reflect the committed changes.