Issue 234385
Summary [flang] Internal error on reference to an ambiguous type-bound generic proceudre
Labels flang
Assignees
Reporter ivan-pi
    The following program triggers an internal compiler on flang 23.1.1 (Homebrew, arm64-apple-darwin25.6.0):

```fortran
! flang_ice.f90
module m
 implicit none
  type :: t
  contains
    procedure :: a => sa
 procedure, nopass :: b => sb
    generic :: g => a, b
  end type
contains
  subroutine sa(x, n)
    class(t) :: x
    integer :: n
 end subroutine
  subroutine sb(n)
    integer :: n
  end subroutine
 subroutine user(v) 
    type(t) :: v
    call v%g(1)         ! <- this lines leads to ICE.
  end subroutine
end module
```

The program is invalid because the procedures `sa` and `sb` in generic `g` violate constraint C1514 (F2023 15.4.3.4.5) that the procedures should be distinguishable. 

```
$ flang -c flang_ice.f90

fatal internal error: CHECK(x.perArg.size() == y.perArg.size()) failed at flang/lib/Semantics/_expression_.cpp(2913)
PLEASE submit a bug report to https://github.com/Homebrew/homebrew-core/issues and include the crash backtrace and instructions to reproduce the bug.
Stack dump:
0.	Program arguments: /opt/homebrew/Cellar/flang/23.1.1/bin/flang-23 -fc1 -triple arm64-apple-macosx26.0.0 -emit-obj -fcolor-diagnostics -mrelocation-model pic -pic-level 2 -target-cpu apple-m1 -target-feature +v8.4a -target-feature +aes -target-feature +altnzcv -target-feature +ccdp -target-feature +ccpp -target-feature +complxnum -target-feature +crc -target-feature +dotprod -target-feature +flagm -target-feature +fp-armv8 -target-feature +fp16fml -target-feature +fptoint -target-feature +fullfp16 -target-feature +jsconv -target-feature +lse -target-feature +neon -target-feature +pauth -target-feature +perfmon -target-feature +predres -target-feature +ras -target-feature +rcpc -target-feature +rdm -target-feature +sb -target-feature +sha2 -target-feature +sha3 -target-feature +specrestrict -target-feature +ssbs -resource-dir /opt/homebrew/Cellar/flang/23.1.1/lib/clang/23 -fintrinsic-modules-path /opt/homebrew/Cellar/flang/23.1.1/lib/clang/23/finclude/flang/arm64-apple-darwin25.6.0 -mframe-pointer=non-leaf-no-reserve -o flang_ice.o -x f95 flang_ice.f90
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  libLLVM.23.1.dylib 0x000000012c3b8278 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  libLLVM.23.1.dylib       0x0000000130662abc SignalHandler(int, __siginfo*, void*) + 372
2  libsystem_platform.dylib 0x0000000183189744 _sigtramp + 56
3  libsystem_pthread.dylib  0x000000018317f8d8 pthread_kill + 296
4  libsystem_c.dylib        0x0000000183085978 abort + 148
5  flang-23 0x0000000103b4c380 mlir::OperationName::Impl::~Impl() + 0
6 flang-23                 0x0000000102de4fd4 Fortran::evaluate::ExpressionAnalyzer::ResolveGeneric(Fortran::semantics::Symbol const&, std::__1::vector<std::__1::optional<Fortran::evaluate::ActualArgument>, std::__1::allocator<std::__1::optional<Fortran::evaluate::ActualArgument>>> const&, std::__1::optional<std::__1::function<bool (Fortran::semantics::Symbol const&, std::__1::vector<std::__1::optional<Fortran::evaluate::ActualArgument>, std::__1::allocator<std::__1::optional<Fortran::evaluate::ActualArgument>>>&)>> const&, bool, std::__1::vector<Fortran::common::Reference<Fortran::semantics::Symbol const>, std::__1::allocator<Fortran::common::Reference<Fortran::semantics::Symbol const>>>&&, bool) + 4040
7  flang-23                 0x0000000102ddc1b8 Fortran::evaluate::ExpressionAnalyzer::AnalyzeProcedureComponentRef(Fortran::parser::ProcComponentRef const&, std::__1::vector<std::__1::optional<Fortran::evaluate::ActualArgument>, std::__1::allocator<std::__1::optional<Fortran::evaluate::ActualArgument>>>&&, bool) + 320
8  flang-23                 0x0000000102e1a674 Fortran::evaluate::ExpressionAnalyzer::Analyze(Fortran::parser::CallStmt const&) + 236
9  flang-23                 0x0000000102e25b84 void Fortran::semantics::ExprChecker::AnalyzeAndNoteUses<Fortran::parser::CallStmt>(Fortran::parser::CallStmt const&, bool) + 32
10 flang-23                 0x0000000102e220dc void Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::semantics::ExprChecker>(std::__1::list<Fortran::parser::ExecutionPartConstruct, std::__1::allocator<Fortran::parser::ExecutionPartConstruct>> const&, Fortran::semantics::ExprChecker&) + 68
11 flang-23 0x0000000102e2b0f0 void Fortran::parser::detail::ParseTreeVisitorLookupScope::ForEachInTuple<0ul, void Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::semantics::ExprChecker, Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>>(std::__1::tuple<Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>> const&, Fortran::semantics::ExprChecker&)::'lambda'(Fortran::semantics::ExprChecker const&), std::__1::tuple<Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>>>(std::__1::tuple<Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>> const&, void Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::semantics::ExprChecker, Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>>(std::__1::tuple<Fortran::parser::Statement<Fortran::parser::SubroutineStmt>, Fortran::parser::SpecificationPart, Fortran::parser::ExecutionPart, std::__1::optional<Fortran::parser::InternalSubprogramPart>, Fortran::parser::Statement<Fortran::parser::EndSubroutineStmt>> const&, Fortran::semantics::ExprChecker&)::'lambda'(Fortran::semantics::ExprChecker const&)) + 56
12 flang-23                 0x0000000102e2b344 void Fortran::parser::detail::ParseTreeVisitorLookupScope::Walk<Fortran::parser::ModuleSubprogram, Fortran::semantics::ExprChecker>(std::__1::list<Fortran::parser::ModuleSubprogram, std::__1::allocator<Fortran::parser::ModuleSubprogram>> const&, Fortran::semantics::ExprChecker&) + 240
13 flang-23 0x0000000102e2afd8 Fortran::semantics::ExprChecker::Walk(Fortran::parser::Program const&) + 360
14 flang-23                 0x0000000102f4713c Fortran::semantics::Semantics::Perform() + 536
15 flang-23 0x000000010271d950 Fortran::frontend::FrontendAction::runSemanticChecks() + 180
16 flang-23                 0x000000010271e898 Fortran::frontend::CodeGenAction::beginSourceFileAction() + 672
17 flang-23 0x000000010271c51c Fortran::frontend::FrontendAction::beginSourceFile(Fortran::frontend::CompilerInstance&, Fortran::frontend::FrontendInputFile const&) + 344
18 flang-23 0x000000010268a270 Fortran::frontend::CompilerInstance::executeAction(Fortran::frontend::FrontendAction&) + 580
19 flang-23                 0x000000010272c604 Fortran::frontend::executeCompilerInvocation(Fortran::frontend::CompilerInstance*) + 3524
20 flang-23                 0x00000001026880c4 fc1_main(llvm::ArrayRef<char const*>, char const*) + 676
21 flang-23 0x0000000102686a28 main + 696
22 dyld 0x0000000182db44e4 start + 6992
flang-23: error: unable to execute command: Abort trap: 6
flang-23: error: flang frontend command failed with exit code -2 (use -v to see invocation)
Homebrew flang version 23.1.1
Target: arm64-apple-darwin25.6.0
Thread model: posix
InstalledDir: /opt/homebrew/Cellar/flang/23.1.1/bin
Configuration file: /opt/homebrew/Cellar/flang/23.1.1/etc/clang/arm64-apple-darwin25.cfg
flang-23: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING CRASH REPRODUCER FILES TO THE BUG REPORT:
flang-23: note: diagnostic msg: /var/folders/5h/txm_8yhd2n721_w7gsrvlkj8p3bpj9/T/flang_ice-9f52ee
flang-23: note: diagnostic msg: /var/folders/5h/txm_8yhd2n721_w7gsrvlkj8p3bpj9/T/flang_ice-9f52ee.sh
flang-23: note: diagnostic msg: Crash backtrace is located in
flang-23: note: diagnostic msg: /Users/di75yas/Library/Logs/DiagnosticReports/flang-23_<YYYY-MM-DD-HHMMSS>_<hostname>.crash
flang-23: note: diagnostic msg: (choose the .crash file that corresponds to your crash)
flang-23: note: diagnostic msg:

```

With the line `call v%g(1)` removed or commented, flang correctly diagnoses the issue:

```
$ flang -c flang_ice.f90
error: Semantic errors in flang_ice.f90
flang_ice.f90:8:16: error: Generic 'g' may not have specific procedures 'a' and 'b' as their interfaces are not distinguishable
      generic :: g => a, b
 ^
flang_ice.f90:6:18: Declaration of 'a'
      procedure :: a => sa
 ^
flang_ice.f90:11:14: Procedure 'a' of type 't' is bound to 'sa'
    subroutine sa(x, n)
               ^^
flang_ice.f90:7:26: Declaration of 'b'
      procedure, nopass :: b => sb
 ^
flang_ice.f90:15:14: Procedure 'b' of type 't' is bound to 'sb'
 subroutine sb(n)
               ^^
```

The expected behavior would be to issue the diagnostic and not crash. 

Found using Claude Opus while testing some object-oriented Fortran patterns. 


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

Reply via email to