Skip to content
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

[flang] Fix crash in fuzzing test #122189

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

klausler
Copy link
Contributor

@klausler klausler commented Jan 8, 2025

Fixes #121972.

@llvmbot llvmbot added flang Flang issues not falling into any other category flang:semantics labels Jan 8, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 8, 2025

@llvm/pr-subscribers-flang-semantics

Author: Peter Klausler (klausler)

Changes

Fixes #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 --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

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
4 participants