From c8202db43ad0cafdc59903dadc4ea9f95a73de9b Mon Sep 17 00:00:00 2001 From: Peter Klausler Date: Tue, 14 Jan 2025 10:40:39 -0800 Subject: [PATCH] [flang] Fix crash in fuzzing test (#122189) 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 6bd623a690e3..2d0e1996632f 100644 --- a/flang/lib/Evaluate/tools.cpp +++ b/flang/lib/Evaluate/tools.cpp @@ -1320,6 +1320,9 @@ template static std::optional> DataConstantConversionHelper( FoldingContext &context, const DynamicType &toType, const Expr &expr) { + if (!IsValidKindOfIntrinsicType(FROM, toType.kind())) { + return std::nullopt; + } DynamicType sizedType{FROM, toType.kind()}; if (auto sized{ Fold(context, ConvertToType(sizedType, Expr{expr}))}) { diff --git a/flang/test/Semantics/bug121972.f90 b/flang/test/Semantics/bug121972.f90 new file mode 100644 index 000000000000..a4c255ce2947 --- /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