[all-commits] [llvm/llvm-project] c07797: [clang-format] Fix alignment in #else preprocessor...

mitchell-stellar via All-commits all-commits at lists.llvm.org
Tue Sep 27 12:46:57 PDT 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: c0779756a0c4cc84d9f98714734d47879701cc3d
      https://github.com/llvm/llvm-project/commit/c0779756a0c4cc84d9f98714734d47879701cc3d
  Author: mitchell <56368743+mitchell-stellar at users.noreply.github.com>
  Date:   2022-09-27 (Tue, 27 Sep 2022)

  Changed paths:
    M clang/lib/Format/WhitespaceManager.cpp
    M clang/unittests/Format/FormatTest.cpp

  Log Message:
  -----------
  [clang-format] Fix alignment in #else preprocessor blocks
Summary:
clang-format makes multiple passes when #if/#else preprocessor blocks are found.  It will make
one pass for normal code and code in the #if block, and then it will make another pass for just
the code in #else blocks. This often results in invalid alignment inside the else blocks because
they do not have any scope or indentAndNestingLevel context from their surrounding tokens/lines.

This patch remedies that by caching any initial indentAndNestingLevel from a second pass and
not breaking/returning early when a scope change is detected.

Fixes #36070

Reviewers: HazardyKnusperkeks, MyDeveloperDay

Tags: clang, clang-format

Differential Revision: https://reviews.llvm.org/D134042




More information about the All-commits mailing list