Skip to content

Commit b35be6f

Browse files
committed
[Clang][Sema][OpenMP] Sema support for atomic compare
This patch adds the Sema support for `atomic compare`. Reviewed By: ABataev Differential Revision: https://reviews.llvm.org/D116637
1 parent 679c77e commit b35be6f

File tree

6 files changed

+867
-21
lines changed

6 files changed

+867
-21
lines changed

clang/include/clang/Basic/DiagnosticSemaKinds.td

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10516,6 +10516,15 @@ def err_omp_atomic_capture_not_compound_statement : Error<
1051610516
" where x is an lvalue expression with scalar type">;
1051710517
def note_omp_atomic_capture: Note<
1051810518
"%select{expected assignment expression|expected compound statement|expected exactly two expression statements|expected in right hand side of the first expression}0">;
10519+
def err_omp_atomic_compare : Error<
10520+
"the statement for 'atomic compare' must be a compound statement of form '{x = expr ordop x ? expr : x;}', '{x = x ordop expr? expr : x;}',"
10521+
" '{x = x == e ? d : x;}', '{x = e == x ? d : x;}', or 'if(expr ordop x) {x = expr;}', 'if(x ordop expr) {x = expr;}', 'if(x == e) {x = d;}',"
10522+
" 'if(e == x) {x = d;}' where 'x' is an lvalue expression with scalar type, 'expr', 'e', and 'd' are expressions with scalar type,"
10523+
" and 'ordop' is one of '<' or '>'.">;
10524+
def note_omp_atomic_compare: Note<
10525+
"%select{expected compound statement|expected exactly one expression statement|expected assignment statement|expected conditional operator|expect result value to be at false expression|"
10526+
"expect binary operator in conditional expression|expect '<', '>' or '==' as order operator|expect comparison in a form of 'x == e', 'e == x', 'x ordop expr', or 'expr ordop x'|"
10527+
"expect lvalue for result value|expect scalar value|expect integer value}0">;
1051910528
def err_omp_atomic_several_clauses : Error<
1052010529
"directive '#pragma omp atomic' cannot contain more than one 'read', 'write', 'update', 'capture', or 'compare' clause">;
1052110530
def err_omp_several_mem_order_clauses : Error<

clang/lib/CodeGen/CGStmtOpenMP.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6031,9 +6031,13 @@ static void emitOMPAtomicExpr(CodeGenFunction &CGF, OpenMPClauseKind Kind,
60316031
emitOMPAtomicCaptureExpr(CGF, AO, IsPostfixUpdate, V, X, E, UE,
60326032
IsXLHSInRHSPart, Loc);
60336033
break;
6034-
case OMPC_compare:
6035-
// Do nothing here as we already emit an error.
6034+
case OMPC_compare: {
6035+
// Emit an error here.
6036+
unsigned DiagID = CGF.CGM.getDiags().getCustomDiagID(
6037+
DiagnosticsEngine::Error, "'atomic compare' is not supported for now");
6038+
CGF.CGM.getDiags().Report(DiagID);
60366039
break;
6040+
}
60376041
case OMPC_if:
60386042
case OMPC_final:
60396043
case OMPC_num_threads:

0 commit comments

Comments
 (0)