Skip to content

Commit d4673fe

Browse files
authored
[flang][openacc] fix unguarded dereference of type pointer (#153606)
The added test used to cause a segfault, now it doesn't.
1 parent 0d9b9d1 commit d4673fe

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

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

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -983,24 +983,26 @@ void AccStructureChecker::Enter(const parser::AccClause::Reduction &reduction) {
983983
[&](const parser::Designator &designator) {
984984
if (const auto *name = getDesignatorNameIfDataRef(designator)) {
985985
if (name->symbol) {
986-
const auto *type{name->symbol->GetType()};
987-
if (type->IsNumeric(TypeCategory::Integer) &&
988-
!reductionIntegerSet.test(op.v)) {
989-
context_.Say(GetContext().clauseSource,
990-
"reduction operator not supported for integer type"_err_en_US);
991-
} else if (type->IsNumeric(TypeCategory::Real) &&
992-
!reductionRealSet.test(op.v)) {
993-
context_.Say(GetContext().clauseSource,
994-
"reduction operator not supported for real type"_err_en_US);
995-
} else if (type->IsNumeric(TypeCategory::Complex) &&
996-
!reductionComplexSet.test(op.v)) {
997-
context_.Say(GetContext().clauseSource,
998-
"reduction operator not supported for complex type"_err_en_US);
999-
} else if (type->category() ==
1000-
Fortran::semantics::DeclTypeSpec::Category::Logical &&
1001-
!reductionLogicalSet.test(op.v)) {
1002-
context_.Say(GetContext().clauseSource,
1003-
"reduction operator not supported for logical type"_err_en_US);
986+
if (const auto *type{name->symbol->GetType()}) {
987+
if (type->IsNumeric(TypeCategory::Integer) &&
988+
!reductionIntegerSet.test(op.v)) {
989+
context_.Say(GetContext().clauseSource,
990+
"reduction operator not supported for integer type"_err_en_US);
991+
} else if (type->IsNumeric(TypeCategory::Real) &&
992+
!reductionRealSet.test(op.v)) {
993+
context_.Say(GetContext().clauseSource,
994+
"reduction operator not supported for real type"_err_en_US);
995+
} else if (type->IsNumeric(TypeCategory::Complex) &&
996+
!reductionComplexSet.test(op.v)) {
997+
context_.Say(GetContext().clauseSource,
998+
"reduction operator not supported for complex type"_err_en_US);
999+
} else if (type->category() ==
1000+
Fortran::semantics::DeclTypeSpec::Category::
1001+
Logical &&
1002+
!reductionLogicalSet.test(op.v)) {
1003+
context_.Say(GetContext().clauseSource,
1004+
"reduction operator not supported for logical type"_err_en_US);
1005+
}
10041006
}
10051007
// TODO: check composite type.
10061008
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,3 +175,15 @@ program openacc_reduction_validity
175175

176176

177177
end program
178+
179+
subroutine sum()
180+
! ERROR: 'sum' is already declared in this scoping unit
181+
integer :: i,sum
182+
sum = 0
183+
!$acc parallel
184+
!$acc loop independent gang reduction(+:sum)
185+
do i=1,10
186+
sum = sum + i
187+
enddo
188+
!$acc end parallel
189+
end subroutine

0 commit comments

Comments
 (0)