summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaStmt.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2018-10-25 01:08:00 +0000
committerRichard Trieu <rtrieu@google.com>2018-10-25 01:08:00 +0000
commitf371380fc96c67cab15067dea51a55131757d351 (patch)
tree5d057a41ba8deefc448a4c36f5790bc1b8434fc5 /clang/lib/Sema/SemaStmt.cpp
parenta6c6698217d7e20fd5564377d5ba2ab6b3c6f768 (diff)
downloadbcm5719-llvm-f371380fc96c67cab15067dea51a55131757d351.tar.gz
bcm5719-llvm-f371380fc96c67cab15067dea51a55131757d351.zip
[Sema] Fix -Wcomma for C89
There is a small difference in the scope flags for C89 versus the other C/C++ dialects. This change ensures that the -Wcomma warning won't be duplicated or issued in the wrong location. Also, the test case is refactored into C and C++ parts, with the C++ parts guarded by a #ifdef to allow the test to run in both modes. https://bugs.llvm.org/show_bug.cgi?id=32370 llvm-svn: 345228
Diffstat (limited to 'clang/lib/Sema/SemaStmt.cpp')
-rw-r--r--clang/lib/Sema/SemaStmt.cpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaStmt.cpp b/clang/lib/Sema/SemaStmt.cpp
index 16ed9ed767c..7fc89bfd69a 100644
--- a/clang/lib/Sema/SemaStmt.cpp
+++ b/clang/lib/Sema/SemaStmt.cpp
@@ -551,8 +551,9 @@ Sema::ActOnIfStmt(SourceLocation IfLoc, bool IsConstexpr, Stmt *InitStmt,
false);
Expr *CondExpr = Cond.get().second;
- if (!Diags.isIgnored(diag::warn_comma_operator,
- CondExpr->getExprLoc()))
+ // Only call the CommaVisitor when not C89 due to differences in scope flags.
+ if ((getLangOpts().C99 || getLangOpts().CPlusPlus) &&
+ !Diags.isIgnored(diag::warn_comma_operator, CondExpr->getExprLoc()))
CommaVisitor(*this).Visit(CondExpr);
if (!elseStmt)
@@ -1328,6 +1329,11 @@ Sema::ActOnDoStmt(SourceLocation DoLoc, Stmt *Body,
return StmtError();
Cond = CondResult.get();
+ // Only call the CommaVisitor for C89 due to differences in scope flags.
+ if (Cond && !getLangOpts().C99 && !getLangOpts().CPlusPlus &&
+ !Diags.isIgnored(diag::warn_comma_operator, Cond->getExprLoc()))
+ CommaVisitor(*this).Visit(Cond);
+
DiagnoseUnusedExprResult(Body);
return new (Context) DoStmt(Body, Cond, DoLoc, WhileLoc, CondRParen);
OpenPOWER on IntegriCloud