Skip to content

Commit 75a1e97

Browse files
committed
[flang] Fix crash in CO_REDUCE semantics
A std::optional<> value was being accessed without first ensuring its presence.
1 parent 016557f commit 75a1e97

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

flang/lib/Semantics/check-call.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1690,8 +1690,10 @@ static void CheckCoReduce(
16901690
characteristics::FunctionResult::Attr::Allocatable,
16911691
characteristics::FunctionResult::Attr::Pointer,
16921692
};
1693-
const auto *result{
1694-
procChars ? procChars->functionResult->GetTypeAndShape() : nullptr};
1693+
const characteristics::TypeAndShape *result{
1694+
procChars && procChars->functionResult
1695+
? procChars->functionResult->GetTypeAndShape()
1696+
: nullptr};
16951697
if (!procChars || !procChars->IsPure() ||
16961698
procChars->dummyArguments.size() != 2 || !procChars->functionResult) {
16971699
messages.Say(

flang/test/Semantics/bug396.f90

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
! RUN: %python %S/test_errors.py %s %flang_fc1
2+
external ext
3+
integer caf[*]
4+
!ERROR: OPERATION= argument of CO_REDUCE() must be a pure function of two data arguments
5+
call co_reduce(caf, ext)
6+
end

0 commit comments

Comments
 (0)