Skip to content

Commit 7f64e8f

Browse files
authored
[flang][openacc] Avoid crash when variable is not declared in reduction (#114603)
1 parent 4006b28 commit 7f64e8f

File tree

2 files changed

+26
-19
lines changed

2 files changed

+26
-19
lines changed

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -674,26 +674,28 @@ void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
674674
common::visitors{
675675
[&](const parser::Designator &designator) {
676676
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
677-
const auto *type{name->symbol->GetType()};
678-
if (type->IsNumeric(TypeCategory::Integer) &&
679-
!reductionIntegerSet.test(op.v)) {
680-
context_.Say(GetContext().clauseSource,
681-
"reduction operator not supported for integer type"_err_en_US);
682-
} else if (type->IsNumeric(TypeCategory::Real) &&
683-
!reductionRealSet.test(op.v)) {
684-
context_.Say(GetContext().clauseSource,
685-
"reduction operator not supported for real type"_err_en_US);
686-
} else if (type->IsNumeric(TypeCategory::Complex) &&
687-
!reductionComplexSet.test(op.v)) {
688-
context_.Say(GetContext().clauseSource,
689-
"reduction operator not supported for complex type"_err_en_US);
690-
} else if (type->category() ==
691-
Fortran::semantics::DeclTypeSpec::Category::Logical &&
692-
!reductionLogicalSet.test(op.v)) {
693-
context_.Say(GetContext().clauseSource,
694-
"reduction operator not supported for logical type"_err_en_US);
677+
if (name->symbol) {
678+
const auto *type{name->symbol->GetType()};
679+
if (type->IsNumeric(TypeCategory::Integer) &&
680+
!reductionIntegerSet.test(op.v)) {
681+
context_.Say(GetContext().clauseSource,
682+
"reduction operator not supported for integer type"_err_en_US);
683+
} else if (type->IsNumeric(TypeCategory::Real) &&
684+
!reductionRealSet.test(op.v)) {
685+
context_.Say(GetContext().clauseSource,
686+
"reduction operator not supported for real type"_err_en_US);
687+
} else if (type->IsNumeric(TypeCategory::Complex) &&
688+
!reductionComplexSet.test(op.v)) {
689+
context_.Say(GetContext().clauseSource,
690+
"reduction operator not supported for complex type"_err_en_US);
691+
} else if (type->category() ==
692+
Fortran::semantics::DeclTypeSpec::Category::Logical &&
693+
!reductionLogicalSet.test(op.v)) {
694+
context_.Say(GetContext().clauseSource,
695+
"reduction operator not supported for logical type"_err_en_US);
696+
}
697+
// TODO: check composite type.
695698
}
696-
// TODO: check composite type.
697699
}
698700
},
699701
[&](const Fortran::parser::Name &name) {

flang/test/Semantics/OpenACC/acc-reduction-validity.f90

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
! Check OpenACC reduction validity.
44

55
program openacc_reduction_validity
6+
implicit none
67

78
integer :: i
89
real :: r
@@ -168,5 +169,9 @@ program openacc_reduction_validity
168169
!$acc parallel reduction(ieor:l)
169170
!$acc end parallel
170171

172+
!ERROR: No explicit type declared for 'xyz'
173+
!$acc parallel reduction(+:xyz)
174+
!$acc end parallel
175+
171176

172177
end program

0 commit comments

Comments
 (0)