From c8509f14ae87b5826366005c342ede92b81f9415 Mon Sep 17 00:00:00 2001 From: Jean-Didier Pailleux Date: Fri, 24 Jan 2025 15:17:05 +0100 Subject: [PATCH] [flang][Semantics] Fix ICE when compiling a mod file with parameter without type specified --- flang/lib/Semantics/mod-file.cpp | 8 +++++++- flang/test/Semantics/modfile_missing_type.f90 | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 flang/test/Semantics/modfile_missing_type.f90 diff --git a/flang/lib/Semantics/mod-file.cpp b/flang/lib/Semantics/mod-file.cpp index 51ff70c3ed834..7a60e22de726e 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 0000000000000..fda19372b8993 --- /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 +