Fortran: Fixes ICE for ASSOCIATE selectors with type-bound user-defined operators.
This commit resolves three bugs that could cause an Internal Compiler Error (ICE) or incorrect code generation when `ASSOCIATE` selectors in Fortran involved t…
This commit addresses three interconnected bugs in the Fortran compiler that led to either an Internal Compiler Error (ICE) or incorrect code when ASSOCIATE selectors were type-bound user-defined operator expressions. These issues stemmed from incorrect handling of inherited type-bound procedures, premature returns in type resolution, and an inability to correctly type-check complex operator expressions within ASSOCIATE. The fixes involve improvements in symbol lookup for inherited procedures, corrected type resolution logic, and new helper functions for robust type inferencing of operator expressions. This significantly enhances the compiler’s ability to handle advanced Fortran features.
In Details
In Fortran, ASSOCIATE constructs allow aliasing of expressions, and type-bound user-defined operators (UDOs) provide object-oriented extensibility. Three bugs were identified across class.cc, resolve.cc, and match.cc. Bug 1 in find_typebound_proc_uop in class.cc failed to correctly traverse inherited types for UDOs when a derived type lacked a f2k_derived namespace. Bug 2 in resolve_typebound_procedures in resolve.cc suffered from an early return, preventing resolution of parent-type bindings. Bug 3 in match_association_list in match.cc struggled with untyped ASSOCIATE…
For Context
Compilers sometimes struggle with very complex or advanced ways of writing code, leading to crashes or incorrect programs. This commit fixes three related problems in the Fortran compiler that occurred when a program used a feature called ASSOCIATE (which lets you temporarily rename expressions or variables) in combination with 'type-bound user-defined operators' (a way to define custom operations that belong to a specific data type). The bugs were mainly about the compiler incorrectly searching for these custom operations, missing inherited ones, or failing to figure out the correct 'type' (e.g., integer, string) of complex expressions when they were used with ASSOCIATE. The fixes involve improving how the compiler looks up these custom operations and how it determines the types of complex expressions, making the Fortran compiler more robust when handling these sophisticated language features.