[flang-commits] [flang] [flang] Fix crash in fuzzing test (PR #122189)

Peter Klausler via flang-commits flang-commits at lists.llvm.org
Wed Jan 8 15:18:33 PST 2025


https://github.com/klausler created https://github.com/llvm/llvm-project/pull/122189

Fixes https://github.com/llvm/llvm-project/issues/121972.

>From bf36c4cd49bd6f97d50f4213bb6fe67b397e1641 Mon Sep 17 00:00:00 2001
From: Peter Klausler <pklausler at nvidia.com>
Date: Wed, 8 Jan 2025 15:16:52 -0800
Subject: [PATCH] [flang] Fix crash in fuzzing test

Fixes https://github.com/llvm/llvm-project/issues/121972.
---
 flang/lib/Evaluate/tools.cpp       | 3 +++
 flang/test/Semantics/bug121972.f90 | 5 +++++
 2 files changed, 8 insertions(+)
 create mode 100644 flang/test/Semantics/bug121972.f90

diff --git a/flang/lib/Evaluate/tools.cpp b/flang/lib/Evaluate/tools.cpp
index 6bd623a690e380..2d0e1996632fc2 100644
--- a/flang/lib/Evaluate/tools.cpp
+++ b/flang/lib/Evaluate/tools.cpp
@@ -1320,6 +1320,9 @@ template <TypeCategory TO, TypeCategory FROM>
 static std::optional<Expr<SomeType>> DataConstantConversionHelper(
     FoldingContext &context, const DynamicType &toType,
     const Expr<SomeType> &expr) {
+  if (!IsValidKindOfIntrinsicType(FROM, toType.kind())) {
+    return std::nullopt;
+  }
   DynamicType sizedType{FROM, toType.kind()};
   if (auto sized{
           Fold(context, ConvertToType(sizedType, Expr<SomeType>{expr}))}) {
diff --git a/flang/test/Semantics/bug121972.f90 b/flang/test/Semantics/bug121972.f90
new file mode 100644
index 00000000000000..a4c255ce2947ef
--- /dev/null
+++ b/flang/test/Semantics/bug121972.f90
@@ -0,0 +1,5 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+module acc_declare_test
+! ERROR: Initialization expression cannot be converted to declared type of 'ifcondition' from LOGICAL(4)
+ integer(16), parameter :: ifCondition = .FALSE.
+end module



More information about the flang-commits mailing list