summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaChecking.cpp
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2013-01-17 22:06:26 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2013-01-17 22:06:26 +0000
commit01a7fba820a612d55d2c09ab734f4c774ba6aa0a (patch)
treeb37845f3857ee871350de05eb01d34ba4547413c /clang/lib/Sema/SemaChecking.cpp
parent50dc8a6a388f6fd1140a501b9e9f2d0ef2ef138d (diff)
downloadbcm5719-llvm-01a7fba820a612d55d2c09ab734f4c774ba6aa0a.tar.gz
bcm5719-llvm-01a7fba820a612d55d2c09ab734f4c774ba6aa0a.zip
-Wunsequenced: if the LHS of an &&, || or ?: is not constant, check for
unsequenced operations in the RHS. We don't compare the RHS with the rest of the expression yet; such checks will need care to avoid diagnosing unsequenced operations which are both in conditionally-evaluated subexpressions which actually can't occur together, such as in '(b && ++x) + (!b && ++x)'. llvm-svn: 172760
Diffstat (limited to 'clang/lib/Sema/SemaChecking.cpp')
-rw-r--r--clang/lib/Sema/SemaChecking.cpp28
1 files changed, 22 insertions, 6 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp
index 69500ae87c5..1b9239c6e9e 100644
--- a/clang/lib/Sema/SemaChecking.cpp
+++ b/clang/lib/Sema/SemaChecking.cpp
@@ -5507,9 +5507,18 @@ public:
bool Result;
if (!BO->getLHS()->isValueDependent() &&
- BO->getLHS()->EvaluateAsBooleanCondition(Result, SemaRef.Context) &&
- !Result)
- Visit(BO->getRHS());
+ BO->getLHS()->EvaluateAsBooleanCondition(Result, SemaRef.Context)) {
+ if (!Result)
+ Visit(BO->getRHS());
+ } else {
+ // Check for unsequenced operations in the RHS, treating it as an
+ // entirely separate evaluation.
+ //
+ // FIXME: If there are operations in the RHS which are unsequenced
+ // with respect to operations outside the RHS, and those operations
+ // are unconditionally evaluated, diagnose them.
+ SequenceChecker(SemaRef, BO->getRHS());
+ }
}
void VisitBinLAnd(BinaryOperator *BO) {
{
@@ -5519,9 +5528,12 @@ public:
bool Result;
if (!BO->getLHS()->isValueDependent() &&
- BO->getLHS()->EvaluateAsBooleanCondition(Result, SemaRef.Context) &&
- Result)
- Visit(BO->getRHS());
+ BO->getLHS()->EvaluateAsBooleanCondition(Result, SemaRef.Context)) {
+ if (Result)
+ Visit(BO->getRHS());
+ } else {
+ SequenceChecker(SemaRef, BO->getRHS());
+ }
}
// Only visit the condition, unless we can be sure which subexpression will
@@ -5534,6 +5546,10 @@ public:
if (!CO->getCond()->isValueDependent() &&
CO->getCond()->EvaluateAsBooleanCondition(Result, SemaRef.Context))
Visit(Result ? CO->getTrueExpr() : CO->getFalseExpr());
+ else {
+ SequenceChecker(SemaRef, CO->getTrueExpr());
+ SequenceChecker(SemaRef, CO->getFalseExpr());
+ }
}
void VisitCXXConstructExpr(CXXConstructExpr *CCE) {
OpenPOWER on IntegriCloud