Skip to content
Open
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
27 changes: 26 additions & 1 deletion flang/lib/Semantics/check-omp-atomic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ void OmpStructureChecker::CheckAtomicType(
return;
}

// Variable is a pointer.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change

if (typeSpec->IsPolymorphic()) {
context_.Say(source,
"Atomic variable %s cannot be a pointer to a polymorphic type"_err_en_US,
Expand Down Expand Up @@ -829,6 +828,32 @@ void OmpStructureChecker::CheckAtomicWriteAssignment(
if (!IsVarOrFunctionRef(atom)) {
ErrorShouldBeVariable(atom, rsrc);
} else {
// For intrinsic assignment (x = expr), check if the variable is a pointer
// to a non-intrinsic type, which is not allowed in ATOMIC WRITE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't specific to WRITE. It should be checked in CheckAtomicType.

if (!IsPointerAssignment(write)) {
std::vector<SomeExpr> dsgs{GetAllDesignators(atom)};
if (!dsgs.empty()) {
evaluate::SymbolVector syms{evaluate::GetSymbolVector(dsgs.front())};
if (!syms.empty() && IsPointer(syms.back())) {
SymbolRef sym = syms.back();
if (const DeclTypeSpec *typeSpec{sym->GetType()}) {
using Category = DeclTypeSpec::Category;
Category cat{typeSpec->category()};
if (cat != Category::Numeric && cat != Category::Logical) {
std::string details = " has the POINTER attribute";
if (const auto *derived{typeSpec->AsDerived()}) {
details +=
" and derived type '"s + derived->name().ToString() + "'";
}
context_.Say(lsrc,
"ATOMIC WRITE requires an intrinsic scalar variable; '%s'%s"_err_en_US,
sym->name(), details);
return;
}
}
}
}
}
CheckAtomicVariable(atom, lsrc);
CheckStorageOverlap(atom, {write.rhs}, source);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
! RUN: not %flang_fc1 -fopenmp -fsyntax-only %s 2>&1 | FileCheck %s
type t
end type
type(t), pointer :: a1, a2
!$omp atomic write
a1 = a2
! CHECK: error: ATOMIC WRITE requires an intrinsic scalar variable; 'a1' has the POINTER attribute and derived type 't'
end