Skip to content

Commit 062e69a

Browse files
authored
[flang][OpenMP] Fix 2 more regressions after #101009 (#101538)
PR #101009 exposed a semantic check issue with OPTIONAL dummy arguments. Another issue occurred when using %{re,im,len,kind}, as these also need to be skipped when handling variables with implicitly defined DSAs. These issues were found by Fujitsu testsuite.
1 parent d68d217 commit 062e69a

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1645,7 +1645,8 @@ static void CheckPresent(evaluate::ActualArguments &arguments,
16451645
} else {
16461646
symbol = arg->GetAssumedTypeDummy();
16471647
}
1648-
if (!symbol || !symbol->attrs().test(semantics::Attr::OPTIONAL)) {
1648+
if (!symbol ||
1649+
!symbol->GetUltimate().attrs().test(semantics::Attr::OPTIONAL)) {
16491650
messages.Say(arg ? arg->sourceLocation() : messages.at(),
16501651
"Argument of PRESENT() must be the name of a whole OPTIONAL dummy argument"_err_en_US);
16511652
}

flang/lib/Semantics/resolve-directives.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2036,20 +2036,21 @@ void OmpAttributeVisitor::Post(const parser::OpenMPAllocatorsConstruct &x) {
20362036
void OmpAttributeVisitor::Post(const parser::Name &name) {
20372037
auto *symbol{name.symbol};
20382038
auto IsPrivatizable = [](const Symbol *sym) {
2039+
auto *misc{sym->detailsIf<MiscDetails>()};
20392040
return !IsProcedure(*sym) && !IsNamedConstant(*sym) &&
20402041
!sym->owner().IsDerivedType() &&
20412042
sym->owner().kind() != Scope::Kind::ImpliedDos &&
20422043
!sym->detailsIf<semantics::AssocEntityDetails>() &&
2043-
!sym->detailsIf<semantics::NamelistDetails>();
2044+
!sym->detailsIf<semantics::NamelistDetails>() &&
2045+
(!misc ||
2046+
(misc->kind() != MiscDetails::Kind::ComplexPartRe &&
2047+
misc->kind() != MiscDetails::Kind::ComplexPartIm &&
2048+
misc->kind() != MiscDetails::Kind::KindParamInquiry &&
2049+
misc->kind() != MiscDetails::Kind::LenParamInquiry &&
2050+
misc->kind() != MiscDetails::Kind::ConstructName));
20442051
};
20452052

20462053
if (symbol && !dirContext_.empty() && GetContext().withinConstruct) {
2047-
// Exclude construct-names
2048-
if (auto *details{symbol->detailsIf<semantics::MiscDetails>()}) {
2049-
if (details->kind() == semantics::MiscDetails::Kind::ConstructName) {
2050-
return;
2051-
}
2052-
}
20532054
if (IsPrivatizable(symbol) && !IsObjectWithDSA(*symbol)) {
20542055
// TODO: create a separate function to go through the rules for
20552056
// predetermined, explicitly determined, and implicitly
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
! RUN: %flang_fc1 -fopenmp -fsyntax-only %s
2+
3+
! Check that using %re/%im inside 'parallel' doesn't cause syntax errors.
4+
subroutine test_complex_re_im
5+
complex :: cc(4) = (1,2)
6+
integer :: i
7+
8+
!$omp parallel do private(cc)
9+
do i = 1, 4
10+
print *, cc(i)%re, cc(i)%im
11+
end do
12+
!$omp end parallel do
13+
end subroutine
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
! RUN: %flang_fc1 -fopenmp -fsyntax-only %s
2+
3+
! Check that using 'present' inside 'parallel' doesn't cause syntax errors.
4+
subroutine test_present(opt)
5+
integer, optional :: opt
6+
!$omp parallel
7+
if (present(opt)) print *, "present"
8+
!$omp end parallel
9+
end subroutine

0 commit comments

Comments
 (0)