r193352 - clang-format: Properly reset nested AnnotatedLine structure.
Daniel Jasper
djasper at google.com
Thu Oct 24 08:23:11 PDT 2013
Author: djasper
Date: Thu Oct 24 10:23:11 2013
New Revision: 193352
URL: http://llvm.org/viewvc/llvm-project?rev=193352&view=rev
Log:
clang-format: Properly reset nested AnnotatedLine structure.
This fixes llvm.org/PR17682.
Without this patch, the following code leads to invalid reads/writes:
DEBUG({
return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;
});
#if a
#else
#endif
Because of the #if-#else structure, the code is formatted and annotated
twice and becauce of the nested block, the annotated lines form a
hierarchical structure. This structure was not properly reset between
runs.
Modified:
cfe/trunk/lib/Format/TokenAnnotator.h
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/TokenAnnotator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=193352&r1=193351&r2=193352&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.h Thu Oct 24 10:23:11 2013
@@ -56,6 +56,7 @@ public:
Current->Next = I->Tok;
I->Tok->Previous = Current;
Current = Current->Next;
+ Current->Children.clear();
for (SmallVectorImpl<UnwrappedLine>::const_iterator
I = Node.Children.begin(),
E = Node.Children.end();
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=193352&r1=193351&r2=193352&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Thu Oct 24 10:23:11 2013
@@ -2333,6 +2333,13 @@ TEST_F(FormatTest, LayoutStatementsAroun
"#if 1\n"
"#else\n"
"#endif\n");
+ verifyFormat("DEBUG({\n"
+ " return aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +\n"
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa;\n"
+ "});\n"
+ "#if a\n"
+ "#else\n"
+ "#endif");
}
TEST_F(FormatTest, FormatsJoinedLinesOnSubsequentRuns) {
More information about the cfe-commits
mailing list