Skip to content

Commit

Permalink
[OpenMP] Ignore parens in atomic capture
Browse files Browse the repository at this point in the history
Clang misdiagnoses atomic captures cases that contains parens.
i.e.

  int v, int *p;
#pragma omp atomic capture
{ v = (*p); (*p)++; }

Patch by David S.

Differential Revision: https://reviews.llvm.org/D22487

llvm-svn: 276167
  • Loading branch information
kkwli committed Jul 20, 2016
1 parent 628fd34 commit 4f161cf
Showing 3 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions clang/lib/Sema/SemaOpenMP.cpp
Original file line number Diff line number Diff line change
@@ -6163,7 +6163,7 @@ bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId,
AtomicCompAssignOp->getOpcode());
OpLoc = AtomicCompAssignOp->getOperatorLoc();
E = AtomicCompAssignOp->getRHS();
X = AtomicCompAssignOp->getLHS();
X = AtomicCompAssignOp->getLHS()->IgnoreParens();
IsXLHSInRHSPart = true;
} else if (auto *AtomicBinOp = dyn_cast<BinaryOperator>(
AtomicBody->IgnoreParenImpCasts())) {
@@ -6177,7 +6177,7 @@ bool OpenMPAtomicUpdateChecker::checkStatement(Stmt *S, unsigned DiagId,
IsPostfixUpdate = AtomicUnaryOp->isPostfix();
Op = AtomicUnaryOp->isIncrementOp() ? BO_Add : BO_Sub;
OpLoc = AtomicUnaryOp->getOperatorLoc();
X = AtomicUnaryOp->getSubExpr();
X = AtomicUnaryOp->getSubExpr()->IgnoreParens();
E = SemaRef.ActOnIntegerConstant(OpLoc, /*uint64_t Val=*/1).get();
IsXLHSInRHSPart = true;
} else {
4 changes: 4 additions & 0 deletions clang/test/OpenMP/atomic_messages.c
Original file line number Diff line number Diff line change
@@ -312,6 +312,8 @@ int captureint() {
{ *&a = *&a + 2; c = *&a;}
#pragma omp atomic capture
{c = a; a++;}
#pragma omp atomic capture
{c = a; (a)++;}
#pragma omp atomic capture
{++a;c = a;}
#pragma omp atomic capture
@@ -320,6 +322,8 @@ int captureint() {
{--a;c = a;}
#pragma omp atomic capture
{c = a; a += b;}
#pragma omp atomic capture
{c = a; (a) += b;}
#pragma omp atomic capture
{a %= b; c = a;}
#pragma omp atomic capture
4 changes: 4 additions & 0 deletions clang/test/OpenMP/atomic_messages.cpp
Original file line number Diff line number Diff line change
@@ -452,6 +452,8 @@ T capture() {
{ *&a = *&a + 2; c = *&a;}
#pragma omp atomic capture
{c = a; a++;}
#pragma omp atomic capture
{c = a; (a)++;}
#pragma omp atomic capture
{++a;c = a;}
#pragma omp atomic capture
@@ -460,6 +462,8 @@ T capture() {
{--a;c = a;}
#pragma omp atomic capture
{c = a; a += b;}
#pragma omp atomic capture
{c = a; (a) += b;}
#pragma omp atomic capture
{a %= b; c = a;}
#pragma omp atomic capture

0 comments on commit 4f161cf

Please sign in to comment.