Fixes ICE with BIND(C) and PRIVATE in Fortran.
Fixes an internal compiler error in Fortran when using BIND(C) and PRIVATE attributes together, by improving symbol lookup for private entities.
A recent change caused an internal compiler error in Fortran when using BIND(C) and PRIVATE attributes together. The compiler was unable to find symbols for private entities within a gsymbol’s namespace. This commit resolves the issue by iterating over all symbols to find the correct name when a direct lookup fails if the entity is private. This restores expected behavior.
In Details
BIND(C) in Fortran allows interoperability with C code by specifying a common calling convention and symbol naming scheme. PRIVATE restricts the visibility of entities within a module. The issue arose in gfc_verify_binding_labels during symbol resolution. The fix involves calling gfc_find_symbol_by_name and iterating through all symbols when the direct lookup fails for private entities. The interaction between symbol visibility and C binding triggered the regression.
For Context
Fortran's BIND(C) attribute enables interoperability with C, allowing Fortran code to be called from C and vice versa. The PRIVATE attribute controls the visibility of variables and procedures within a Fortran module, limiting their accessibility from outside the module. This commit addresses a bug where the compiler would crash when trying to link Fortran code using BIND(C) with PRIVATE variables. The fix makes sure to search for the private symbols, even if they are declared with the PRIVATE attribute.