Issue |
133646
|
Summary |
[flang] The function result `res(max(n, 0))` has distinct extents when split across a module and its submodule
|
Labels |
flang
|
Assignees |
|
Reporter |
osada-yum
|
## Description
Flang 20.1.1 cannot compile files that define a function returning `res(max(n, 0))` in a module/submodule split, but it does compile successfully if the function and its implementation are placed in a single file.
```bash
$ flang -c bug_sub.f90 bug.f90
error: Semantic errors in bug_sub.f90
./bug_sub.f90:4:24: error: Result of function 'f1' is not compatible with the result of the corresponding interface body: function results have distinct extents (max(0_8,int(max(n,0_4),kind=8)) vs max(0_8,int(max(n,0_4),kind=8)))
pure module function f1(n) result(res)
^^
./test_m.mod:4:22: Declaration of 'f1'
module pure function f1(n) result(res)
^^
./bug_sub.f90:9:24: error: Result of function 'f2' is not compatible with the result of the corresponding interface body: function results have distinct extents (max(0_8,int(min(n,0_4),kind=8)) vs max(0_8,int(min(n,0_4),kind=8)))
pure module function f2(n) result(res)
^^
./test_m.mod:10:22: Declaration of 'f2'
module pure function f2(n) result(res)
^^
$ flang -c bug_in_one.f90
(Compilation success)
```
### bug.f90
```bug.f90
module test_m
implicit none
private
public :: f1, f2
interface f1
pure module function f1(n) result(res)
integer, intent(in) :: n
integer :: res(max(n, 0))
end function f1
end interface f1
interface f2
pure module function f2(n) result(res)
integer, intent(in) :: n
integer :: res(min(n, 0))
end function f2
end interface f2
end module test_m
```
### bug_sub.f90
```bug_sub.f90
submodule (test_m) test_sub_m
implicit none
contains
pure module function f1(n) result(res)
integer, intent(in) :: n
integer :: res(max(n, 0))
res(:) = 0
end function f1
pure module function f2(n) result(res)
integer, intent(in) :: n
integer :: res(min(n, 0))
res(:) = 0
end function f2
end submodule test_sub_m
```
### bug_in_one.f90
```bug_in_one.f90
module test_in_one_m
implicit none
private
public :: f1, f2
interface f1
pure module function f1(n) result(res)
integer, intent(in) :: n
integer :: res(max(n, 0))
end function f1
end interface f1
interface f2
pure module function f2(n) result(res)
integer, intent(in) :: n
integer :: res(min(n, 0))
end function f2
end interface f2
end module test_in_one_m
submodule (test_in_one_m) test_in_one_sub_m
implicit none
contains
pure module function f1(n) result(res)
integer, intent(in) :: n
integer :: res(max(n, 0))
res(:) = 0
end function f1
pure module function f2(n) result(res)
integer, intent(in) :: n
integer :: res(min(n, 0))
res(:) = 0
end function f2
end submodule test_in_one_sub_m
```
## OS, environment
- CPU(x86_64)
Intel(R) Core(TM) i7-3632QM CPU @ 2.20GHz
```bash
$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 22.04.5 LTS
Release: 22.04
Codename: jammy
$ flang --version
flang version 20.1.1 (https://github.com/llvm/llvm-project 424c2d9b7e4de40d0804dd374721e6411c27d1d1)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/flang/LLVM-20.1.1-Linux-X64/bin
```
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs