Skip to content

Commit 28e3606

Browse files
Krish GuptaKrish Gupta
authored andcommitted
[flang][OpenMP] Add diagnostic for ATOMIC WRITE with pointer to non-intrinsic type
Fixes #161932
1 parent 6b1604a commit 28e3606

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

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

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -539,7 +539,6 @@ void OmpStructureChecker::CheckAtomicType(
539539
return;
540540
}
541541

542-
// Variable is a pointer.
543542
if (typeSpec->IsPolymorphic()) {
544543
context_.Say(source,
545544
"Atomic variable %s cannot be a pointer to a polymorphic type"_err_en_US,
@@ -829,6 +828,32 @@ void OmpStructureChecker::CheckAtomicWriteAssignment(
829828
if (!IsVarOrFunctionRef(atom)) {
830829
ErrorShouldBeVariable(atom, rsrc);
831830
} else {
831+
// For intrinsic assignment (x = expr), check if the variable is a pointer
832+
// to a non-intrinsic type, which is not allowed in ATOMIC WRITE
833+
if (!IsPointerAssignment(write)) {
834+
std::vector<SomeExpr> dsgs{GetAllDesignators(atom)};
835+
if (!dsgs.empty()) {
836+
evaluate::SymbolVector syms{evaluate::GetSymbolVector(dsgs.front())};
837+
if (!syms.empty() && IsPointer(syms.back())) {
838+
SymbolRef sym = syms.back();
839+
if (const DeclTypeSpec *typeSpec{sym->GetType()}) {
840+
using Category = DeclTypeSpec::Category;
841+
Category cat{typeSpec->category()};
842+
if (cat != Category::Numeric && cat != Category::Logical) {
843+
std::string details = " has the POINTER attribute";
844+
if (const auto *derived{typeSpec->AsDerived()}) {
845+
details +=
846+
" and derived type '"s + derived->name().ToString() + "'";
847+
}
848+
context_.Say(lsrc,
849+
"ATOMIC WRITE requires an intrinsic scalar variable; '%s'%s"_err_en_US,
850+
sym->name(), details);
851+
return;
852+
}
853+
}
854+
}
855+
}
856+
}
832857
CheckAtomicVariable(atom, lsrc);
833858
CheckStorageOverlap(atom, {write.rhs}, source);
834859
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
! RUN: not %flang_fc1 -fopenmp -fsyntax-only %s 2>&1 | FileCheck %s
2+
type t
3+
end type
4+
type(t), pointer :: a1, a2
5+
!$omp atomic write
6+
a1 = a2
7+
! CHECK: error: ATOMIC WRITE requires an intrinsic scalar variable; 'a1' has the POINTER attribute and derived type 't'
8+
end

0 commit comments

Comments
 (0)