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

via flang-commits flang-commits at lists.llvm.org
Wed Jan 8 15:19:06 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

<details>
<summary>Changes</summary>

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

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


2 Files Affected:

- (modified) flang/lib/Evaluate/tools.cpp (+3) 
- (added) flang/test/Semantics/bug121972.f90 (+5) 


``````````diff
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

``````````

</details>


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


More information about the flang-commits mailing list