<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - clang-format crash: Assertion `idx < size()' failed"
href="https://bugs.llvm.org/show_bug.cgi?id=51343">51343</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang-format crash: Assertion `idx < size()' failed
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Formatter
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>a.b@kaze.ch
</td>
</tr>
<tr>
<th>CC</th>
<td>djasper@google.com, klimek@google.com, llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>Using clang-format from git repository llvm-project at revision
735da5f5ad74ad139d3287c897be2057203a6032
When I try to format the code I attached to this issue, clang-format crashes
with the following backtrace:
clang-format:
/home/user/.local/src/llvm-project/llvm/include/llvm/ADT/SmallVector.h:281:
llvm::SmallVectorTemplateCommon::const_reference
llvm::SmallVectorTemplateCommon<clang::format::WhitespaceManager::Change>::operator[](llvm::SmallVectorTemplateCommon::size_type)
const [T = clang::format::WhitespaceManager::Change]: Assertion `idx < size()'
failed.
PLEASE submit a bug report to <a href="https://bugs.llvm.org/">https://bugs.llvm.org/</a> and include the crash
backtrace.
Stack dump:
0. Program arguments: /home/user/.local/llvm-git/bin/clang-format
inc/basic_widgets/core/math.hpp
#0 0x0000000000505d9a llvm::sys::PrintStackTrace(llvm::raw_ostream&, int)
/home/user/.local/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:565:11
#1 0x0000000000505f4b PrintStackTraceSignalHandler(void*)
/home/user/.local/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:632:1
#2 0x0000000000504613 llvm::sys::RunSignalHandlers()
/home/user/.local/src/llvm-project/llvm/lib/Support/Signals.cpp:97:5
#3 0x0000000000506675 SignalHandler(int)
/home/user/.local/src/llvm-project/llvm/lib/Support/Unix/Signals.inc:407:1
#4 0x00007fe42b69d3f0 __restore_rt sigaction.c:0:0
#5 0x00007fe42b176b41 raise
/usr/src/debug/sys-libs/glibc-2.33-r1/glibc-2.33/signal/../sysdeps/unix/sysv/linux/raise.c:50:1
#6 0x00007fe42b160538 abort
/usr/src/debug/sys-libs/glibc-2.33-r1/glibc-2.33/stdlib/abort.c:81:7
#7 0x00007fe42b160421 get_sysdep_segment_value
/usr/src/debug/sys-libs/glibc-2.33-r1/glibc-2.33/intl/loadmsgcat.c:509:8
#8 0x00007fe42b160421 _nl_load_domain
/usr/src/debug/sys-libs/glibc-2.33-r1/glibc-2.33/intl/loadmsgcat.c:970:34
#9 0x00007fe42b16f412 (/lib64/libc.so.6+0x31412)
#10 0x000000000062c0d9
llvm::SmallVectorTemplateCommon<clang::format::WhitespaceManager::Change,
void>::operator[](unsigned long) const
/home/user/.local/src/llvm-project/llvm/include/llvm/ADT/SmallVector.h:0:5
#11 0x000000000062bc72 auto
clang::format::WhitespaceManager::getNetWidth<clang::format::WhitespaceManager::CellDescription*>(clang::format::WhitespaceManager::CellDescription*
const&, clang::format::WhitespaceManager::CellDescription* const&, unsigned
int) const
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.h:267:51
#12 0x000000000062be5d unsigned int
clang::format::WhitespaceManager::getMaximumNetWidth<clang::format::WhitespaceManager::CellDescription*>(clang::format::WhitespaceManager::CellDescription*
const&, clang::format::WhitespaceManager::CellDescription* const&, unsigned
int, unsigned int) const
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.h:305:33
#13 0x000000000062498c
clang::format::WhitespaceManager::alignArrayInitializersRightJustified(clang::format::WhitespaceManager::CellDescriptions&&)
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.cpp:1022:14
#14 0x0000000000624727
clang::format::WhitespaceManager::alignArrayInitializers(unsigned int, unsigned
int)
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.cpp:989:5
#15 0x0000000000621fef
clang::format::WhitespaceManager::alignArrayInitializers()
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.cpp:975:25
#16 0x000000000062099b clang::format::WhitespaceManager::generateReplacements()
/home/user/.local/src/llvm-project/clang/lib/Format/WhitespaceManager.cpp:105:3
#17 0x000000000059fc8f clang::format::(anonymous
namespace)::Formatter::analyze(clang::format::TokenAnnotator&,
llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&,
clang::format::FormatTokenLexer&)
/home/user/.local/src/llvm-project/clang/lib/Format/Format.cpp:1706:26
#18 0x00000000005d9c8b clang::format::TokenAnalyzer::process()
/home/user/.local/src/llvm-project/clang/lib/Format/TokenAnalyzer.cpp:93:5
#19 0x00000000005a50e9
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*)::$_6::operator()(clang::format::Environment
const&) const
/home/user/.local/src/llvm-project/clang/lib/Format/Format.cpp:2875:5
#20 0x00000000005a5075 std::pair<clang::tooling::Replacements, unsigned int>
std::__invoke_impl<std::pair<clang::tooling::Replacements, unsigned int>,
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*)::$_6&, clang::format::Environment
const&>(std::__invoke_other,
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*)::$_6&, clang::format::Environment
const&)
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/bits/invoke.h:60:14
#21 0x00000000005a4ff5
std::enable_if<__and_<std::__not_<std::is_void<std::pair<clang::tooling::Replacements,
unsigned int> > >,
std::is_convertible<std::__invoke_result<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*)::$_6&, clang::format::Environment
const&>::type, std::pair<clang::tooling::Replacements, unsigned int> >
<span class="quote">>::value, std::pair<clang::tooling::Replacements, unsigned int> >::type</span >
std::__invoke_r<std::pair<clang::tooling::Replacements, unsigned int>,
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*)::$_6&, 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*)::$_6&, clang::format::Environment
const&)
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/bits/invoke.h:141:14
#22 0x00000000005a4ec5
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*)::$_6>::_M_invoke(std::_Any_data
const&, clang::format::Environment const&)
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/bits/std_function.h:291:9
#23 0x00000000005a7638 std::function<std::pair<clang::tooling::Replacements,
unsigned int> (clang::format::Environment
const&)>::operator()(clang::format::Environment const&) const
/usr/lib/gcc/x86_64-pc-linux-gnu/10.3.0/include/g++-v10/bits/std_function.h:622:14
#24 0x00000000005982cb
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/user/.local/src/llvm-project/clang/lib/Format/Format.cpp:2893:9
#25 0x0000000000598a7f clang::format::reformat(clang::format::FormatStyle
const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>,
llvm::StringRef, clang::format::FormattingAttemptStatus*)
/home/user/.local/src/llvm-project/clang/lib/Format/Format.cpp:2915:10
#26 0x00000000004172c9 clang::format::format(llvm::StringRef)
/home/user/.local/src/llvm-project/clang/tools/clang-format/ClangFormat.cpp:435:23
#27 0x00000000004163df main
/home/user/.local/src/llvm-project/clang/tools/clang-format/ClangFormat.cpp:551:14
#28 0x00007fe42b1617fd __libc_start_main
/usr/src/debug/sys-libs/glibc-2.33-r1/glibc-2.33/csu/../csu/libc-start.c:332:16
#29 0x0000000000415eda _start
(/home/user/.local/llvm-git/bin/clang-format+0x415eda)
clang-format config:
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignArrayOfStructures: Right
AlignConsecutiveAssignments: AcrossComments
AlignConsecutiveBitFields: AcrossComments
AlignConsecutiveDeclarations: AcrossComments
AlignConsecutiveMacros: AcrossComments
AlignOperands: AlignAfterOperator
AllowShortBlocksOnASingleLine: Always
AllowShortFunctionsOnASingleLine: Inline
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLoopsOnASingleLine: true
AlwaysBreakTemplateDeclarations: Yes
BraceWrapping:
AfterClass: true
AfterControlStatement: MultiLine
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterStruct: true
AfterUnion: true
BeforeElse: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Custom
BreakInheritanceList: AfterComma
ColumnLimit: 89
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
EmptyLineBeforeAccessModifier: Always
FixNamespaceComments: false
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '<[[:alnum:].]+>'
Priority: -10
- Regex: '^<fontconfig/'
Priority: -5
- Regex: '^<SDL2/'
Priority: -5
- Regex: '^<basic_widgets/'
Priority: 0
- Regex: '^".*"$'
Priority: 5
IndentCaseLabels: true
IndentExternBlock: true
IndentGotoLabels: false
IndentRequires: true
IndentWidth: 4
KeepEmptyLinesAtTheStartOfBlocks: false
Language: Cpp
NamespaceIndentation: All
PointerAlignment: Left
SortIncludes: CaseInsensitive
SpaceAfterTemplateKeyword: false
SpaceBeforeCpp11BracedList: true
SpaceBeforeParens: ControlStatementsExceptControlMacros
Standard: c++20
TabWidth: 4
math.hpp:
#ifndef BWIDGETS_MATH_HPP
#define BWIDGETS_MATH_HPP
#include <algorithm>
#include <cmath>
#include <SDL2/SDL_rect.h>
#include <basic_widgets/core/type/color.hpp>
#include <basic_widgets/core/type/concepts.hpp>
#include <basic_widgets/core/type/size.hpp>
namespace bwidgets::core
{
static inline auto center_line(int available_len, int used_len) noexcept ->
int
{
return (available_len - used_len) / 2;
}
static inline auto distance_sqrd(const SDL_Point& a, const SDL_Point& b)
noexcept
-> float
{
return (a.x - b.x) * (a.x - b.x) //
NOLINT(bugprone-narrowing-conversions)
+ (a.y - b.y) * (a.y - b.y);
}
static inline auto distance(const SDL_Point& a, const SDL_Point& b)
noexcept -> float
{
return std::sqrt(distance_sqrd(a, b));
}
template<FloatingPoint F>
static inline auto lerp(const Color& a, const Color& b, F x, bool
op_alpha=false, bool op_color=true) -> Color
{
return {{
op_color ? (uint8_t)std::lerp(a.r, b.r, x) : a.r,
op_color ? (uint8_t)std::lerp(a.g, b.g, x) : a.g,
op_color ? (uint8_t)std::lerp(a.b, b.b, x) : a.b,
op_alpha ? (uint8_t)std::lerp(a.a, b.a, x) : a.a,
}};
}
template<Numeric N>
static inline auto linear(N x, N a, N b) noexcept -> float
{
return (float)(x - a) / (float)(b - a);
}
static inline auto rect_in_rect(const SDL_Rect outer, const SDL_Rect inner)
noexcept
-> bool
{
SDL_Point top_left {inner.x, inner.y};
SDL_Point bottom_right {inner.x + inner.w, inner.y + inner.h};
return (SDL_PointInRect(&top_left, &outer) == SDL_TRUE)
&& (SDL_PointInRect(&bottom_right, &outer) == SDL_TRUE);
}
static inline auto rect_margin(const SDL_Rect& r, const Size& margin)
noexcept
-> SDL_Rect
{
return {r.x + margin.w, r.y + margin.h, r.w - 2 * margin.w, r.h - 2 *
margin.h};
}
static inline auto rect_offset(const SDL_Rect& r, const SDL_Point& offset)
noexcept
-> SDL_Rect
{
return {r.x + offset.x, r.y + offset.y, r.w, r.h};
}
static inline auto rect_offset(const SDL_Rect& r, const SDL_Rect& offset)
noexcept
-> SDL_Rect
{
return rect_offset(r, SDL_Point {offset.x, offset.y});
}
template<Numeric N>
static inline auto smoothstep(N x, N a, N b) noexcept -> float
{
const float x_norm = linear(std::clamp<float>(x, a, b), a, b);
return 3 * x_norm * x_norm - 2 * x_norm * x_norm * x_norm;
}
}
#endif</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>