This is an archive of the discontinued LLVM Phabricator instance.

[clang-format] Support inheriting from more than 1 parents in the fallback case
ClosedPublic

Authored by zwliew on Dec 29 2021, 5:37 AM.

Details

Summary

Currently, we are unable to inherit from a chain of parent configs where the outermost parent config has BasedOnStyle: InheritParentConfig set. This patch adds a test case for this scenario, and adds support for it.

To illustrate, suppose we have the following directory structure:

- e/
  |- .clang-format (BasedOnStyle: InheritParentConfig) <-- outermost config
  |- sub/
    |- .clang-format (BasedOnStyle: InheritParentConfig)
    |- sub/
      |- .clang-format (BasedOnStyle: InheritParentConfig)
      |- code.cpp

Now consider what happens when we run clang-format --style=file /e/sub/sub/code.cpp.

Without this patch, on a release build, only the innermost config will be applied. On a debug build, clang-format crashes due to an assertion failure.
With this patch, clang-format behaves as we'd expect, applying all 3 configs.

Diff Detail

Event Timeline

zwliew requested review of this revision.Dec 29 2021, 5:37 AM
zwliew created this revision.
zwliew added projects: Restricted Project, Restricted Project.
zwliew edited the summary of this revision. (Show Details)
zwliew edited the summary of this revision. (Show Details)Dec 29 2021, 7:05 AM

Thanks for fixing that.

This revision is now accepted and ready to land.Dec 29 2021, 7:30 AM
curdeius accepted this revision.Dec 29 2021, 7:54 AM

LGTM. Thanks for splitting this.

zwliew updated this revision to Diff 396580.Dec 29 2021, 5:14 PM

Rebased on master for context.

This revision was landed with ongoing or failed builds.Jan 3 2022, 2:35 AM
This revision was automatically updated to reflect the committed changes.