Skip to content

clang-format crashes when formatting LLVM itself #53880

@junaire

Description

@junaire
❯ clang-format -lines=265:282 -lines=341:342 lld/MachO/InputFiles.cpp
clang-format: /home/jun/dev/llvm-project/clang/lib/Format/WhitespaceManager.cpp:409: void clang::format::AlignTokenSequence(const clang::format::FormatStyle&, unsigned int, unsigned int, unsigned int, F&&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16>&) [with F = clang::format::WhitespaceManager::alignChainedConditionals()::<lambda(const clang::format::WhitespaceManager::Change&)>&]: Assertion `Changes[i].NewlinesBefore > 0 || Changes[i].Spaces >= static_cast<int>(Changes[i].Tok->SpacesRequiredBefore) || Changes[i].Tok->is(tok::eof)' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.	Program arguments: clang-format -lines=265:282 -lines=341:342 lld/MachO/InputFiles.cpp
 #0 0x00007f4f81ddec04 PrintStackTraceSignalHandler(void*) Signals.cpp:0:0
 #1 0x00007f4f81ddc32e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007f4f817d6210 (/lib/x86_64-linux-gnu/libc.so.6+0x46210)
 #3 0x00007f4f817d618b raise /build/glibc-eX1tMB/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #4 0x00007f4f817b5859 abort /build/glibc-eX1tMB/glibc-2.31/stdlib/abort.c:81:7
 #5 0x00007f4f817b5729 get_sysdep_segment_value /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:509:8
 #6 0x00007f4f817b5729 _nl_load_domain /build/glibc-eX1tMB/glibc-2.31/intl/loadmsgcat.c:970:34
 #7 0x00007f4f817c6f36 (/lib/x86_64-linux-gnu/libc.so.6+0x36f36)
 #8 0x00007f4f82698adf void clang::format::AlignTokenSequence<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, unsigned int, unsigned int, unsigned int, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&) (.isra.0) WhitespaceManager.cpp:0:0
 #9 0x00007f4f8269a7a2 unsigned int clang::format::AlignTokens<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&, unsigned int, clang::format::FormatStyle::AlignConsecutiveStyle const&) WhitespaceManager.cpp:0:0
#10 0x00007f4f8269a731 unsigned int clang::format::AlignTokens<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&, unsigned int, clang::format::FormatStyle::AlignConsecutiveStyle const&) WhitespaceManager.cpp:0:0
#11 0x00007f4f8269a731 unsigned int clang::format::AlignTokens<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&, unsigned int, clang::format::FormatStyle::AlignConsecutiveStyle const&) WhitespaceManager.cpp:0:0
#12 0x00007f4f8269a731 unsigned int clang::format::AlignTokens<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&, unsigned int, clang::format::FormatStyle::AlignConsecutiveStyle const&) WhitespaceManager.cpp:0:0
#13 0x00007f4f8269a731 unsigned int clang::format::AlignTokens<clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&>(clang::format::FormatStyle const&, clang::format::WhitespaceManager::alignChainedConditionals()::'lambda'(clang::format::WhitespaceManager::Change const&)&, llvm::SmallVector<clang::format::WhitespaceManager::Change, 16u>&, unsigned int, clang::format::FormatStyle::AlignConsecutiveStyle const&) WhitespaceManager.cpp:0:0
#14 0x00007f4f8269fcaf clang::format::WhitespaceManager::alignChainedConditionals() (/usr/local/bin/../lib/libclangFormat.so.15git+0xe7caf)
#15 0x00007f4f826a7944 clang::format::WhitespaceManager::generateReplacements() (/usr/local/bin/../lib/libclangFormat.so.15git+0xef944)
#16 0x00007f4f826280ce clang::format::(anonymous namespace)::Formatter::analyze(clang::format::TokenAnnotator&, llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&, clang::format::FormatTokenLexer&) Format.cpp:0:0
#17 0x00007f4f82660f10 clang::format::TokenAnalyzer::process() (/usr/local/bin/../lib/libclangFormat.so.15git+0xa8f10)
#18 0x00007f4f826173a8 clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*)::'lambda5'(clang::format::Environment const&)::operator()(clang::format::Environment const&) const (.isra.0) Format.cpp:0:0
#19 0x00007f4f8261740c std::_Function_handler<std::pair<clang::tooling::Replacements, unsigned int> (clang::format::Environment const&), clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*)::'lambda5'(clang::format::Environment const&)>::_M_invoke(std::_Any_data const&, clang::format::Environment const&) Format.cpp:0:0
#20 0x00007f4f8262474b clang::format::internal::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, unsigned int, unsigned int, unsigned int, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/usr/local/bin/../lib/libclangFormat.so.15git+0x6c74b)
#21 0x00007f4f82625feb clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) (/usr/local/bin/../lib/libclangFormat.so.15git+0x6dfeb)
#22 0x000055d3fffbe579 clang::format::format(llvm::StringRef) ClangFormat.cpp:0:0
#23 0x000055d3fffc09a2 main (/usr/local/bin/clang-format+0x179a2)
#24 0x00007f4f817b70b3 __libc_start_main /build/glibc-eX1tMB/glibc-2.31/csu/../csu/libc-start.c:342:3
#25 0x000055d3fffb330e _start (/usr/local/bin/clang-format+0xa30e)
[1]    119524 abort (core dumped)  clang-format -lines=265:282 -lines=341:342 lld/MachO/InputFiles.cpp

Current commit: 94c28d2

Metadata

Metadata

Assignees

Labels

bugIndicates an unexpected problem or unintended behaviorclang-formatconfirmedVerified by a second partycrashPrefer [crash-on-valid] or [crash-on-invalid]

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions