<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/144530>144530</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] generation of invalid module file
</td>
</tr>
<tr>
<th>Labels</th>
<td>
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
MarDiehl
</td>
</tr>
</table>
<pre>
I’m trying to compile DAMASK with clang+flang but encounter an issue related to the generation of module files for submodules. The code has nested submodules. That works in general, i.e. I could not reproduce the error with a MWE.
The error message explains the situation nicely.
```
error: Semantic errors in /tmp/DAMASK/src/phase_mechanical_plastic.f90
./phase-mechanical.mod:3:5: error: Module 'phase' cannot USE itself from its own submodule 'mechanical'
use phase,only:ph
^^^^^
./phase-mechanical.mod:3:16: error: 'ph' not found in module 'phase'
use phase,only:ph
^^
./phase-mechanical.mod:4:1: error: PRIVATE statement may only appear in the specification part of a module
private::ph
```
the content of the module file is given below.
Since I cannot build an MWE, I've creates a [script](https://github.com/user-attachments/files/20776631/run_sh.txt) that triggers the issue. Besides flang, clang, and clang++ it needs build tools like CMake and make. It installs PETSc with HDF5 and then a minimal version of DAMASK.
```
#! /usr/bin/env bash
cd $(mktemp -d)
git clone git@gitlab.com:petsc/petsc.git
cd petsc
git checkout 8c8ad5034fba97ace90de833fd30fd3e0748fc58
export PETSC_DIR=${PWD}
export PETSC_ARCH=flang_test
./configure \
--with-cc=clang --with-cxx=clang++ --with-fc=flang \
-FOPTFLAGS='-O0 -g' -COPTFLAGS='-O0 -g' -CXXOPTFLAGS='-O0 -g' \
--with-fortran-bindings=1 --with-mpi-f90module-visibility=1 --with-shared-libraries=1 \
--download-mpich=1 \
--download-hdf5=1 --with-hdf5-fortran-bindings=1 --with-hdf5-cxx-bindings=1
make all
cd ..
wget https://martin-diehl.net/download/DAMASK.tar.xz
tar -xf DAMASK.tar.xz
cd DAMASK
make test OPENMP=OFF
```
[](url)
```
!mod$ v1 sum:a3d8a5a7569feda3
submodule(phase) mechanical
use phase,only:ph
private::ph
type(ttensorcontainer),allocatable::phase_mechanical_fe(:)
type(ttensorcontainer),allocatable::phase_mechanical_fi(:)
type(ttensorcontainer),allocatable::phase_mechanical_fp(:)
type(ttensorcontainer),allocatable::phase_mechanical_f(:)
type(ttensorcontainer),allocatable::phase_mechanical_li(:)
type(ttensorcontainer),allocatable::phase_mechanical_lp(:)
type(ttensorcontainer),allocatable::phase_mechanical_s(:)
type(ttensorcontainer),allocatable::phase_mechanical_p(:)
type(ttensorcontainer),allocatable::phase_mechanical_fi0(:)
type(ttensorcontainer),allocatable::phase_mechanical_fp0(:)
type(ttensorcontainer),allocatable::phase_mechanical_f0(:)
type(ttensorcontainer),allocatable::phase_mechanical_li0(:)
type(ttensorcontainer),allocatable::phase_mechanical_lp0(:)
type(ttensorcontainer),allocatable::phase_mechanical_s0(:)
interface
module subroutine eigen_init(phases)
type(tdict),pointer::phases
end
end interface
interface
module subroutine elastic_init(phases)
type(tdict),pointer::phases
end
end interface
interface
module subroutine plastic_init()
end
end interface
interface
module subroutine phase_hooke_sanditstangents(s,ds_dfe,ds_dfi,fe,fi,ph,en)
real(8),intent(out)::s(1_8:3_8,1_8:3_8)
real(8),intent(out)::ds_dfe(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(out)::ds_dfi(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(in)::fe(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi(1_8:3_8,1_8:3_8)
integer(4),intent(in)::ph
integer(4),intent(in)::en
end
end interface
interface
module subroutine plastic_isotropic_lianditstangent(li,dli_dmi,mi,ph,en)
real(8),intent(out)::li(1_8:3_8,1_8:3_8)
real(8),intent(out)::dli_dmi(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(in)::mi(1_8:3_8,1_8:3_8)
integer(4),intent(in)::ph
integer(4),intent(in)::en
end
end interface
interface
module function plastic_dotstate(subdt,ph,en) result(dotstate)
real(8),intent(in)::subdt
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::dotstate(1_8:int(plasticstate(int(ph,kind=8))%tstate%sizedotstate,kind=8))
end
end interface
interface
module function plastic_deltastate(ph,en) result(status)
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
end interface
interface
module subroutine phase_lianditstangents(li,dli_ds,dli_dfi,s,fi,ph,en)
real(8),intent(out)::li(1_8:3_8,1_8:3_8)
real(8),intent(out)::dli_ds(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(out)::dli_dfi(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(in)::s(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi(1_8:3_8,1_8:3_8)
integer(4),intent(in)::ph
integer(4),intent(in)::en
end
end interface
interface
module subroutine plastic_lpanditstangents(lp,dlp_ds,dlp_dfi,s,fi,ph,en)
real(8),intent(out)::lp(1_8:3_8,1_8:3_8)
real(8),intent(out)::dlp_ds(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(out)::dlp_dfi(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
real(8),intent(in)::s(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi(1_8:3_8,1_8:3_8)
integer(4),intent(in)::ph
integer(4),intent(in)::en
end
end interface
interface
module subroutine plastic_isotropic_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module subroutine plastic_phenopowerlaw_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module subroutine plastic_kinehardening_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module subroutine plastic_dislotwin_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module subroutine plastic_dislotungsten_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module subroutine plastic_nonlocal_result(ph,group)
integer(4),intent(in)::ph
character(*,1),intent(in)::group
end
end interface
interface
module function plastic_dislotwin_homogenizedc(ph,en) result(homogenizedc)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::homogenizedc(1_8:6_8,1_8:6_8)
end
end interface
interface
module pure function elastic_c66(ph,en) result(c66)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::c66(1_8:6_8,1_8:6_8)
end
end interface
interface
module pure function elastic_mu(ph,en,isotropic_bound) result(mu)
integer(4),intent(in)::ph
integer(4),intent(in)::en
character(*,1),intent(in)::isotropic_bound
real(8)::mu
end
end interface
interface
module pure function elastic_nu(ph,en,isotropic_bound) result(nu)
integer(4),intent(in)::ph
integer(4),intent(in)::en
character(*,1),intent(in)::isotropic_bound
real(8)::nu
end
end interface
type::toutput
character(256_4,1),allocatable::label(:)
end type
type(toutput),allocatable::output_mechanical(:)
procedure(integratestatefpi),pointer::integratestate
contains
module subroutine mechanical_init(phases,num_mech)
type(tdict),pointer::phases
type(tdict),pointer::num_mech
end
module subroutine mechanical_result(group,ph)
character(*,1),intent(in)::group
integer(4),intent(in)::ph
end
function integratestress(f,fp0,fi0,delta_t,ph,en) result(status)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestatefpi(f_0,f,fp0,fi0,state0,delta_t,ph,en) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestateeuler(f_0,f,fp0,fi0,state0,delta_t,ph,en) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestateeuleradaptive(f_0,f,fp0,fi0,state0,delta_t,ph,en) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestaterk4(f_0,f,fp0,fi0,state0,delta_t,ph,en) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestaterkck45(f_0,f,fp0,fi0,state0,delta_t,ph,en) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
integer(4)::status
end
function integratestaterk(f_0,f,fp0,fi0,state0,delta_t,ph,en,a,b,c,db) result(status)
real(8),intent(in)::f_0(1_8:3_8,1_8:3_8)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
real(8),intent(in)::fp0(1_8:3_8,1_8:3_8)
real(8),intent(in)::fi0(1_8:3_8,1_8:3_8)
real(8),intent(in)::state0(:)
real(8),intent(in)::delta_t
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8),intent(in)::a(:,:)
real(8),intent(in)::b(:)
real(8),intent(in)::c(:)
real(8),intent(in),optional::db(:)
integer(4)::status
end
subroutine results(group,ph)
character(*,1),intent(in)::group
integer(4),intent(in)::ph
end
module subroutine mechanical_forward()
end
module function phase_mechanical_constitutive(delta_t,co,ce) result(status)
real(8),intent(in)::delta_t
integer(4),intent(in)::co
integer(4),intent(in)::ce
integer(4)::status
end
module subroutine mechanical_restore(ce,includel)
integer(4),intent(in)::ce
logical(4),intent(in)::includel
end
module function phase_mechanical_dpdf(delta_t,co,ce) result(dpdf)
real(8),intent(in)::delta_t
integer(4),intent(in)::co
integer(4),intent(in)::ce
real(8)::dpdf(1_8:3_8,1_8:3_8,1_8:3_8,1_8:3_8)
end
module subroutine mechanical_restartwrite(grouphandle,ph)
integer(8),intent(in)::grouphandle
integer(4),intent(in)::ph
end
module subroutine mechanical_restartread(grouphandle,ph)
integer(8),intent(in)::grouphandle
integer(4),intent(in)::ph
end
module function mechanical_s(ph,en) result(s)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::s(1_8:3_8,1_8:3_8)
end
module function mechanical_l_p(ph,en) result(l_p)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::l_p(1_8:3_8,1_8:3_8)
end
module function mechanical_f_e(ph,en) result(f_e)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::f_e(1_8:3_8,1_8:3_8)
end
module function mechanical_f_i(ph,en) result(f_i)
integer(4),intent(in)::ph
integer(4),intent(in)::en
real(8)::f_i(1_8:3_8,1_8:3_8)
end
module function phase_p(co,ce) result(p)
integer(4),intent(in)::co
integer(4),intent(in)::ce
real(8)::p(1_8:3_8,1_8:3_8)
end
module function phase_f(co,ce) result(f)
integer(4),intent(in)::co
integer(4),intent(in)::ce
real(8)::f(1_8:3_8,1_8:3_8)
end
module subroutine phase_set_f(f,co,ce)
real(8),intent(in)::f(1_8:3_8,1_8:3_8)
integer(4),intent(in)::co
integer(4),intent(in)::ce
end
end
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzsW0tv4zgS_jXMhbAhU5YfhxzcdrzT2M12Y7p3Z24GRZYkbihSIKk85tcvSMnPxI4TO5nJIEEQK2Kx-FXVV8WHJWqtyBXAJUq-oGR2QWtXaHN5Tc1MQCEvUs0fLr-iK4JGERqPS-zMg1A5dhozXVZCAp5Nric__onvhCswk1TliHzJ_CdOa4dBMV0rBwZThYW1NWADkjrgXocrAOegwFAntMI6w6XmtQScCQkWZ9pgW6fNPdvFPwvATHPABbVYgfVattupw3fa3FgsVKtYIjLFogtd_BUzXUuOlXbYQGU0rxkECGCMNo0FFF__dtVF0QRFk5-rphKspTlguK8kFcqGXla4usGtBAP50PZCg6j9jSahN4on-AeUVDnBGn0BHiJzV1aIzBsHIjK3hiEyrwpqYVECK6gSjMpFJal1gnWzsVfZXYp01iLdUnMUT2IUTxI_2mrY68abiAxDF0SGmFHlHfCfH1dYOAsyw5nRpb_G-k6t3ek7rUdAZIiiCca1BdyqmmolH1A8qYrQ4n9QcrX1-yza3mALbsDpQXqEma4V944qHxlxBJSNn2PA9D2YLSzff_3638nPK2wddVCCcrikD9gPhGlVATUeWqBBBUxkgjVUqKhxnse0hR0AVUbcUgconixBbpIERRMXiK2cH0ZnQe1GImBhcS5uQeEUpL5refZDKAae1E1A01pI7pPs-rcrT_mviAxvATMD1IHFFKPki2VGVA4lM0RGhXOV9YjIHJF5LlxRp12mS0TmtQXToc5RVnjDLSLzkI-IzEk0HA4GcQ-RuanVwhZdd-8QGWPnU88ZkedgmvQIyd7FX8AK7nO5KQ3TZY2YYqr4qmAg8gULhxUAt60pTmtpsRQ3gKfX9AaCfElvfCY7LJR1VEqLv1_9_MGa3P1lNk-ClCtA-QgIJUoq8S0Y25aXJte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