Skip to content

[clang-format] Crash with Whitesmiths and labels in top-level block #50007

@oold

Description

@oold
Bugzilla Link 50663
Resolution FIXED
Resolved on Jun 16, 2021 00:04
Version 12.0
OS All
Blocks #48661
Attachments Zipped goto.cpp and switch.cpp files
CC @mydeveloperday,@oold,@tstellar
Fixed by commit(s) f7f9f94 c7d7ace

Extended Description

Formatting a file with a label within a top-level block causes clang-format to hang for an extended period of time and use a lot of memory. It then proceeds to crash:

PS C:\Users\olive\clang-format-repro> clang-format.exe --style='{BreakBeforeBraces: Whitesmiths}' goto.cpp
PLEASE submit a bug report to https://bugs.llvm.org/ and include the crash backtrace.
Stack dump:
0. Program arguments: "C:\Program Files\LLVM\bin\clang-format.exe" "--style={BreakBeforeBraces: Whitesmiths}" goto.cpp
PS C:\Users\olive\clang-format-repro> cat goto.cpp
int main() {
test:
return 0;
}

No actual backtrace is printed.

I have prepared test cases with both a simple function and a switch statement and both lead to a crash.

My suspicion is that this was caused by the patch that tried to fix case labels with Whitesmiths [1]. This bug does not occur with version 11.0 of clang-format.

[1] https://reviews.llvm.org/D94500

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions