public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/108961] New: Segfault when associating to pointer from C_F_POINTER
@ 2023-02-28  0:22 jeffrey.p.hill at nasa dot gov
  2023-02-28  0:23 ` [Bug fortran/108961] " jeffrey.p.hill at nasa dot gov
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: jeffrey.p.hill at nasa dot gov @ 2023-02-28  0:22 UTC (permalink / raw)
  To: gcc-bugs

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!

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2023-07-30 12:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-28  0:22 [Bug fortran/108961] New: Segfault when associating to pointer from C_F_POINTER jeffrey.p.hill at nasa dot gov
2023-02-28  0:23 ` [Bug fortran/108961] " jeffrey.p.hill at nasa dot gov
2023-03-23 18:39 ` pault at gcc dot gnu.org
2023-04-18  9:17 ` pault at gcc dot gnu.org
2023-06-20 12:55 ` pault at gcc dot gnu.org
2023-06-21 16:02 ` cvs-commit at gcc dot gnu.org
2023-06-21 21:07 ` pault at gcc dot gnu.org
2023-07-29 20:18 ` anlauf at gcc dot gnu.org
2023-07-30  9:46 ` paul.richard.thomas at gmail dot com
2023-07-30 12:25 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).