Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang-format crashes when formatting LLVM itself #53880

Closed
junaire opened this issue Feb 16, 2022 · 6 comments
Closed

clang-format crashes when formatting LLVM itself #53880

junaire opened this issue Feb 16, 2022 · 6 comments
Assignees
Labels
bug Indicates an unexpected problem or unintended behavior clang-format confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]

Comments

@junaire
Copy link
Member

junaire commented Feb 16, 2022

❯ 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

@llvmbot
Copy link
Collaborator

llvmbot commented Feb 16, 2022

@llvm/issue-subscribers-clang-format

@junaire junaire added the crash Prefer [crash-on-valid] or [crash-on-invalid] label Feb 16, 2022
@mkurdej
Copy link
Member

mkurdej commented Feb 16, 2022

Thanks for the report.
What version of clang-format do you use and on which platform?

@junaire
Copy link
Member Author

junaire commented Feb 16, 2022

Thanks for the report. What version of clang-format do you use and on which platform?

clang-format version: clang-format version 15.0.0
FYI, I compile it from source, and I'm in commit: 94c28d2

System version:

Linux Theseus 5.13.0-28-generic #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

@mkurdej
Copy link
Member

mkurdej commented Feb 16, 2022

Got it, thanks, I reproduce now, it's an assertion that I added recently.

I reproduce with a smaller file:

static Optional<size_t> getRecordSize(StringRef segname, StringRef name) {
  if (name == section_names::cfString) {
    if (config->icfLevel != ICFLevel::none && segname == segment_names::data)
      return target->wordSize == 8 ? 32 : 16;
  } else if (name == section_names::compactUnwind) {
    if (segname == segment_names::ld)
      return target->wordSize == 8 ? 32 : 20;
  }
  return {};
}

static Error parseCallGraph(ArrayRef<uint8_t> data,
                            std::vector<CallGraphEntry> &callGraph) {
}

and

clang-format -lines=5:7 InputFiles.cpp

@mkurdej
Copy link
Member

mkurdej commented Feb 16, 2022

And even with clang-format -lines=4:4 InputFiles.cpp:

void f() {
  return a == 8 ? 32 : 16;
}

@mkurdej mkurdej added bug Indicates an unexpected problem or unintended behavior confirmed Verified by a second party and removed new issue labels Feb 16, 2022
@mkurdej mkurdej self-assigned this Feb 16, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Feb 16, 2022

@llvm/issue-subscribers-bug

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior clang-format confirmed Verified by a second party crash Prefer [crash-on-valid] or [crash-on-invalid]
Projects
None yet
Development

No branches or pull requests

3 participants