Skip to content

Commit 9bfd15a

Browse files
committed
[flang][OpenMP] Error out when CHARACTER type is used in atomic constructs
1 parent 645e6f1 commit 9bfd15a

File tree

5 files changed

+29
-19
lines changed

5 files changed

+29
-19
lines changed

flang/lib/Lower/DirectivesCommon.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,8 @@ static void processOmpAtomicTODO(mlir::Type elementType,
126126
return;
127127
if constexpr (std::is_same<AtomicListT,
128128
Fortran::parser::OmpAtomicClauseList>()) {
129-
// Based on assertion for supported element types in OMPIRBuilder.cpp
130-
// createAtomicRead
131-
mlir::Type unwrappedEleTy = fir::unwrapRefType(elementType);
132-
bool supportedAtomicType = fir::isa_trivial(unwrappedEleTy);
133-
if (!supportedAtomicType)
134-
TODO(loc, "Unsupported atomic type");
129+
assert(fir::isa_trivial(fir::unwrapRefType(elementType)) &&
130+
"is supported type for omp atomic");
135131
}
136132
}
137133

flang/lib/Semantics/check-omp-structure.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,16 +1888,21 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
18881888
inline void OmpStructureChecker::ErrIfNonScalarAssignmentStmt(
18891889
const parser::Variable &var, const parser::Expr &expr) {
18901890
// Err out if either the variable on the LHS or the expression on the RHS of
1891-
// the assignment statement are non-scalar (i.e. have rank > 0)
1891+
// the assignment statement are non-scalar (i.e. have rank > 0 or is of
1892+
// CHARACTER type)
18921893
const auto *e{GetExpr(context_, expr)};
18931894
const auto *v{GetExpr(context_, var)};
18941895
if (e && v) {
1895-
if (e->Rank() != 0)
1896+
if (e->Rank() != 0 ||
1897+
(e->GetType().has_value() &&
1898+
e->GetType().value().category() == common::TypeCategory::Character))
18961899
context_.Say(expr.source,
18971900
"Expected scalar expression "
18981901
"on the RHS of atomic assignment "
18991902
"statement"_err_en_US);
1900-
if (v->Rank() != 0)
1903+
if (v->Rank() != 0 ||
1904+
(v->GetType().has_value() &&
1905+
v->GetType()->category() == common::TypeCategory::Character))
19011906
context_.Say(var.GetSource(),
19021907
"Expected scalar variable "
19031908
"on the LHS of atomic assignment "
@@ -2008,12 +2013,16 @@ void OmpStructureChecker::CheckAtomicUpdateStmt(
20082013
expr.u);
20092014
if (const auto *e{GetExpr(context_, expr)}) {
20102015
const auto *v{GetExpr(context_, var)};
2011-
if (e->Rank() != 0)
2016+
if (e->Rank() != 0 ||
2017+
(e->GetType().has_value() &&
2018+
e->GetType().value().category() == common::TypeCategory::Character))
20122019
context_.Say(expr.source,
20132020
"Expected scalar expression "
20142021
"on the RHS of atomic update assignment "
20152022
"statement"_err_en_US);
2016-
if (v->Rank() != 0)
2023+
if (v->Rank() != 0 ||
2024+
(v->GetType().has_value() &&
2025+
v->GetType()->category() == common::TypeCategory::Character))
20172026
context_.Say(var.GetSource(),
20182027
"Expected scalar variable "
20192028
"on the LHS of atomic update assignment "

flang/test/Lower/OpenMP/Todo/atomic-character.f90

Lines changed: 0 additions & 8 deletions
This file was deleted.

flang/test/Semantics/OpenMP/atomic02.f90

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ program OmpAtomic
3232
a = a**4
3333
!$omp atomic
3434
!ERROR: Invalid or missing operator in atomic update statement
35+
!ERROR: Expected scalar expression on the RHS of atomic update assignment statement
3536
c = c//d
3637
!$omp atomic
3738
!ERROR: Atomic update statement should be of form `l = l operator expr` OR `l = expr operator l`
@@ -78,6 +79,7 @@ program OmpAtomic
7879
a = a**4
7980
!$omp atomic update
8081
!ERROR: Invalid or missing operator in atomic update statement
82+
!ERROR: Expected scalar expression on the RHS of atomic update assignment statement
8183
c = c//d
8284
!$omp atomic update
8385
!ERROR: Atomic update statement should be of form `l = l operator expr` OR `l = expr operator l`

flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt.f90

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ program sample
1414
integer :: m
1515
endtype
1616
type(sample_type) :: z
17+
character :: l, r
1718
!$omp atomic read
1819
v = x
1920

@@ -148,4 +149,14 @@ program sample
148149
y(1) = y(1) + 1
149150
x = y(2)
150151
!$omp end atomic
152+
153+
!$omp atomic read
154+
!ERROR: Expected scalar variable on the LHS of atomic assignment statement
155+
!ERROR: Expected scalar expression on the RHS of atomic assignment statement
156+
l = r
157+
158+
!$omp atomic write
159+
!ERROR: Expected scalar variable on the LHS of atomic assignment statement
160+
!ERROR: Expected scalar expression on the RHS of atomic assignment statement
161+
l = r
151162
end program

0 commit comments

Comments
 (0)