[llvm] [clang-tools-extra] [clang] [OpenMP] atomic compare weak : Parser & AST support (PR #79475)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 26 07:29:10 PST 2024
================
@@ -13202,6 +13204,29 @@ StmtResult Sema::ActOnOpenMPAtomicDirective(ArrayRef<OMPClause *> Clauses,
E = Checker.getE();
D = Checker.getD();
CE = Checker.getCond();
+ /* The weak clause may only appear if the resulting atomic operation is
+ * an atomic conditional update for which the comparison tests for
+ * equality.
+ * It was not possible to do this check in
+ * OpenMPAtomicCompareChecker::checkStmt() as the check for OMPC_weak
+ * could not be performed (Clauses are not available).
+ */
+ for (OMPClause *C : Clauses) {
+ if (C->getClauseKind() == llvm::omp::Clause::OMPC_weak) {
+ auto *Cond = dyn_cast<BinaryOperator>(CE);
+ if (Cond->getOpcode() != BO_EQ) {
+
+ ErrorInfo.Error = Checker.ErrorTy::NotAnAssignment;
+ ErrorInfo.ErrorLoc = Cond->getExprLoc();
+ ErrorInfo.NoteLoc = Cond->getOperatorLoc();
+ ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
+
+ Diag(ErrorInfo.ErrorLoc, diag::err_omp_atomic_weak_no_equality)
+ << ErrorInfo.ErrorRange;
+ return StmtError();
+ }
+ }
+ }
----------------
alexey-bataev wrote:
```suggestion
auto *It = find_if(Clauses, [](OMPClause *C) { return C->getClauseKind() == llvm::omp::Clause::OMPC_weak; });
if (It != Clauses.end()) {
auto *Cond = dyn_cast<BinaryOperator>(CE);
if (Cond->getOpcode() != BO_EQ) {
ErrorInfo.Error = Checker.ErrorTy::NotAnAssignment;
ErrorInfo.ErrorLoc = Cond->getExprLoc();
ErrorInfo.NoteLoc = Cond->getOperatorLoc();
ErrorInfo.ErrorRange = ErrorInfo.NoteRange = Cond->getSourceRange();
Diag(ErrorInfo.ErrorLoc, diag::err_omp_atomic_weak_no_equality)
<< ErrorInfo.ErrorRange;
return StmtError();
}
}
```
https://github.com/llvm/llvm-project/pull/79475
More information about the llvm-commits
mailing list