Issue 169863
Summary [Flang] Compile error when an ancestor module is referenced within submodule via USE statement
Labels flang:frontend
Assignees
Reporter ohno-fj
    ```
Version of flang : 22.0.0(7761a89e1230d8ccbb8e6ee15dc14ea74792a53c)/AArch64
```

The attached program (`test01.f90`) contains `module (mod)` and `submodule (smod)` that extends this `module (mod)`. Within `module subroutine sub` section following `CONTAINS statement` in `submodule (smod)`, the ancestor `module (mod)` is referenced via `USE statement`.

According to `Fortran Standard 2023 14.2.2 The USE statement and use association`, it states: `A module shall not reference itself, either directly or indirectly.`
and according to `Fortran Standard 2023 5.2.1 Program units and scoping units`, it states: `The module or submodule containing a module subprogram is the host scoping unit of the module subprogram.`

I believe this program does not fall under the above specification.
The scope extends only `to the definitions of declared procedures`, which is separate from `the module's program unit`, and I do not believe it falls under the above.
Therefore, the compilation error of Flang appears to be incorrect.
Is my interpretation of this specification incorrect?

The following are the test program, Flang-new, Gfortran and ifx compilation/execution result.

test01.f90:
```fortran
module mod
 integer:: var=1
  interface
    module subroutine sub
    end
  end interface
end

submodule (mod) smod
  integer:: var=100
  contains
 module subroutine sub
  use mod
   print *,var
  end
end

use mod
call sub
print *,'pass'
end
```

```
$ flang test01.f90
error: Semantic errors in test01.f90
./test01.f90:13:7: error: Module 'mod' cannot USE itself from its own submodule 'smod'
    use mod
 ^^^
$
```

```
$ gfortran test01.f90; ./a.out
           1
 pass
$
```

```
$ ifx test01.f90
test01.f90(12): error #6406: Conflicting attributes or multiple declaration of name.   [SUB]
  module subroutine sub
--------------------^
compilation aborted for test01.f90 (code 1)
$
```


_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to