Skip to content

[flang][OpenMP] Error out when CHARACTER type is used in atomic constructs #113045

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions flang/lib/Lower/DirectivesCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,8 @@ static void processOmpAtomicTODO(mlir::Type elementType,
return;
if constexpr (std::is_same<AtomicListT,
Fortran::parser::OmpAtomicClauseList>()) {
// Based on assertion for supported element types in OMPIRBuilder.cpp
// createAtomicRead
mlir::Type unwrappedEleTy = fir::unwrapRefType(elementType);
bool supportedAtomicType = fir::isa_trivial(unwrappedEleTy);
if (!supportedAtomicType)
TODO(loc, "Unsupported atomic type");
assert(fir::isa_trivial(fir::unwrapRefType(elementType)) &&
"is supported type for omp atomic");
}
}

Expand Down
19 changes: 14 additions & 5 deletions flang/lib/Semantics/check-omp-structure.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1888,16 +1888,21 @@ inline void OmpStructureChecker::ErrIfLHSAndRHSSymbolsMatch(
inline void OmpStructureChecker::ErrIfNonScalarAssignmentStmt(
const parser::Variable &var, const parser::Expr &expr) {
// Err out if either the variable on the LHS or the expression on the RHS of
// the assignment statement are non-scalar (i.e. have rank > 0)
// the assignment statement are non-scalar (i.e. have rank > 0 or is of
// CHARACTER type)
const auto *e{GetExpr(context_, expr)};
const auto *v{GetExpr(context_, var)};
if (e && v) {
if (e->Rank() != 0)
if (e->Rank() != 0 ||
(e->GetType().has_value() &&
e->GetType().value().category() == common::TypeCategory::Character))
context_.Say(expr.source,
"Expected scalar expression "
"on the RHS of atomic assignment "
"statement"_err_en_US);
if (v->Rank() != 0)
if (v->Rank() != 0 ||
(v->GetType().has_value() &&
v->GetType()->category() == common::TypeCategory::Character))
context_.Say(var.GetSource(),
"Expected scalar variable "
"on the LHS of atomic assignment "
Expand Down Expand Up @@ -2008,12 +2013,16 @@ void OmpStructureChecker::CheckAtomicUpdateStmt(
expr.u);
if (const auto *e{GetExpr(context_, expr)}) {
const auto *v{GetExpr(context_, var)};
if (e->Rank() != 0)
if (e->Rank() != 0 ||
(e->GetType().has_value() &&
e->GetType().value().category() == common::TypeCategory::Character))
context_.Say(expr.source,
"Expected scalar expression "
"on the RHS of atomic update assignment "
"statement"_err_en_US);
if (v->Rank() != 0)
if (v->Rank() != 0 ||
(v->GetType().has_value() &&
v->GetType()->category() == common::TypeCategory::Character))
context_.Say(var.GetSource(),
"Expected scalar variable "
"on the LHS of atomic update assignment "
Expand Down
8 changes: 0 additions & 8 deletions flang/test/Lower/OpenMP/Todo/atomic-character.f90

This file was deleted.

2 changes: 2 additions & 0 deletions flang/test/Semantics/OpenMP/atomic02.f90
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ program OmpAtomic
a = a**4
!$omp atomic
!ERROR: Invalid or missing operator in atomic update statement
!ERROR: Expected scalar expression on the RHS of atomic update assignment statement
c = c//d
!$omp atomic
!ERROR: Atomic update statement should be of form `l = l operator expr` OR `l = expr operator l`
Expand Down Expand Up @@ -78,6 +79,7 @@ program OmpAtomic
a = a**4
!$omp atomic update
!ERROR: Invalid or missing operator in atomic update statement
!ERROR: Expected scalar expression on the RHS of atomic update assignment statement
c = c//d
!$omp atomic update
!ERROR: Atomic update statement should be of form `l = l operator expr` OR `l = expr operator l`
Expand Down
11 changes: 11 additions & 0 deletions flang/test/Semantics/OpenMP/omp-atomic-assignment-stmt.f90
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ program sample
integer :: m
endtype
type(sample_type) :: z
character :: l, r
!$omp atomic read
v = x

Expand Down Expand Up @@ -148,4 +149,14 @@ program sample
y(1) = y(1) + 1
x = y(2)
!$omp end atomic

!$omp atomic read
!ERROR: Expected scalar variable on the LHS of atomic assignment statement
!ERROR: Expected scalar expression on the RHS of atomic assignment statement
l = r

!$omp atomic write
!ERROR: Expected scalar variable on the LHS of atomic assignment statement
!ERROR: Expected scalar expression on the RHS of atomic assignment statement
l = r
end program
Loading