[PATCH] D135740: [clang-format] Fix multiple preprocessor if sections parsing incorrectly

sstwcw via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 11 19:25:03 PDT 2022


sstwcw created this revision.
sstwcw added reviewers: HazardyKnusperkeks, MyDeveloperDay, curdeius, owenpan, sammccall.
Herald added a project: All.
sstwcw requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

In 2183fe2 <https://reviews.llvm.org/rG2183fe2160fbcb754893e98829f2bff4d0fccfa3> I didn't notice that `PPLevelBranchIndex` was common to the
entire file.  The commit caused problems when there are multiple
preprocessor if sections.  Using a single `PPLevelBranchIndex` also
brings the problem that the extra branches in an if section with more
branches than other sections are parsed without other sections.

This patch fixes the problem by storing the structure of the
preprocessor if sections.  This way, `PPLevelBranchIndex` is checked
against the stored structure, and if a nonexistent branch is called for
because another section has more branches, the first or second branch
will be parsed.  The change in 2183fe2 <https://reviews.llvm.org/rG2183fe2160fbcb754893e98829f2bff4d0fccfa3> setting `PPLevelBranchIndex` is
reverted.  Instead the stored branch structure is used to determine when
the second branch should be parsed instead of the first.

The logic for determining when a branch is skipped in moved from
`conditionalCompilationStart` and `conditionalCompilationAlternative`
into `conditionalCompilationCondition` because the two cases now have
more overlap.  `PPChainbranchIndex` is changed to include the section
number in addition to the branch number.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D135740

Files:
  clang/lib/Format/UnwrappedLineParser.cpp
  clang/lib/Format/UnwrappedLineParser.h
  clang/unittests/Format/FormatTest.cpp

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D135740.466996.patch
Type: text/x-patch
Size: 9683 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221012/c09656a5/attachment-0001.bin>


More information about the cfe-commits mailing list