Skip to content

Commit 329bfa9

Browse files
authored
[flang] Fix crash in CO_REDUCE semantics (llvm#131211)
A std::optional<> value was being accessed without first ensuring its presence.
1 parent 3f04fb4 commit 329bfa9

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
@@ -1688,8 +1688,10 @@ static void CheckCoReduce(
16881688
characteristics::FunctionResult::Attr::Allocatable,
16891689
characteristics::FunctionResult::Attr::Pointer,
16901690
};
1691-
const auto *result{
1692-
procChars ? procChars->functionResult->GetTypeAndShape() : nullptr};
1691+
const characteristics::TypeAndShape *result{
1692+
procChars && procChars->functionResult
1693+
? procChars->functionResult->GetTypeAndShape()
1694+
: nullptr};
16931695
if (!procChars || !procChars->IsPure() ||
16941696
procChars->dummyArguments.size() != 2 || !procChars->functionResult) {
16951697
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)