<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/74685>74685</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Segfault in clang::format::reformat
</td>
</tr>
<tr>
<th>Labels</th>
<td>
clang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
equeim
</td>
</tr>
</table>
<pre>
Happened in Qt Creator.
Stacktrace:
```
#0 clang::format::FormatToken::getBlockKind() const (this=0x0) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/FormatToken.h:348
#1 clang::format::FormatToken::is(clang::format::BraceBlockKind) const (this=0x0, BBK=clang::format::BK_BracedInit) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/FormatToken.h:569
#2 clang::format::ContinuationIndenter::getNewLineColumn(clang::format::LineState const&) (this=0x7ffe6fb704b0, State=...) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/ContinuationIndenter.cpp:1175
#3 0x00007f378f299112 in clang::format::ContinuationIndenter::mustBreak(clang::format::LineState const&) (this=0x7ffe6fb704b0, State=...) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/ContinuationIndenter.cpp:443
#4 0x00007f378f302fc0 in clang::format::(anonymous namespace)::NoColumnLimitLineFormatter::formatLine(clang::format::AnnotatedLine const&, unsigned int, unsigned int, bool)
(this=0x7ffe6fb70250, Line=<optimized out>, FirstIndent=<optimized out>, FirstStartColumn=<optimized out>, DryRun=<optimized out>) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/UnwrappedLineFormatter.cpp:1088
#5 0x00007f378f301233 in clang::format::UnwrappedLineFormatter::format(llvm::SmallVectorImpl<clang::format::AnnotatedLine*> const&, bool, int, bool, unsigned int, unsigned int, unsigned int)
(this=0x7ffe6fb70450, Lines=..., DryRun=false, AdditionalIndent=0, FixBadIndentation=false, FirstStartColumn=<optimized out>, NextStartColumn=0, LastStartColumn=0)
at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/UnwrappedLineFormatter.cpp:1378
#6 0x00007f378f2b7c0e in clang::format::(anonymous namespace)::Formatter::analyze(clang::format::TokenAnnotator&, llvm::SmallVectorImpl<clang::format::AnnotatedLine*>&, clang::format::FormatTokenLexer&)
(this=<optimized out>, Annotator=<optimized out>, AnnotatedLines=<optimized out>, Tokens=<optimized out>) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/Format.cpp:2383
#7 0x00007f378f2edab9 in clang::format::TokenAnalyzer::process(bool) (this=0x7ffe6fb72c20, SkipAnnotation=false) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/TokenAnalyzer.cpp:130
#8 0x00007f378f2c7e21 in 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*)::$_9::operator()(clang::format::Environment const&) const (this=<optimized out>, Env=<optimized out>) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/Format.cpp:3671
#9 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*)::$_9&, 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*)::$_9&, clang::format::Environment const&) (__f=<optimized out>, __args=<optimized out>)
at /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:61
#10 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*)::$_9&, 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*)::$_9&, clang::format::Environment const&) (__fn=<optimized out>, __args=<optimized out>) at /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/invoke.h:114
#11 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*)::$_9>::_M_invoke(std::_Any_data const&, clang::format::Environment const&) (__functor=<optimized out>, __args=<optimized out>)
at /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:290
#12 0x00007f378f2b05f2 in std::function<std::pair<clang::tooling::Replacements, unsigned int> (clang::format::Environment const&)>::operator()(clang::format::Environment const&) const (__args=..., this=<optimized out>)
at /usr/bin/../lib/gcc/x86_64-redhat-linux/13/../../../../include/c++/13/bits/std_function.h:591
#13 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*)
(Style=..., Code=..., Ranges=..., FirstStartColumn=0, NextStartColumn=0, LastStartColumn=0, FileName=..., Status=0x7ffe6fb75060) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/Format.cpp:3685
#14 0x00007f378f2b1195 in clang::format::reformat(clang::format::FormatStyle const&, llvm::StringRef, llvm::ArrayRef<clang::tooling::Range>, llvm::StringRef, clang::format::FormattingAttemptStatus*)
(Style=..., Code=..., Ranges=..., FileName=..., Status=0x7ffe6fb75060) at /usr/src/debug/clang-17.0.4-1.fc39.x86_64/lib/Format/Format.cpp:3729
#15 0x00007f37a8f24a54 in ClangFormat::ClangFormatBaseIndenter::replacements(QByteArray, QTextBlock const&, QTextBlock const&, int, ClangFormat::ReplacementsToKeep, QChar const&, bool) const [clone .isra.0]
(this=this@entry=0x56470942d4d0, buffer=..., startBlock=..., endBlock=..., replacementsToKeep=ClangFormat::ReplacementsToKeep::OnlyIndent, typedChar=..., secondTry=false, cursorPositionInEditor=<optimized out>)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/clangformat/clangformatbaseindenter.cpp:538
#16 0x00007f37a8eeeffd in ClangFormat::ClangFormatBaseIndenter::indentsFor(QTextBlock, QTextBlock const&, QChar const&, int, bool)
(this=this@entry=0x56470942d4d0, startBlock=..., endBlock=..., typedChar=..., cursorPositionInEditor=-1, trimTrailingWhitespace=true) at /usr/include/qt6/QtCore/qarraydata.h:52
#17 0x00007f37a8eefe8a in ClangFormat::ClangFormatBaseIndenter::indentationForBlocks(QList<QTextBlock> const&, TextEditor::TabSettings const&, int) (this=0x56470942d4d0, blocks=..., cursorPositionInEditor=<optimized out>)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/clangformat/clangformatbaseindenter.cpp:734
#18 0x00007f37a8f0411b in ClangFormat::ClangFormatForwardingIndenter::indentationForBlocks(QList<QTextBlock> const&, TextEditor::TabSettings const&, int) (this=<optimized out>, blocks=..., tabSettings=..., cursorPositionInEditor=-1)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/clangformat/clangformatindenter.cpp:195
#19 0x00007f37a9b5e688 in TextEditor::TextDocument::cleanWhitespace(QTextCursor&, bool, bool) (this=this@entry=0x5647096713f0, cursor=..., inEntireDocument=false, cleanIndentation=true)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/texteditor/textdocument.cpp:938
#20 0x00007f37a9b61d23 in TextEditor::TextDocument::saveImpl(QString*, Utils::FilePath const&, bool) (this=0x5647096713f0, errorString=0x7ffe6fb75a10, filePath=..., autoSave=<optimized out>)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/texteditor/textdocument.cpp:656
#21 0x00007f37aa053bee in Core::IDocument::save(QString*, Utils::FilePath const&, bool) (this=0x5647096713f0, errorString=0x7ffe6fb75a10, filePath=<optimized out>, autoSave=<optimized out>)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/coreplugin/idocument.cpp:350
#22 0x00007f37a9faceee in Core::DocumentManager::saveDocument(Core::IDocument*, Utils::FilePath const&, bool*) (document=0x5647096713f0, filePath=<optimized out>, isReadOnly=0x7ffe6fb75adf)
at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/coreplugin/documentmanager.cpp:722
#23 0x00007f37a9fce6da in Core::Internal::EditorManagerPrivate::saveDocument(Core::IDocument*) (document=0x5647096713f0) at /usr/src/debug/qt-creator-12.0.0-1.fc39.x86_64/src/plugins/coreplugin/editormanager/editormanager.cpp:2336
#24 0x00007f37d7002011 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffe6fb75c30, r=0x5647068d1140, this=0x5647068e3470) at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobjectdefs_impl.h:433
#25 doActivate<false>(QObject*, int, void**) (sender=0x56470682c8c0, signal_index=7, argv=0x7ffe6fb75c30) at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobject.cpp:4021
#26 0x00007f37d6ff85f7 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**) (sender=<optimized out>, m=m@entry=0x7f37d810e6e0 <QAction::staticMetaObject>, local_signal_index=local_signal_index@entry=4, argv=argv@entry=0x7ffe6fb75c30)
at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobject.cpp:4081
#27 0x00007f37d7e1daa4 in QAction::triggered(bool) (this=<optimized out>, _t1=<optimized out>) at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/redhat-linux-build/src/gui/Gui_autogen/include/moc_qaction.cpp:642
#28 0x00007f37d7002011 in QtPrivate::QSlotObjectBase::call(QObject*, void**) (a=0x7ffe6fb75d50, r=0x56470682c8c0, this=0x564706e8aeb0) at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobjectdefs_impl.h:433
#29 doActivate<false>(QObject*, int, void**) (sender=0x5647068b1440, signal_index=7, argv=0x7ffe6fb75d50) at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobject.cpp:4021
#30 0x00007f37d6ff85f7 in QMetaObject::activate(QObject*, QMetaObject const*, int, void**)
(sender=sender@entry=0x5647068b1440, m=m@entry=0x7f37d810e6e0 <QAction::staticMetaObject>, local_signal_index=local_signal_index@entry=4, argv=argv@entry=0x7ffe6fb75d50)
at /usr/src/debug/qt6-qtbase-6.6.0-6.fc39.x86_64/src/corelib/kernel/qobject.cpp:4081
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsW19z4rjy_TTOCwUlS_7HQx4IhN9vamZndybZex8p2WqDbozEyHI22U9_S5LBNmBIcjPJbFWqUgmWhdx9TvdRS3JoWfKlALj0wisvnF3QSq-kuoQfFfD1RSrZ4-X_080GBLABF4NvejBVQLVUIw_NPDS50TS704pm4JGJa6p_R6j-cZeYoEFWULE0_cgkl2pNtfs8t59v5R0I17AEfVXI7O4zF8zDiYfHg0yKUg88nOgVLz0yQw_INFPTNq9K5eF5qTIPzxmk1dLDc_usoR-P0CgY-qM8I-PRQxItosDD84KnHp675-4-WANGK49MSJDsrPafbDUvPZz0dL4yCLV86nFoOri6-uyRWd8onxd2IPZJcP3z3A-j8c593Of-VArNRUU1l-KTYCA0qB17X-GvL1zAVBbVWvSjYvrcaKrBoeHhyDjVxiTOc4jyNEZBauGxvT0yG41Gr-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