summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorDaniel Jasper <djasper@google.com>2014-04-28 09:19:28 +0000
committerDaniel Jasper <djasper@google.com>2014-04-28 09:19:28 +0000
commit942d971c84e3089aab902756b6911bd82ccac300 (patch)
treea73b2593d20c175c76e344465810bfdbb9bdf654 /clang
parentf8542956d39c4a8adb81085c90af5f7f903916ca (diff)
downloadbcm5719-llvm-942d971c84e3089aab902756b6911bd82ccac300.tar.gz
bcm5719-llvm-942d971c84e3089aab902756b6911bd82ccac300.zip
clang-format: Improve binary operator detection.
Before: *(int *)(p &~3UL) = 0; After: *(int *)(p & ~3UL) = 0; This fixes llvm.org/PR19464. llvm-svn: 207405
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Format/TokenAnnotator.cpp2
-rw-r--r--clang/unittests/Format/FormatTest.cpp1
2 files changed, 2 insertions, 1 deletions
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 54961218a2d..843d8777188 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -682,7 +682,7 @@ private:
for (FormatToken *Previous = Current.Previous;
Previous && !Previous->isOneOf(tok::comma, tok::semi);
Previous = Previous->Previous) {
- if (Previous->is(tok::r_square))
+ if (Previous->isOneOf(tok::r_square, tok::r_paren))
Previous = Previous->MatchingParen;
if (Previous->Type == TT_BinaryOperator &&
Previous->isOneOf(tok::star, tok::amp)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index c006c399f38..084d1dd33d8 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -4523,6 +4523,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyIndependentOfContext("a * [self dostuff];");
verifyIndependentOfContext("int x = a * (a + b);");
verifyIndependentOfContext("(a *)(a + b);");
+ verifyIndependentOfContext("*(int *)(p & ~3UL) = 0;");
verifyIndependentOfContext("int *pa = (int *)&a;");
verifyIndependentOfContext("return sizeof(int **);");
verifyIndependentOfContext("return sizeof(int ******);");
OpenPOWER on IntegriCloud