Issue 76716
Summary clang-format fails with assertion "`idx < size()' failed"
Labels clang-format
Assignees
Reporter ksdd
    
The archive [files.tar.gz](https://github.com/llvm/llvm-project/files/13810489/files.tar.gz) contains a "_clang-format" configuration file as well as a minimal example C file "crash-example.c". The provided C file compiles both with recent gcc and clang, although both submit some warnings (depending on options). The problem is reproducible with several recent versions of clang-format as well as with a build from latest main branch.

How to reproduce:

Unpack the archive [files.tar.gz](https://github.com/llvm/llvm-project/files/13810489/files.tar.gz) and run:

```
$ tar xzf files.tar.gz
$ clang-format --version
clang-format version 18.0.0git (https://github.com/llvm/llvm-project.git 2eb0ac0b3e3c74875e9b376239a27b8eb389189c)
$ clang-format files/crash-example.c
clang-format: /home/foo/llvm/include/llvm/ADT/SmallVector.h:298: const T& llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::operator[](llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type) const [with T = clang::format::WhitespaceManager::Change; <template-parameter-1-2> = void; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::const_reference = const clang::format::WhitespaceManager::Change&; llvm::SmallVectorTemplateCommon<T, <template-parameter-1-2> >::size_type = long unsigned int]: Assertion `idx < size()' 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 files/crash-example.c
 #0 0x000055accecb5bfe llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /home/foo/llvm/lib/Support/Unix/Signals.inc:723:22
 #1 0x000055accecb600f PrintStackTraceSignalHandler(void*) /home/foo/llvm/lib/Support/Unix/Signals.inc:798:1
 #2 0x000055accecb359a llvm::sys::RunSignalHandlers() /home/foo/llvm/lib/Support/Signals.cpp:105:20
 #3 0x000055accecb54b8 SignalHandler(int) /home/foo/llvm/lib/Support/Unix/Signals.inc:413:1
 #4 0x00007f0cbce16420 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x14420)
 #5 0x00007f0cbc8cf00b raise /build/glibc-wuryBv/glibc-2.31/signal/../sysdeps/unix/sysv/linux/raise.c:51:1
 #6 0x00007f0cbc8ae859 abort /build/glibc-wuryBv/glibc-2.31/stdlib/abort.c:81:7
 #7 0x00007f0cbc8ae729 get_sysdep_segment_value /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:509:8
 #8 0x00007f0cbc8ae729 _nl_load_domain /build/glibc-wuryBv/glibc-2.31/intl/loadmsgcat.c:970:34
 #9 0x00007f0cbc8bffd6 (/lib/x86_64-linux-gnu/libc.so.6+0x33fd6)
#10 0x000055accee397f9 llvm::SmallVectorTemplateCommon<clang::format::WhitespaceManager::Change, void>::operator[](unsigned long) const /home/foo/llvm/include/llvm/ADT/SmallVector.h:299:19
#11 0x000055accee39020 auto clang::format::WhitespaceManager::getNetWidth<clang::format::WhitespaceManager::CellDescription*>(clang::format::WhitespaceManager::CellDescription* const&, clang::format::WhitespaceManager::CellDescription* const&, unsigned int) const /home/foo/clang/lib/Format/WhitespaceManager.h:285:36
#12 0x000055accee39a59 unsigned int clang::format::WhitespaceManager::getMaximumNetWidth<clang::format::WhitespaceManager::CellDescription*>(clang::format::WhitespaceManager::CellDescription* const&, clang::format::WhitespaceManager::CellDescription* const&, unsigned int, unsigned int, unsigned int) const /home/foo/clang/lib/Format/WhitespaceManager.h:325:19
#13 0x000055accee2d617 clang::format::WhitespaceManager::alignArrayInitializersRightJustified(clang::format::WhitespaceManager::CellDescriptions&&) /home/foo/clang/lib/Format/WhitespaceManager.cpp:1310:46
#14 0x000055accee2d2a6 clang::format::WhitespaceManager::alignArrayInitializers(unsigned int, unsigned int) /home/foo/clang/lib/Format/WhitespaceManager.cpp:1272:50
#15 0x000055accee2d1f2 clang::format::WhitespaceManager::alignArrayInitializers() /home/foo/clang/lib/Format/WhitespaceManager.cpp:1258:23
#16 0x000055accee2ac51 clang::format::WhitespaceManager::generateReplacements() /home/foo/clang/lib/Format/WhitespaceManager.cpp:118:18
#17 0x000055acced6db4b clang::format::(anonymous namespace)::Formatter::analyze(clang::format::TokenAnnotator&, llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&, clang::format::FormatTokenLexer&) /home/foo/clang/lib/Format/Format.cpp:2441:59
#18 0x000055accedcb2b6 clang::format::TokenAnalyzer::process(bool) /home/foo/clang/lib/Format/TokenAnalyzer.cpp:132:5
#19 0x000055acced7383f 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*)::'lambda9'(clang::format::Environment const&)::operator()(clang::format::Environment const&) const /home/foo/clang/lib/Format/Format.cpp:3730:12
#20 0x000055acced7ca16 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*)::'lambda9'(clang::format::Environment const&)>::_M_invoke(std::_Any_data const&, clang::format::Environment const&) /usr/include/c++/9/bits/std_function.h:287:7
#21 0x000055acced943da std::function<std::pair<clang::tooling::Replacements, unsigned int> (clang::format::Environment const&)>::operator()(clang::format::Environment const&) const /usr/include/c++/9/bits/std_function.h:689:5
#22 0x000055acced7456d 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*) /home/foo/clang/lib/Format/Format.cpp:3746:49
#23 0x000055acced74b46 clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*) /home/foo/clang/lib/Format/Format.cpp:3788:28
#24 0x000055accebbcbfd clang::format::format(llvm::StringRef, bool) /home/foo/clang/tools/clang-format/ClangFormat.cpp:499:76
#25 0x000055accebbe24d main /home/foo/clang/tools/clang-format/ClangFormat.cpp:692:11
#26 0x00007f0cbc8b0083 __libc_start_main /build/glibc-wuryBv/glibc-2.31/csu/../csu/libc-start.c:342:3
#27 0x000055accebbaa4e _start (/home/foo/build/bin/clang-format+0x349a4e)
```

_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to