[cfe-commits] r173262 - in /cfe/trunk: lib/Format/Format.cpp lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp
Manuel Klimek
klimek at google.com
Wed Jan 23 06:08:21 PST 2013
Author: klimek
Date: Wed Jan 23 08:08:21 2013
New Revision: 173262
URL: http://llvm.org/viewvc/llvm-project?rev=173262&view=rev
Log:
Fixes layouting regression and invalid-read.
Layouting would prevent breaking before + in
a[b + c] = d;
Regression detected by code review.
Also fixes an invalid-read found by the valgrind bot.
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/lib/Format/UnwrappedLineParser.cpp
cfe/trunk/unittests/Format/FormatTest.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=173262&r1=173261&r2=173262&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Jan 23 08:08:21 2013
@@ -1256,8 +1256,10 @@
IsExpression = true;
AnnotatedToken *Previous = Current.Parent;
while (Previous != NULL) {
- if (Previous->Type == TT_BinaryOperator)
+ if (Previous->Type == TT_BinaryOperator &&
+ (Previous->is(tok::star) || Previous->is(tok::amp))) {
Previous->Type = TT_PointerOrReference;
+ }
Previous = Previous->Parent;
}
}
Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=173262&r1=173261&r2=173262&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Wed Jan 23 08:08:21 2013
@@ -38,7 +38,10 @@
}
~ScopedDeclarationState() {
Stack.pop_back();
- Line.MustBeDeclaration = Stack.back();
+ if (!Stack.empty())
+ Line.MustBeDeclaration = Stack.back();
+ else
+ Line.MustBeDeclaration = true;
}
private:
UnwrappedLine &Line;
Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=173262&r1=173261&r2=173262&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Jan 23 08:08:21 2013
@@ -1365,6 +1365,13 @@
verifyGoogleFormat("A = new SomeType* [Length]();");
}
+TEST_F(FormatTest, FormatsBinaryOperatorsPrecedingEquals) {
+ verifyFormat("void f() {\n"
+ " x[aaaaaaaaa -\n"
+ " b] = 23;\n"
+ "}", getLLVMStyleWithColumns(15));
+}
+
TEST_F(FormatTest, FormatsCasts) {
verifyFormat("Type *A = static_cast<Type *>(P);");
verifyFormat("Type *A = (Type *)P;");
More information about the cfe-commits
mailing list