Skip to content

[flang] Fix crash in CO_REDUCE semantics #131211

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 19, 2025
Merged

[flang] Fix crash in CO_REDUCE semantics #131211

merged 1 commit into from
Mar 19, 2025

Conversation

klausler
Copy link
Contributor

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

A std::optional<> value was being accessed without first ensuring
its presence.
@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Mar 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Mar 13, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/131211.diff

2 Files Affected:

  • (modified) flang/lib/Semantics/check-call.cpp (+4-2)
  • (added) flang/test/Semantics/bug396.f90 (+6)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index 205b4a780258c..2991a27612f32 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1690,8 +1690,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

@klausler klausler merged commit 329bfa9 into llvm:main Mar 19, 2025
14 checks passed
@klausler klausler deleted the bug396 branch March 19, 2025 19:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flang:semantics flang Flang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants