Skip to content

[flang][Semantics] Fix ICE when compiling a mod file with parameter w… #124285

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

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

Conversation

JDPailleux
Copy link
Contributor

…ithout type specified

Fatal internal error occurred when compiling a mod file with a subroutine which contain a parameter with no
explicit type.

Ex:

   module inform
      implicit none
      interface normp
         module subroutine normt( array, n, val,p )
         integer siz
         integer,optional::p
         real*8 array(*)
         real*8 val
         end subroutine
      end interface
   end

Copy link

Thank you for submitting a Pull Request (PR) to the LLVM Project!

This PR will be automatically labeled and the relevant teams will be notified.

If you wish to, you can add reviewers by using the "Reviewers" section on this page.

If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using @ followed by their GitHub username.

If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers.

If you have further questions, they may be answered by the LLVM GitHub User Guide.

You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums.

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

llvmbot commented Jan 24, 2025

@llvm/pr-subscribers-flang-semantics

Author: Jean-Didier PAILLEUX (JDPailleux)

Changes

…ithout type specified

Fatal internal error occurred when compiling a mod file with a subroutine which contain a parameter with no
explicit type.

Ex:

   module inform
      implicit none
      interface normp
         module subroutine normt( array, n, val,p )
         integer siz
         integer,optional::p
         real*8 array(*)
         real*8 val
         end subroutine
      end interface
   end

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

2 Files Affected:

  • (modified) flang/lib/Semantics/mod-file.cpp (+7-1)
  • (added) flang/test/Semantics/modfile_missing_type.f90 (+14)
diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp
index 51ff70c3ed8341..7a60e22de726e7 100644
--- a/flang/lib/Semantics/mod-file.cpp
+++ b/flang/lib/Semantics/mod-file.cpp
@@ -955,7 +955,13 @@ void ModFileWriter::PutObjectEntity(
     }
   }
   PutEntity(
-      os, symbol, [&]() { PutType(os, DEREF(symbol.GetType())); },
+      os, symbol,
+      [&]() {
+        // Need to check if there is a TYPE on this symbol to avoid any ICE
+        if (details.type()) {
+          PutType(os, DEREF(symbol.GetType()));
+        }
+      },
       getSymbolAttrsToWrite(symbol));
   PutShape(os, details.shape(), '(', ')');
   PutShape(os, details.coshape(), '[', ']');
diff --git a/flang/test/Semantics/modfile_missing_type.f90 b/flang/test/Semantics/modfile_missing_type.f90
new file mode 100644
index 00000000000000..fda19372b8993f
--- /dev/null
+++ b/flang/test/Semantics/modfile_missing_type.f90
@@ -0,0 +1,14 @@
+! RUN: %python %S/test_errors.py %s %flang_fc1
+! Test to check that this module can be compiled when an argument has no specified type
+module inform
+  implicit none
+  interface normp
+     module subroutine normt( array,n,val,p )
+     integer siz
+     integer,optional::p
+     real*8 array(*)
+     real*8 val
+     end subroutine
+  end interface
+end
+

@clementval clementval requested a review from klausler January 24, 2025 16:13
Copy link
Contributor

@klausler klausler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This DEREF is not the bug. The bug is that the symbol has no type after name resolution, but must have one. The DEREF() here is catching the bug, and it must remain in place.

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
Development

Successfully merging this pull request may close these issues.

3 participants