<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/137126>137126</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[flang] Flang is unable to lower to LLVM IR
</td>
</tr>
<tr>
<th>Labels</th>
<td>
flang
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
inaki-amatria
</td>
</tr>
</table>
<pre>
- `flang` version is: `flang version 21.0.0git (git@github.com:inaki-amatria/llvm-project.git 054ee17f88fcd4dd8d646740b975ef1d2f4ea3aa)`
- Reduced test case:
```fortran
! foo.f90
program main
use external_types
contains
subroutine foo()
type(external_data_t) :: foo_list
end
subroutine bar(bar_patch)
type(patch_t) :: bar_patch
end
end
! bar.f90
module model
type :: subset_range_t
type(patch_t), pointer :: p => null()
end type
type :: grid_vertices_t
type(subset_range_t) :: domain
end type
type :: patch_t
type(grid_vertices_t) :: verts
end type
end
module var_metadata
use model
type :: var_metadata_t
type(subset_range_t) :: access
end type
end
module var
use var_metadata
type :: var_t
type(var_metadata_t) :: md
end type
type :: var_ptr_t
type(var_t), pointer :: p => null()
end type
end
module var_list
use var
type :: var_list_t
type(var_ptr_t) :: var
end type
type :: var_list_ptr_t
type(var_list_t), pointer :: p => null()
end type
end
module external_types
use var_list
type :: external_data_t
type(var_list_ptr_t) :: list
end type
end
```
- `flang` invocation is: `flang -fc1 -emit-llvm bar.f90 foo.f90`
- Expected behavior is: The code lowers to LLVM IR successfully
- Actual behavior: Lowering aborts with the following backtrace:
```
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace.
Stack dump:
0. Program arguments: /home/inaki/repos/llvm-project/build/bin/flang -fc1 -emit-llvm bar.f90 foo.f90
#0 0x00006517c534a6b6 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/home/inaki/repos/llvm-project/build/bin/flang+0x27656b6)
#1 0x00006517c534818e llvm::sys::RunSignalHandlers() (/home/inaki/repos/llvm-project/build/bin/flang+0x276318e)
#2 0x00006517c534b014 SignalHandler(int, siginfo_t*, void*) Signals.cpp:0:0
#3 0x000077fd16c4bcd0 (/usr/lib/libc.so.6+0x3dcd0)
#4 0x00006517ca44bb78 mlir::Operation::~Operation() (/home/inaki/repos/llvm-project/build/bin/flang+0x7866b78)
#5 0x00006517ca44c58d llvm::ilist_traits<mlir::Operation>::deleteNode(mlir::Operation*) (/home/inaki/repos/llvm-project/build/bin/flang+0x786758d)
#6 0x00006517ca39e457 mlir::Block::clear() Block.cpp:0:0
#7 0x00006517ca39e32d mlir::Block::~Block() (/home/inaki/repos/llvm-project/build/bin/flang+0x77b932d)
#8 0x00006517ca45fde3 mlir::Region::~Region() (/home/inaki/repos/llvm-project/build/bin/flang+0x787ade3)
#9 0x00006517ca44bb48 mlir::Operation::~Operation() (/home/inaki/repos/llvm-project/build/bin/flang+0x7866b48)
#10 0x00006517ca44c58d llvm::ilist_traits<mlir::Operation>::deleteNode(mlir::Operation*) (/home/inaki/repos/llvm-project/build/bin/flang+0x786758d)
#11 0x00006517ca39e457 mlir::Block::clear() Block.cpp:0:0
#12 0x00006517ca39e32d mlir::Block::~Block() (/home/inaki/repos/llvm-project/build/bin/flang+0x77b932d)
#13 0x00006517ca45fde3 mlir::Region::~Region() (/home/inaki/repos/llvm-project/build/bin/flang+0x787ade3)
#14 0x00006517ca44bb48 mlir::Operation::~Operation() (/home/inaki/repos/llvm-project/build/bin/flang+0x7866b48)
#15 0x00006517ca44c6a0 mlir::Operation::erase() (/home/inaki/repos/llvm-project/build/bin/flang+0x78676a0)
#16 0x00006517c5388543 Fortran::frontend::CodeGenAction::beginSourceFileAction() (/home/inaki/repos/llvm-project/build/bin/flang+0x27a3543)
#17 0x00006517c538366f Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) (/home/inaki/repos/llvm-project/build/bin/flang+0x279e66f)
#18 0x00006517c5363203 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) (/home/inaki/repos/llvm-project/build/bin/flang+0x277e203)
#19 0x00006517c53879cd Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) (/home/inaki/repos/llvm-project/build/bin/flang+0x27a29cd)
#20 0x00006517c4ea70d4 fc1_main(llvm::ArrayRef<char const*>, char const*) (/home/inaki/repos/llvm-project/build/bin/flang+0x22c20d4)
#21 0x00006517c4ea62f6 main (/home/inaki/repos/llvm-project/build/bin/flang+0x22c12f6)
#22 0x000077fd16c35488 (/usr/lib/libc.so.6+0x27488)
#23 0x000077fd16c3554c __libc_start_main (/usr/lib/libc.so.6+0x2754c)
#24 0x00006517c4ea53a5 _start (/home/inaki/repos/llvm-project/build/bin/flang+0x22c03a5)
Segmentation fault (core dumped)
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzUWF1v2zoS_TX0CxGDIilKevCDm8a7Bbq7RXKxrwZFjmxuZdEgqTR5ub99QUm2ZMXJ7RYG7l2gjfXBOXPOzGj4Ib03uwZghdJPKP28kG3YW7cyjfxu7uRBBmfkorT6dXWHkSBVLZsdEgQ_g_PGNth4xNbnN-fHNFmSJdmZgBHNdyYgHm_2bblU9oDY-gIf0U1dPx_ujs7-B1RYRjOScoAkq_K8UpprnWvBRcZJWWQpVImmFQfJpES0QIIgsr7Dj6BbBRoH8AEr6QGxNSLr-Lr7V1kXnGziI5rgytplVUTLo7M7Jw_4IE18iXHrAcNLANfIehtej-ARWSvbBGmaeIl9WzrbBtNAhEE0jyyiJcZxOKL52VzLILcB0QJHNmwdDba18aEbD43ufieApXSI5qV026MMav8GuXt6gTiOHSH7v4PUUrpB6sHqtgZ8sBrqbnQEPeH4tvQQtk42O9iG97wieo-P1jQB3MnwiBH7jNgDbtq6nkQDGt3bzz3tnNHbZ3DBKPC9q8HPjMMoUttzet6FPZEc4eaORrz40M_hzlEb4vQs3fYAQcYknivjevCmQ-fBe1eUVAr8z7A4O3_DaM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