[clang] cb61a5e - [clang-format] Fix an assertion failure in RemoveSemicolon (#117472)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Dec 7 16:47:39 PST 2024
Author: Owen Pan
Date: 2024-12-07T16:47:35-08:00
New Revision: cb61a5e4209beef64b0a3b621c16010c53ed323a
URL: https://github.com/llvm/llvm-project/commit/cb61a5e4209beef64b0a3b621c16010c53ed323a
DIFF: https://github.com/llvm/llvm-project/commit/cb61a5e4209beef64b0a3b621c16010c53ed323a.diff
LOG: [clang-format] Fix an assertion failure in RemoveSemicolon (#117472)
Fixes #117290.
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/lib/Format/TokenAnnotator.h
clang/unittests/Format/FormatTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index bc5239209f3aab..49482973223c64 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -3901,6 +3901,11 @@ bool TokenAnnotator::mustBreakForReturnType(const AnnotatedLine &Line) const {
}
void TokenAnnotator::calculateFormattingInformation(AnnotatedLine &Line) const {
+ if (Line.Computed)
+ return;
+
+ Line.Computed = true;
+
for (AnnotatedLine *ChildLine : Line.Children)
calculateFormattingInformation(*ChildLine);
diff --git a/clang/lib/Format/TokenAnnotator.h b/clang/lib/Format/TokenAnnotator.h
index 5a02030e5ba7f9..9117ca3f9fb7b5 100644
--- a/clang/lib/Format/TokenAnnotator.h
+++ b/clang/lib/Format/TokenAnnotator.h
@@ -182,6 +182,9 @@ class AnnotatedLine {
/// \c True if this line contains a macro call for which an expansion exists.
bool ContainsMacroCall = false;
+ /// \c True if calculateFormattingInformation() has been called on this line.
+ bool Computed = false;
+
/// \c True if this line should be formatted, i.e. intersects directly or
/// indirectly with one of the input ranges.
bool Affected;
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 250e51b5421664..63d8dc2486e45f 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -27386,6 +27386,13 @@ TEST_F(FormatTest, RemoveSemicolon) {
Style);
#endif
+ verifyFormat("auto sgf = [] {\n"
+ " ogl = {\n"
+ " a, b, c, d, e,\n"
+ " };\n"
+ "};",
+ Style);
+
Style.TypenameMacros.push_back("STRUCT");
verifyFormat("STRUCT(T, B) { int i; };", Style);
}
More information about the cfe-commits
mailing list