Issue 123534
Summary [Flang] Compilation abnormally terminates when interface declaration of function in module is inconsistent with definition of function outside the module
Labels flang
Assignees
Reporter ohno-fj
    ```
Version of flang : 20.0.0(f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)/AArch64
```

The attached program is incorrect.  
`interface` declaration of `function (px6)` in `module` is inconsistent with definition of `function (px6)` outside the `module`.  
- The former: `result-name` is defined as a procedure pointer with an `interface-name` of x2.  
- The latter: `result-name` is defined as a procedure pointer with an `interface-name` of x2. and it is associated with the function x2.  

In the above case, a compilation terminates abnormally. 
This should be detected as an error during compilation.  

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

sngg520i_2.f90:
```fortran
module mod
  interface
 function px6() result(r)
       interface
          function x2(i) result(r)
            character(i),pointer::r
          end function x2
 end interface
       procedure (x2),pointer :: r
     end function px6
  end interface
  procedure (x1),pointer :: p
contains
  function x1(i) result(r)
    character(i),pointer::r
    allocate(r)
    r='12'
 end function x1
end module mod

subroutine s1
  use mod
  p=>px6()
  if (p(2)/='12')print *,3
end subroutine s1

program main
  call s1
  print *,'pass'
end program main

function x2(i) result(r)
 character(i),pointer::r
  allocate(r)
  r='12'
end function x2

function px6() result(r)
  interface
     function x2(i) result(r)
 character(i),pointer::r
     end function x2
  end interface
  procedure (x2),pointer :: r
  r=>x2
end function px6

```

```
$ flang sngg520i_2.f90

fatal internal error: CHECK(symbol.has<DerivedTypeDetails>()) failed at /work/groups/ssoft/compiler/llvm/src/llvm-main/flang/lib/Semantics/mod-file.cpp(1783)
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0.      Program arguments: /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang -fc1 -triple aarch64-unknown-linux-gnu -emit-obj -mrelocation-model pic -pic-level 2 -pic-is-pie -target-cpu generic -target-feature +outline-atomics -target-feature +v8a -target-feature +fp-armv8 -target-feature
 +neon -resource-dir /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/lib/clang/20 -mframe-pointer=non-leaf -o /tmp/sngg520i_2-e3167b.o -x f95-cpp-input sngg520i_2.f90
 #0 0x000040003ef271a0 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59e71a0)
 #1 0x000040003ef25228 llvm::sys::RunSignalHandlers() (/work/groups/ssoft/compiler/llvm/aarch64/main-latest/lib/libLLVM.so.20.0git+0x59e5228)
 #2 0x000040003ef25380 SignalHandler(int) Signals.cpp:0:0
 #3 0x00004000345607a0 (linux-vdso.so.1+0x7a0)
 #4 0x0000400043da6274 raise (/lib64/libc.so.6+0x36274)
 #5 0x0000400043d90a2c abort (/lib64/libc.so.6+0x20a2c)
 #6 0x0000000006d9de34 (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x6d9de34)
 #7 0x0000000005fc41e4 (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc41e4)
 #8 0x0000000005fc456c Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc456c)
 #9 0x0000000005fc4760 Fortran::semantics::SubprogramSymbolCollector::DoParamValue(Fortran::semantics::ParamValue const&) (.part.5305) mod-file.cpp:0:0
#10 0x0000000005fc4630 Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc4630)
#11 0x0000000005fc45dc Fortran::semantics::SubprogramSymbolCollector::DoSymbol(Fortran::parser::CharBlock const&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc45dc)
#12 0x0000000005fc4c04 Fortran::semantics::SubprogramSymbolCollector::Collect() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc4c04)
#13 0x0000000005fc537c Fortran::semantics::ModFileWriter::PutSubprogram(Fortran::semantics::Symbol const&) (.part.5310) mod-file.cpp:0:0
#14 0x0000000005fc2d80 Fortran::semantics::ModFileWriter::PutSymbol(llvm::raw_ostream&, Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fc2d80)
#15 0x0000000005fcc980 Fortran::semantics::ModFileWriter::PutSymbols(Fortran::semantics::Scope const&, std::set<Fortran::common::Reference<Fortran::semantics::Symbol const>, Fortran::semantics::SymbolAddressCompare, std::allocator<Fortran::common::Reference<Fortran::semantics::Symbol const>>>*) (/work/groups/ssoft/c
ompiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcc980)
#16 0x0000000005fcad8c Fortran::semantics::ModFileWriter::Write(Fortran::semantics::Symbol const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcad8c)
#17 0x0000000005fcd060 Fortran::semantics::ModFileWriter::WriteAll() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5fcd060)
#18 0x0000000006013328 Fortran::semantics::Semantics::Perform() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x6013328)
#19 0x0000000005860680 Fortran::frontend::FrontendAction::runSemanticChecks() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5860680)
#20 0x000000000594d214 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x594d214)
#21 0x0000000005862954 Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5862954)
#22 0x0000000005852e48 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5852e48)
#23 0x00000000058671e4 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x58671e4)
#24 0x000000000584b620 fc1_main(llvm::ArrayRef<char const*>, char const*) (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x584b620)
#25 0x000000000584b078 main (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x584b078)
#26 0x0000400043d94384 __libc_start_main (/lib64/libc.so.6+0x24384)
#27 0x0000000005849544 _start (/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang+0x5849544)
flang-20: error: unable to execute command: Aborted (core dumped)
flang-20: error: flang frontend command failed due to signal (use -v to see invocation)
flang version 20.0.0git (https://github.com/llvm/llvm-project.git f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)
Target: aarch64-unknown-linux-gnu
Thread model: posix
InstalledDir: /work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin
Build config: +assertions
flang-20: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
flang-20: note: diagnostic msg: /tmp/sngg520i_2-f292c8
flang-20: note: diagnostic msg: /tmp/sngg520i_2-f292c8.sh
flang-20: note: diagnostic msg:

********************
$
```

```
$ cat /tmp/sngg520i_2-f292c8
#line "./sngg520i_2.f90" 1
      module mod
 interface
      function px6() result(r)
       interface
 function x2(i) result(r)
            character(i),pointer::r
          end function x2
       end interface
       procedure (x2),pointer :: r
 end function px6
      end interface
      procedure(x1),pointer :: p
 contains
      function x1(i) result(r)
      character(i),pointer::r
 allocate(r)
      r='12'
      end function x1
      end module mod

 subroutine s1
      use mod
      p=>px6()
      if(p(2)/='12')print *,3
      end subroutine s1

      program main
      call s1
 print *,'pass'
      end program main

      function x2(i) result(r)
 character(i),pointer::r
      allocate(r)
      r='12'
      end function x2

      function px6() result(r)
      interface
 function x2(i) result(r)
       character(i),pointer::r
      end function x2
      end interface
      procedure(x2),pointer :: r
      r=>x2
 end function px6
$
```

```
$ cat /tmp/sngg520i_2-f292c8.sh
# Crash reproducer for clang version 20.0.0git (https://github.com/llvm/llvm-project.git f5a35a31bfe6cbc16bec0c130f2bb3632dbf1fbf)
# Driver args: "sngg520i_2.f90"
# Original command: "/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-featur
e" "+fp-armv8" "-target-feature" "+neon" "-resource-dir" "/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/lib/clang/20" "-mframe-pointer=non-leaf" "-o" "/tmp/sngg520i_2-e3167b.o" "-x" "f95-cpp-input" "sngg520i_2.f90"
 "/work/groups/ssoft/compiler/llvm/aarch64/main-20250113-f5a35a31bfe6/bin/flang" "-fc1" "-triple" "aarch64-unknown-linux-gnu" "-emit-obj" "-mrelocation-model" "pic" "-pic-level" "2" "-pic-is-pie" "-target-cpu" "generic" "-target-feature" "+outline-atomics" "-target-feature" "+v8a" "-target-feature" "+fp-armv8" "-tar
get-feature" "+neon" "-mframe-pointer=non-leaf" "-x" "f95-cpp-input" "sngg520i_2-f292c8"
$
```

```
$ gfortran sngg520i_2.f90
sngg520i_2.f90:23:5:

   23 |   p=>px6()
      | 1
Error: Interface mismatch in procedure pointer assignment at (1): Type mismatch in function result (CHARACTER(0)/REAL(4))
sngg520i_2.f90:38:0:

 22 |   use mod
      |      2
......
   38 | function px6() result(r)
 |
Warning: Type mismatch in function result (REAL(4)/CHARACTER(0)) between (1) and (2)
$
```

```
$ ifx sngg520i_2.f90
ld: /tmp/ifx1801283341ynlOUg/ifx5iC9BO.o: in function `s1_':
sngg520i_2.f90:(.text+0x65): undefined reference to `mod_mp_px6_.2'
ld: /tmp/ifx1801283341ynlOUg/ifx5iC9BO.o: in function `MAIN__':
sngg520i_2.f90:(.text+0x129): undefined reference to `mod_mp_px6_.2'
$
```

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to