aboutsummaryrefslogtreecommitdiff
path: root/lib/Format/Format.cpp
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2013-01-02 17:21:36 +0000
committerDaniel Jasper <djasper@google.com>2013-01-02 17:21:36 +0000
commitba3d3074e8ef4c4c05ac062b073b2e082e6a0206 (patch)
tree89ecc35d662b1e650f5c56ae12e8b9a68c07c9f6 /lib/Format/Format.cpp
parenta080a187fa7e538da3212c7d5e678e4b7ae03253 (diff)
Format */& as binary operator if followed by a unary operator.
This fixes llvm.org/PR14687. Also fixes segfault for lines starting with * or &. Before: a *~b; *a = 1; // <- this segfaulted After: a * ~b; *a = 1; // no segfault :-) git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@171396 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format/Format.cpp')
-rw-r--r--lib/Format/Format.cpp14
1 files changed, 9 insertions, 5 deletions
diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp
index 8ea95c4862..3c337ec063 100644
--- a/lib/Format/Format.cpp
+++ b/lib/Format/Format.cpp
@@ -835,19 +835,23 @@ private:
}
TokenAnnotation::TokenType determineStarAmpUsage(unsigned Index, bool IsRHS) {
+ if (Index == 0)
+ return TokenAnnotation::TT_UnaryOperator;
if (Index == Annotations.size())
return TokenAnnotation::TT_Unknown;
const FormatToken &PrevToken = Line.Tokens[Index - 1];
const FormatToken &NextToken = Line.Tokens[Index + 1];
- if (Index == 0 || PrevToken.Tok.is(tok::l_paren) ||
- PrevToken.Tok.is(tok::comma) || PrevToken.Tok.is(tok::kw_return) ||
- PrevToken.Tok.is(tok::colon) ||
+ if (PrevToken.Tok.is(tok::l_paren) || PrevToken.Tok.is(tok::comma) ||
+ PrevToken.Tok.is(tok::kw_return) || PrevToken.Tok.is(tok::colon) ||
Annotations[Index - 1].Type == TokenAnnotation::TT_BinaryOperator)
return TokenAnnotation::TT_UnaryOperator;
if (PrevToken.Tok.isLiteral() || NextToken.Tok.isLiteral() ||
- NextToken.Tok.is(tok::kw_sizeof))
+ NextToken.Tok.is(tok::plus) || NextToken.Tok.is(tok::minus) ||
+ NextToken.Tok.is(tok::plusplus) || NextToken.Tok.is(tok::minusminus) ||
+ NextToken.Tok.is(tok::tilde) || NextToken.Tok.is(tok::exclaim) ||
+ NextToken.Tok.is(tok::kw_alignof) || NextToken.Tok.is(tok::kw_sizeof))
return TokenAnnotation::TT_BinaryOperator;
if (NextToken.Tok.is(tok::comma) || NextToken.Tok.is(tok::r_paren) ||
@@ -931,7 +935,7 @@ private:
return Left.is(tok::kw_if) || Left.is(tok::kw_for) ||
Left.is(tok::kw_while) || Left.is(tok::kw_switch) ||
(Left.isNot(tok::identifier) && Left.isNot(tok::kw_sizeof) &&
- Left.isNot(tok::kw_typeof));
+ Left.isNot(tok::kw_typeof) && Left.isNot(tok::kw_alignof));
}
return true;
}