[flang-commits] [flang] 329bfa9 - [flang] Fix crash in CO_REDUCE semantics (#131211)

via flang-commits flang-commits at lists.llvm.org
Wed Mar 19 12:00:28 PDT 2025


Author: Peter Klausler
Date: 2025-03-19T12:00:23-07:00
New Revision: 329bfa91b06724bead2997de45b105b28f220495

URL: https://github.com/llvm/llvm-project/commit/329bfa91b06724bead2997de45b105b28f220495
DIFF: https://github.com/llvm/llvm-project/commit/329bfa91b06724bead2997de45b105b28f220495.diff

LOG: [flang] Fix crash in CO_REDUCE semantics (#131211)

A std::optional<> value was being accessed without first ensuring its
presence.

Added: 
    flang/test/Semantics/bug396.f90

Modified: 
    flang/lib/Semantics/check-call.cpp

Removed: 
    


################################################################################
diff  --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 25cc2e9535a2f..da2be08ca73ff 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1688,8 +1688,10 @@ static void CheckCoReduce(
           characteristics::FunctionResult::Attr::Allocatable,
           characteristics::FunctionResult::Attr::Pointer,
       };
-  const auto *result{
-      procChars ? procChars->functionResult->GetTypeAndShape() : nullptr};
+  const characteristics::TypeAndShape *result{
+      procChars && procChars->functionResult
+          ? procChars->functionResult->GetTypeAndShape()
+          : nullptr};
   if (!procChars || !procChars->IsPure() ||
       procChars->dummyArguments.size() != 2 || !procChars->functionResult) {
     messages.Say(

diff  --git a/flang/test/Semantics/bug396.f90 b/flang/test/Semantics/bug396.f90
new file mode 100644
index 0000000000000..6567f6933c71f
--- /dev/null
+++ b/flang/test/Semantics/bug396.f90
@@ -0,0 +1,6 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+external ext
+integer caf[*]
+!ERROR: OPERATION= argument of CO_REDUCE() must be a pure function of two data arguments
+call co_reduce(caf, ext)
+end


        


More information about the flang-commits mailing list