From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CDA043858D32; Tue, 28 Feb 2023 00:22:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CDA043858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677543746; bh=eXdk8CSaW+PKPtsHezcJ2fGKcfW74fxu2d7sqQHB8HQ=; h=From:To:Subject:Date:From; b=JHi0AHAYFKddrrermSNAHg+4rLhJWDfjgN2WcERRelaEu9ebnM/fcx00SDn/18Fzu HrHtUyl3NymW8w+TsB0K3mo+0WmojYXM8dPdBrVFckPUexu1sf9U+9Xocs6Zx7HACT 1azC8SxcHsDpee/C9AjvES8l1OoglS7Q5nbTlfAs= From: "jeffrey.p.hill at nasa dot gov" To: gcc-bugs@gcc.gnu.org Subject: [Bug fortran/108961] New: Segfault when associating to pointer from C_F_POINTER Date: Tue, 28 Feb 2023 00:22:25 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: jeffrey.p.hill at nasa dot gov X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108961 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=3D54551&action=3Dedit Full example of failing test In support of exposing a Fortran library via a C API, I am trying to implem= ent 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=20 =20 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 =3D> 11). Tests were done under Ubun= tu 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 =3D> p Attachment #2 in a minimal example that just focuses on the C_F_POINTER/poi= nter 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 int= o a character string, but I was hoping to get this approach working, which is zero-copy/zero-allocation. Thanks!=