<div dir="ltr">Fixed in r178779.</div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, Apr 4, 2013 at 10:22 AM, Alexey Samsonov <span dir="ltr"><<a href="mailto:samsonov@google.com" target="_blank">samsonov@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi Daniel!<div><br></div><div>Greetings from out llvm-bootstrap bot:</div><div><div>[ RUN ] FormatTest.IncorrectCodeUnbalancedBraces</div>
<div>=================================================================</div>
<div>==3759==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x60400000340c at pc 0x6fad44 bp 0x7ffff8a7d310 sp 0x7ffff8a7d308</div><div>READ of size 4 at 0x60400000340c thread T0</div><div> #0 0x6fad43 in clang::format::UnwrappedLineFormatter::moveStateToNextToken(clang::format::UnwrappedLineFormatter::LineState&, bool) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:930</div>
<div> #1 0x6fc95f in clang::format::UnwrappedLineFormatter::addTokenToState(bool, bool, clang::format::UnwrappedLineFormatter::LineState&) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:853</div><div> #2 0x6f5d5b in clang::format::UnwrappedLineFormatter::format(clang::format::AnnotatedLine const*) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:509</div>
<div> #3 0x6ecb07 in clang::format::Formatter::format() /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:1422</div><div> #4 0x6eaa31 in clang::format::reformat(clang::format::FormatStyle const&, clang::Lexer&, clang::SourceManager&, std::vector<clang::CharSourceRange, std::allocator<clang::CharSourceRange> >, clang::DiagnosticConsumer*) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:1739</div>
<div> #5 0x588132 in clang::format::FormatTest::format(llvm::StringRef, unsigned int, unsigned int, clang::format::FormatStyle const&) /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:35</div><div>
#6 0x586f6b in str /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:45</div><div> #7 0x586f6b in clang::format::FormatTest::verifyFormat(llvm::StringRef, clang::format::FormatStyle const&) /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:95</div>
<div> #8 0x55de08 in clang::format::FormatTest_IncorrectCodeUnbalancedBraces_Test::TestBody() /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:94</div><div> #9 0x67af37 in testing::Test::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2161</div>
<div> #10 0x67f7d4 in testing::TestInfo::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2309</div><div> #11 0x680cb2 in testing::TestCase::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2416</div>
<div> #12 0x69b1e2 in testing::internal::UnitTestImpl::RunAllTests() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:4205</div><div> #13 0x69a6f0 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2145</div>
<div> #14 0x69a6f0 in testing::UnitTest::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:3840</div><div> #15 0x6e95da in main /usr/local/google/llvm/utils/unittest/UnitTestMain/TestMain.cpp:43</div>
<div>
#16 0x2b63d03f976c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)</div><div> #17 0x51b1cc (/usr/local/google/llvm_bootstrap_clang_asan/tools/clang/unittests/Format/FormatTests+0x51b1cc)</div><div>0x60400000340c is located 4 bytes to the left of 44-byte region [0x604000003410,0x60400000343c)</div>
<div>allocated by thread T0 here:</div><div> #0 0x50da22 in operator new(unsigned long) /usr/local/google/llvm/projects/compiler-rt/lib/asan/asan_new_delete.cc:52</div><div> #1 0x705782 in allocate /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/ext/new_allocator.h:92</div>
<div> #2 0x705782 in _M_allocate /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/stl_vector.h:150</div><div> #3 0x705782 in std::vector<clang::format::UnwrappedLineFormatter::ParenState, std::allocator<clang::format::UnwrappedLineFormatter::ParenState> >::_M_insert_aux(__gnu_cxx::__normal_iterator<clang::format::UnwrappedLineFormatter::ParenState*, std::vector<clang::format::UnwrappedLineFormatter::ParenState, std::allocator<clang::format::UnwrappedLineFormatter::ParenState> > >, clang::format::UnwrappedLineFormatter::ParenState const&) /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/vector.tcc:327</div>
<div> #4 0x6f5a3e in ParenState /usr/lib/gcc/x86_64-linux-gnu/4.6/../../../../include/c++/4.6/bits/stl_vector.h:834</div><div> #5 0x6f5a3e in clang::format::UnwrappedLineFormatter::format(clang::format::AnnotatedLine const*) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:487</div>
<div> #6 0x6ecb07 in clang::format::Formatter::format() /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:1422</div><div> #7 0x6eaa31 in clang::format::reformat(clang::format::FormatStyle const&, clang::Lexer&, clang::SourceManager&, std::vector<clang::CharSourceRange, std::allocator<clang::CharSourceRange> >, clang::DiagnosticConsumer*) /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:1739</div>
<div> #8 0x588132 in clang::format::FormatTest::format(llvm::StringRef, unsigned int, unsigned int, clang::format::FormatStyle const&) /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:35</div><div>
#9 0x586f6b in str /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:45</div><div> #10 0x586f6b in clang::format::FormatTest::verifyFormat(llvm::StringRef, clang::format::FormatStyle const&) /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:95</div>
<div> #11 0x55de08 in clang::format::FormatTest_IncorrectCodeUnbalancedBraces_Test::TestBody() /usr/local/google/llvm/tools/clang/unittests/Format/FormatTest.cpp:94</div><div> #12 0x67af37 in testing::Test::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2161</div>
<div> #13 0x67f7d4 in testing::TestInfo::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2309</div><div> #14 0x680cb2 in testing::TestCase::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2416</div>
<div> #15 0x69b1e2 in testing::internal::UnitTestImpl::RunAllTests() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:4205</div><div> #16 0x69a6f0 in HandleExceptionsInMethodIfSupported<testing::internal::UnitTestImpl, bool> /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:2145</div>
<div> #17 0x69a6f0 in testing::UnitTest::Run() /usr/local/google/llvm/utils/unittest/googletest/gtest.cc:3840</div><div> #18 0x6e95da in main /usr/local/google/llvm/utils/unittest/UnitTestMain/TestMain.cpp:43</div>
<div>
#19 0x2b63d03f976c (/lib/x86_64-linux-gnu/libc.so.6+0x2176c)</div><div>SUMMARY: AddressSanitizer: heap-buffer-overflow /usr/local/google/llvm/tools/clang/lib/Format/Format.cpp:931 clang::format::UnwrappedLineFormatter::moveStateToNextToken(clang::format::UnwrappedLineFormatter::LineState&, bool)</div>
<div><br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div class="h5">On Wed, Apr 3, 2013 at 5:36 PM, Daniel Jasper <span dir="ltr"><<a href="mailto:djasper@google.com" target="_blank">djasper@google.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: djasper<br>
Date: Wed Apr 3 08:36:17 2013<br>
New Revision: 178641<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=178641&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=178641&view=rev</a><br>
Log:<br>
Improve formatting of for loops and multi-variable DeclStmts.<br>
<br>
This combines several related changes:<br>
a) Don't break before after the variable types in for loops with a<br>
single variable.<br>
b) Better indent DeclStmts defining multiple variables.<br>
<br>
Before:<br>
bool aaaaaaaaaaaaaaaaaaaaaaaaa =<br>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),<br>
bbbbbbbbbbbbbbbbbbbbbbbbb =<br>
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);<br>
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa<br>
aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;<br>
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {<br>
}<br>
<br>
After:<br>
bool aaaaaaaaaaaaaaaaaaaaaaaaa =<br>
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),<br>
bbbbbbbbbbbbbbbbbbbbbbbbb =<br>
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);<br>
for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =<br>
aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;<br>
aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {<br>
}<br>
<br>
Modified:<br>
cfe/trunk/lib/Format/Format.cpp<br>
cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
cfe/trunk/lib/Format/TokenAnnotator.h<br>
cfe/trunk/unittests/Format/FormatTest.cpp<br>
<br>
Modified: cfe/trunk/lib/Format/Format.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=178641&r1=178640&r2=178641&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=178641&r1=178640&r2=178641&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/Format.cpp (original)<br>
+++ cfe/trunk/lib/Format/Format.cpp Wed Apr 3 08:36:17 2013<br>
@@ -487,7 +487,6 @@ public:<br>
State.Stack.push_back(<br>
ParenState(FirstIndent, FirstIndent, !Style.BinPackParameters,<br>
/*HasMultiParameterLine=*/ false));<br>
- State.VariablePos = 0;<br>
State.LineContainsContinuedForLoopSection = false;<br>
State.ParenLevel = 0;<br>
State.StartOfStringLiteral = 0;<br>
@@ -537,7 +536,7 @@ private:<br>
AvoidBinPacking(AvoidBinPacking), BreakBeforeParameter(false),<br>
HasMultiParameterLine(HasMultiParameterLine), ColonPos(0),<br>
StartOfFunctionCall(0), NestedNameSpecifierContinuation(0),<br>
- CallContinuation(0) {}<br>
+ CallContinuation(0), VariablePos(0) {}<br>
<br>
/// \brief The position to which a specific parenthesis level needs to be<br>
/// indented.<br>
@@ -591,6 +590,11 @@ private:<br>
/// contains the start column of the second line. Otherwise 0.<br>
unsigned CallContinuation;<br>
<br>
+ /// \brief The column of the first variable name in a variable declaration.<br>
+ ///<br>
+ /// Used to align further variables if necessary.<br>
+ unsigned VariablePos;<br>
+<br>
bool operator<(const ParenState &Other) const {<br>
if (Indent != Other.Indent)<br>
return Indent < Other.Indent;<br>
@@ -618,6 +622,8 @@ private:<br>
Other.NestedNameSpecifierContinuation;<br>
if (CallContinuation != Other.CallContinuation)<br>
return CallContinuation < Other.CallContinuation;<br>
+ if (VariablePos != Other.VariablePos)<br>
+ return VariablePos < Other.VariablePos;<br>
return false;<br>
}<br>
};<br>
@@ -632,11 +638,6 @@ private:<br>
/// \brief The token that needs to be next formatted.<br>
const AnnotatedToken *NextToken;<br>
<br>
- /// \brief The column of the first variable name in a variable declaration.<br>
- ///<br>
- /// Used to align further variables if necessary.<br>
- unsigned VariablePos;<br>
-<br>
/// \brief \c true if this line contains a continued for-loop section.<br>
bool LineContainsContinuedForLoopSection;<br>
<br>
@@ -660,8 +661,6 @@ private:<br>
return NextToken < Other.NextToken;<br>
if (Column != Other.Column)<br>
return Column < Other.Column;<br>
- if (VariablePos != Other.VariablePos)<br>
- return VariablePos < Other.VariablePos;<br>
if (LineContainsContinuedForLoopSection !=<br>
Other.LineContainsContinuedForLoopSection)<br>
return LineContainsContinuedForLoopSection;<br>
@@ -727,10 +726,9 @@ private:<br>
}<br>
} else if (Current.Type == TT_ConditionalExpr) {<br>
State.Column = State.Stack.back().QuestionColumn;<br>
- } else if (Previous.is(tok::comma) && State.VariablePos != 0 &&<br>
- ((RootToken.is(tok::kw_for) && State.ParenLevel == 1) ||<br>
- State.ParenLevel == 0)) {<br>
- State.Column = State.VariablePos;<br>
+ } else if (Previous.is(tok::comma) &&<br>
+ State.Stack.back().VariablePos != 0) {<br>
+ State.Column = State.Stack.back().VariablePos;<br>
} else if (Previous.ClosesTemplateDeclaration ||<br>
(Current.Type == TT_StartOfName && State.ParenLevel == 0)) {<br>
State.Column = State.Stack.back().Indent;<br>
@@ -799,10 +797,13 @@ private:<br>
State.Stack.back().BreakBeforeParameter = true;<br>
}<br>
} else {<br>
- // FIXME: Put VariablePos into ParenState and remove second part of if().<br>
if (Current.is(tok::equal) &&<br>
- (RootToken.is(tok::kw_for) || State.ParenLevel == 0))<br>
- State.VariablePos = State.Column - Previous.FormatTok.TokenLength;<br>
+ (RootToken.is(tok::kw_for) || State.ParenLevel == 0)) {<br>
+ State.Stack.back().VariablePos =<br>
+ State.Column - Previous.FormatTok.TokenLength;<br>
+ if (Previous.PartOfMultiVariableDeclStmt)<br>
+ State.Stack.back().LastSpace = State.Stack.back().VariablePos;<br>
+ }<br>
<br>
unsigned Spaces = State.NextToken->SpacesRequiredBefore;<br>
<br>
@@ -828,7 +829,7 @@ private:<br>
State.Stack.back().HasMultiParameterLine = true;<br>
<br>
State.Column += Spaces;<br>
- if (Current.is(tok::l_paren) && Previous.is(tok::kw_if))<br>
+ if (Current.is(tok::l_paren) && Previous.isOneOf(tok::kw_if, tok::kw_for))<br>
// Treat the condition inside an if as if it was a second function<br>
// parameter, i.e. let nested calls have an indent of 4.<br>
State.Stack.back().LastSpace = State.Column + 1; // 1 is length of "(".<br>
@@ -926,9 +927,11 @@ private:<br>
}<br>
<br>
// Remove scopes created by fake parenthesis.<br>
+ unsigned VariablePos = State.Stack.back().VariablePos;<br></blockquote><div><br></div></div></div><div>looks like State.Stack may be empty at this point.</div><div><div class="h5"><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
for (unsigned i = 0, e = Current.FakeRParens; i != e; ++i) {<br>
State.Stack.pop_back();<br>
}<br>
+ State.Stack.back().VariablePos = VariablePos;<br>
<br>
if (Current.is(tok::string_literal)) {<br>
State.StartOfStringLiteral = State.Column;<br>
<br>
Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=178641&r1=178640&r2=178641&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=178641&r1=178640&r2=178641&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)<br>
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Apr 3 08:36:17 2013<br>
@@ -408,6 +408,10 @@ private:<br>
Tok->FormatTok.Tok.getIdentifierInfo() == &Ident_in)<br>
Tok->Type = TT_ObjCForIn;<br>
break;<br>
+ case tok::comma:<br>
+ if (Contexts.back().FirstStartOfName)<br>
+ Contexts.back().FirstStartOfName->PartOfMultiVariableDeclStmt = true;<br>
+ break;<br>
default:<br>
break;<br>
}<br>
@@ -538,7 +542,8 @@ private:<br>
: ContextKind(ContextKind), BindingStrength(BindingStrength),<br>
LongestObjCSelectorName(0), ColonIsForRangeExpr(false),<br>
ColonIsObjCMethodExpr(false), FirstObjCSelectorName(NULL),<br>
- IsExpression(IsExpression), CanBeExpression(true) {}<br>
+ FirstStartOfName(NULL), IsExpression(IsExpression),<br>
+ CanBeExpression(true) {}<br>
<br>
tok::TokenKind ContextKind;<br>
unsigned BindingStrength;<br>
@@ -546,6 +551,7 @@ private:<br>
bool ColonIsForRangeExpr;<br>
bool ColonIsObjCMethodExpr;<br>
AnnotatedToken *FirstObjCSelectorName;<br>
+ AnnotatedToken *FirstStartOfName;<br>
bool IsExpression;<br>
bool CanBeExpression;<br>
};<br>
@@ -600,8 +606,10 @@ private:<br>
((Current.Parent->is(tok::identifier) &&<br>
Current.Parent->FormatTok.Tok.getIdentifierInfo()<br>
->getPPKeywordID() == tok::pp_not_keyword) ||<br>
+ isSimpleTypeSpecifier(*Current.Parent) ||<br>
Current.Parent->Type == TT_PointerOrReference ||<br>
Current.Parent->Type == TT_TemplateCloser)) {<br>
+ Contexts.back().FirstStartOfName = &Current;<br>
Current.Type = TT_StartOfName;<br>
} else if (Current.isOneOf(tok::star, tok::amp, tok::ampamp)) {<br>
Current.Type =<br>
@@ -720,6 +728,39 @@ private:<br>
return TT_UnaryOperator;<br>
}<br>
<br>
+ // FIXME: This is copy&pasted from Sema. Put it in a common place and remove<br>
+ // duplication.<br>
+ /// \brief Determine whether the token kind starts a simple-type-specifier.<br>
+ bool isSimpleTypeSpecifier(const AnnotatedToken &Tok) const {<br>
+ switch (Tok.FormatTok.Tok.getKind()) {<br>
+ case tok::kw_short:<br>
+ case tok::kw_long:<br>
+ case tok::kw___int64:<br>
+ case tok::kw___int128:<br>
+ case tok::kw_signed:<br>
+ case tok::kw_unsigned:<br>
+ case tok::kw_void:<br>
+ case tok::kw_char:<br>
+ case tok::kw_int:<br>
+ case tok::kw_half:<br>
+ case tok::kw_float:<br>
+ case tok::kw_double:<br>
+ case tok::kw_wchar_t:<br>
+ case tok::kw_bool:<br>
+ case tok::kw___underlying_type:<br>
+ return true;<br>
+ case tok::annot_typename:<br>
+ case tok::kw_char16_t:<br>
+ case tok::kw_char32_t:<br>
+ case tok::kw_typeof:<br>
+ case tok::kw_decltype:<br>
+ return Lex.getLangOpts().CPlusPlus;<br>
+ default:<br>
+ break;<br>
+ }<br>
+ return false;<br>
+ }<br>
+<br>
SmallVector<Context, 8> Contexts;<br>
<br>
SourceManager &SourceMgr;<br>
@@ -886,7 +927,7 @@ unsigned TokenAnnotator::splitPenalty(co<br>
const AnnotatedToken &Right = Tok;<br>
<br>
if (Right.Type == TT_StartOfName) {<br>
- if (<a href="http://Line.First.is" target="_blank">Line.First.is</a>(tok::kw_for))<br>
+ if (<a href="http://Line.First.is" target="_blank">Line.First.is</a>(tok::kw_for) && Right.PartOfMultiVariableDeclStmt)<br>
return 3;<br>
else if (Line.MightBeFunctionDecl && Right.BindingStrength == 1)<br>
// FIXME: Clean up hack of using BindingStrength to find top-level names.<br>
<br>
Modified: cfe/trunk/lib/Format/TokenAnnotator.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=178641&r1=178640&r2=178641&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.h?rev=178641&r1=178640&r2=178641&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Format/TokenAnnotator.h (original)<br>
+++ cfe/trunk/lib/Format/TokenAnnotator.h Wed Apr 3 08:36:17 2013<br>
@@ -76,8 +76,8 @@ public:<br>
ClosesTemplateDeclaration(false), MatchingParen(NULL),<br>
ParameterCount(0), BindingStrength(0), SplitPenalty(0),<br>
LongestObjCSelectorName(0), Parent(NULL), FakeLParens(0),<br>
- FakeRParens(0), LastInChainOfCalls(false) {<br>
- }<br>
+ FakeRParens(0), LastInChainOfCalls(false),<br>
+ PartOfMultiVariableDeclStmt(false) {}<br>
<br>
bool is(tok::TokenKind Kind) const { return <a href="http://FormatTok.Tok.is" target="_blank">FormatTok.Tok.is</a>(Kind); }<br>
<br>
@@ -166,6 +166,11 @@ public:<br>
/// \brief Is this the last "." or "->" in a builder-type call?<br>
bool LastInChainOfCalls;<br>
<br>
+ /// \brief Is this token part of a \c DeclStmt defining multiple variables?<br>
+ ///<br>
+ /// Only set if \c Type == \c TT_StartOfName.<br>
+ bool PartOfMultiVariableDeclStmt;<br>
+<br>
const AnnotatedToken *getPreviousNoneComment() const {<br>
AnnotatedToken *Tok = Parent;<br>
while (Tok != NULL && Tok->is(tok::comment))<br>
<br>
Modified: cfe/trunk/unittests/Format/FormatTest.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=178641&r1=178640&r2=178641&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=178641&r1=178640&r2=178641&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)<br>
+++ cfe/trunk/unittests/Format/FormatTest.cpp Wed Apr 3 08:36:17 2013<br>
@@ -311,8 +311,8 @@ TEST_F(FormatTest, FormatsForLoop) {<br>
verifyFormat(<br>
"for (MachineFun::iterator IIII = PrevIt, EEEE = F.end(); IIII != EEEE;\n"<br>
" ++IIIII) {\n}");<br>
- verifyFormat("for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n"<br>
- " aaaaaaaaaaa = aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n"<br>
+ verifyFormat("for (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaa =\n"<br>
+ " aaaaaaaaaaaaaaaa.aaaaaaaaaaaaaaa;\n"<br>
" aaaaaaaaaaa != aaaaaaaaaaaaaaaaaaa; ++aaaaaaaaaaa) {\n}");<br>
verifyFormat("for (llvm::ArrayRef<NamedDecl *>::iterator\n"<br>
" I = FD->getDeclsInPrototypeScope().begin(),\n"<br>
@@ -329,6 +329,10 @@ TEST_F(FormatTest, FormatsForLoop) {<br>
verifyFormat("for (int aaaaaaaaaaa = 1; aaaaaaaaaaa <= bbbbbbbbbbbbbbb;\n"<br>
" aaaaaaaaaaa++, bbbbbbbbbbbbbbbbb++) {\n"<br>
"}");<br>
+ verifyFormat("for (some_namespace::SomeIterator iter( // force break\n"<br>
+ " aaaaaaaaaa);\n"<br>
+ " iter; ++iter) {\n"<br>
+ "}");<br>
<br>
FormatStyle NoBinPacking = getLLVMStyle();<br>
NoBinPacking.BinPackParameters = false;<br>
@@ -1188,8 +1192,9 @@ TEST_F(FormatTest, FormatsSmallMacroDefi<br>
}<br>
<br>
TEST_F(FormatTest, DoesNotBreakPureVirtualFunctionDefinition) {<br>
- verifyFormat("virtual void write(ELFWriter *writerrr,\n"<br>
- " OwningPtr<FileOutputBuffer> &buffer) = 0;");<br>
+ verifyFormat(<br>
+ "virtual void\n"<br>
+ "write(ELFWriter *writerrr, OwningPtr<FileOutputBuffer> &buffer) = 0;");<br>
}<br>
<br>
TEST_F(FormatTest, LayoutUnknownPPDirective) {<br>
@@ -1378,7 +1383,7 @@ TEST_F(FormatTest, MixingPreprocessorDir<br>
TEST_F(FormatTest, LayoutStatementsAroundPreprocessorDirectives) {<br>
EXPECT_EQ("int\n"<br>
"#define A\n"<br>
- " a;",<br>
+ "a;",<br>
format("int\n#define A\na;"));<br>
verifyFormat("functionCallTo(\n"<br>
" someOtherFunction(\n"<br>
@@ -1613,7 +1618,7 @@ TEST_F(FormatTest, BreaksDesireably) {<br>
}<br>
<br>
TEST_F(FormatTest, FormatsOneParameterPerLineIfNecessary) {<br>
- FormatStyle NoBinPacking = getLLVMStyle();<br>
+ FormatStyle NoBinPacking = getGoogleStyle();<br>
NoBinPacking.BinPackParameters = false;<br>
verifyFormat("f(aaaaaaaaaaaaaaaaaaaa,\n"<br>
" aaaaaaaaaaaaaaaaaaaa,\n"<br>
@@ -1851,14 +1856,13 @@ TEST_F(FormatTest, DeclarationsOfMultipl<br>
" aaaaaaaaaaa = aaaaaa->aaaaaaaaaaa();");<br>
verifyFormat("bool a = true, b = false;");<br>
<br>
- // FIXME: Indentation looks weird.<br>
verifyFormat("bool aaaaaaaaaaaaaaaaaaaaaaaaa =\n"<br>
- " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),\n"<br>
+ " aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(aaaaaaaaaaaaaaaa),\n"<br>
" bbbbbbbbbbbbbbbbbbbbbbbbb =\n"<br>
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb(bbbbbbbbbbbbbbbb);");<br>
verifyFormat(<br>
"bool aaaaaaaaaaaaaaaaaaaaa =\n"<br>
- " bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n"<br>
+ " bbbbbbbbbbbbbbbbbbbbbbbbbbbb && cccccccccccccccccccccccccccc,\n"<br>
" d = e && f;");<br>
<br>
}<br>
@@ -2051,7 +2055,7 @@ TEST_F(FormatTest, WrapsTemplateDeclarat<br>
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa);");<br>
verifyFormat("template <typename T>\n"<br>
"void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"<br>
- " int aaaaaaaaaaaaaaaaa);");<br>
+ " int aaaaaaaaaaaaaaaaaaaaaa);");<br>
verifyFormat(<br>
"template <typename T1, typename T2 = char, typename T3 = char,\n"<br>
" typename T4 = char>\n"<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu" target="_blank">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</blockquote></div></div></div><span class="HOEnZb"><font color="#888888"><br><br clear="all"><div><br></div>-- <br><div>Alexey Samsonov, MSK</div>
</font></span></div></div>
</blockquote></div><br></div>