[flang-commits] [flang] [flang] Fixed a crash in CheckReduce() (PR	#156382)
    Eugene Epshteyn via flang-commits 
    flang-commits at lists.llvm.org
       
    Mon Sep  1 18:41:12 PDT 2025
    
    
  
https://github.com/eugeneepshteyn updated https://github.com/llvm/llvm-project/pull/156382
>From 6014bf06ecb1c0fdfcc5e8fc9b24ece758ed06d8 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Mon, 1 Sep 2025 21:33:35 -0400
Subject: [PATCH 1/3] [flang] Fixed a crash in CheckReduce()
Added extra checks to fix the crash.
Fixes #156167
---
 flang/lib/Semantics/check-call.cpp | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index a9cfe4d059982..c71b3067c4190 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1986,7 +1986,8 @@ static void CheckReduce(
     }
   }
   const auto *result{
-      procChars ? procChars->functionResult->GetTypeAndShape() : nullptr};
+      procChars && procChars->functionResult ?
+          procChars->functionResult->GetTypeAndShape() : nullptr};
   if (!procChars || !procChars->IsPure() ||
       procChars->dummyArguments.size() != 2 || !procChars->functionResult) {
     messages.Say(
>From d07fd080ba6f7c7640f21227dc41df519108d139 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Mon, 1 Sep 2025 21:35:36 -0400
Subject: [PATCH 2/3] clang-format
---
 flang/lib/Semantics/check-call.cpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/flang/lib/Semantics/check-call.cpp b/flang/lib/Semantics/check-call.cpp
index c71b3067c4190..f0078fda3600c 100644
--- a/flang/lib/Semantics/check-call.cpp
+++ b/flang/lib/Semantics/check-call.cpp
@@ -1985,9 +1985,9 @@ static void CheckReduce(
       }
     }
   }
-  const auto *result{
-      procChars && procChars->functionResult ?
-          procChars->functionResult->GetTypeAndShape() : nullptr};
+  const auto *result{procChars && procChars->functionResult
+          ? procChars->functionResult->GetTypeAndShape()
+          : nullptr};
   if (!procChars || !procChars->IsPure() ||
       procChars->dummyArguments.size() != 2 || !procChars->functionResult) {
     messages.Say(
>From 9085af14bd931a52941311aa78738de76f5070b2 Mon Sep 17 00:00:00 2001
From: Eugene Epshteyn <eepshteyn at nvidia.com>
Date: Mon, 1 Sep 2025 21:41:01 -0400
Subject: [PATCH 3/3] Updated LIT test
---
 flang/test/Semantics/reduce01.f90 | 4 ++++
 1 file changed, 4 insertions(+)
diff --git a/flang/test/Semantics/reduce01.f90 b/flang/test/Semantics/reduce01.f90
index ad63a42d73cae..3384366db812f 100644
--- a/flang/test/Semantics/reduce01.f90
+++ b/flang/test/Semantics/reduce01.f90
@@ -71,6 +71,8 @@ pure function f11(x,y) result(res)
     type(pdt(max(x%len, y%len))) :: res
     res%ch = x%ch // y%ch
   end function
+  subroutine bad_reduce
+  end subroutine
 
   subroutine errors
     real :: a(10,10), b, c(10)
@@ -115,6 +117,8 @@ subroutine errors
     !ERROR: MASK= has no .TRUE. element, so IDENTITY= must be present
     b = reduce(a, f, reshape([(j > 100, j=1, 100)], shape(a)))
     b = reduce(a, f, reshape([(j == 50, j=1, 100)], shape(a))) ! ok
+    !ERROR: OPERATION= argument of REDUCE() must be a pure function of two data arguments
+    b = reduce(a, bad_reduce)
   end subroutine
   subroutine not_errors
     type(pdt(10)) :: a(10), b
    
    
More information about the flang-commits
mailing list