summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2014-08-23 00:30:57 +0000
committerRichard Trieu <rtrieu@google.com>2014-08-23 00:30:57 +0000
commit7ec1a318ff6b86f3c06a24dc933cb1d33b187ba1 (patch)
tree765588ac3e81bbedfdd3a4ba2852f8e71b4178a3 /clang
parente3eface17ac15ff3818e76e4fcadef5afad92f2a (diff)
downloadbcm5719-llvm-7ec1a318ff6b86f3c06a24dc933cb1d33b187ba1.tar.gz
bcm5719-llvm-7ec1a318ff6b86f3c06a24dc933cb1d33b187ba1.zip
Fix a bad location in -Wparentheses fix-it hint
The code used getLocStart() instead of getLocEnd(). This works for single token expressions, but breaks if the expression is longer. llvm-svn: 216306
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/Sema/SemaExpr.cpp2
-rw-r--r--clang/test/Sema/parentheses.cpp102
2 files changed, 103 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index b74429ab557..5bb042ce3da 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -9515,7 +9515,7 @@ static void DiagnoseBitwisePrecedence(Sema &Self, BinaryOperatorKind Opc,
StringRef OpStr = isLeftComp ? LHSBO->getOpcodeStr() : RHSBO->getOpcodeStr();
SourceRange ParensRange = isLeftComp ?
SourceRange(LHSBO->getRHS()->getLocStart(), RHSExpr->getLocEnd())
- : SourceRange(LHSExpr->getLocStart(), RHSBO->getLHS()->getLocStart());
+ : SourceRange(LHSExpr->getLocStart(), RHSBO->getLHS()->getLocEnd());
Self.Diag(OpLoc, diag::warn_precedence_bitwise_rel)
<< DiagRange << BinaryOperator::getOpcodeStr(Opc) << OpStr;
diff --git a/clang/test/Sema/parentheses.cpp b/clang/test/Sema/parentheses.cpp
index ac2694f72e1..d9fedb58c64 100644
--- a/clang/test/Sema/parentheses.cpp
+++ b/clang/test/Sema/parentheses.cpp
@@ -113,3 +113,105 @@ namespace PR15628 {
(void)(i-- ? true : false); // no-warning
}
}
+
+namespace PR20735 {
+ struct X {
+ static int state;
+ static int get();
+ int get_num();
+ int num;
+ };
+ namespace ns {
+ int num = 0;
+ int get();
+ }
+ void test(X x) {
+ if (5 & x.get_num() != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:29-[[@LINE-6]]:29}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:24-[[@LINE-9]]:24}:")"
+
+ if (5 & x.num != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:23-[[@LINE-6]]:23}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:18-[[@LINE-9]]:18}:")"
+
+ if (5 & x.state != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:25-[[@LINE-6]]:25}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
+
+ if (5 & x.get() != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:25-[[@LINE-6]]:25}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
+
+ if (5 & X::state != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:21-[[@LINE-9]]:21}:")"
+
+ if (5 & X::get() != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:26-[[@LINE-6]]:26}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:21-[[@LINE-9]]:21}:")"
+
+ if (5 & ns::get() != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:27-[[@LINE-6]]:27}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:22-[[@LINE-9]]:22}:")"
+
+ if (5 & ns::num != 0) {}
+ // expected-warning@-1 {{& has lower precedence than !=; != will be evaluated first}}
+ // expected-note@-2 {{place parentheses around the '!=' expression to silence this warning}}
+ // expected-note@-3 {{place parentheses around the & expression to evaluate it first}}
+ // CHECK: place parentheses around the '!=' expression to silence this warning
+ // fix-it:"{{.*}}":{[[@LINE-5]]:13-[[@LINE-5]]:13}:"("
+ // fix-it:"{{.*}}":{[[@LINE-6]]:25-[[@LINE-6]]:25}:")"
+ // CHECK: place parentheses around the & expression to evaluate it first
+ // fix-it:"{{.*}}":{[[@LINE-8]]:9-[[@LINE-8]]:9}:"("
+ // fix-it:"{{.*}}":{[[@LINE-9]]:20-[[@LINE-9]]:20}:")"
+ }
+}
OpenPOWER on IntegriCloud