https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961
Bug ID: 108961 Summary: Segfault when associating to pointer from C_F_POINTER Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: fortran Assignee: unassigned at gcc dot gnu.org Reporter: jeffrey.p.hill at nasa dot gov Target Milestone: --- Created attachment 54551 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54551&action=edit Full example of failing test In support of exposing a Fortran library via a C API, I am trying to implement C_F_STRPOINTER from the upcoming F202X standard in F2008: https://j3-fortran.org/doc/year/19/19-197r3.txt A sample implementation was provided in an earlier paper, as well as on the Intel forums: https://j3-fortran.org/doc/year/18/18-258r2.txt https://community.intel.com/t5/Intel-Fortran-Compiler/New-Interoperability-Fortran-to-C-String-case/m-p/1144681/highlight/true#M138173 Example usage is provided in this paper: https://j3-fortran.org/doc/year/21/21-107.txt Attachment #1 is a full example that implements and exercises c_f_strpointer per the above references. This works in ifort and nvfortran, but segfaults in all versions of gfortran I tested (4.8 => 11). Tests were done under Ubuntu and RH7. The problematic line is Line 37, when trying to associate the deferred-length output pointer with the defined-length pointer returned by c_f_pointer: call C_F_POINTER(CSTRPTR, p) FSTRPTR => p Attachment #2 in a minimal example that just focuses on the C_F_POINTER/pointer associate operations. I find the error only happens when the pointer to-be-associated is in a separate module with deferred length. Fall back is to simply copy the contents of the character array pointer into a character string, but I was hoping to get this approach working, which is zero-copy/zero-allocation. Thanks!