Fix ICE for ASSOCIATE selector returning a procedure pointer
Fortran compiler fixes an ICE by correctly handling ASSOCIATE selectors that are procedure pointers.
Fortran’s ASSOCIATE construct has a restriction (F2023:C1105) that its selector cannot be a designator of a procedure pointer or a function returning one. Previously, the compiler incorrectly allowed function references returning procedure pointers to proceed, leading to an Internal Compiler Error (ICE) when verification checks were enabled. This patch hoists the check to correctly diagnose these cases, preventing the ICE and adhering to the Fortran standard.
In Details
Fortran standard F2023:C1105 disallows procedure pointers or functions returning procedure pointers from being used as ASSOCIATE construct selectors. The existing check in resolve_assoc_var was gated by EXPR_VARIABLE, causing function references to bypass it. The GIMPLE generated for such cases incorrectly assigned the function's result type and value, leading to an ICE when verify_gimple or release checks were enabled. This commit moves the procedure pointer check outside the EXPR_VARIABLE branch and adds an EXPR_FUNCTION arm to correctly diagnose function references returning proc…
- ASSOCIATE construct
- A Fortran construct that allows a variable or expression to be associated with a new name within a limited scope, simplifying code that repeatedly references the same entity.
- procedure pointer
- In Fortran, a pointer that can point to a procedure (subroutine or function), allowing for dynamic dispatch or callbacks.
- ICE
- Internal Compiler Error. A severe error detected by the compiler itself, indicating a bug within the compiler's logic, which halts compilation.
- GIMPLE
- GCC's Internal Representation (GIR) after the tree-ssa pass. It's a three-address-like code form used for optimization.
- F2023
- The Fortran 2023 standard, a revision of the Fortran programming language standard.