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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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 ` jeffrey.p.hill at nasa dot gov
  2023-03-23 18:39 ` pault at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: jeffrey.p.hill at nasa dot gov @ 2023-02-28  0:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

--- Comment #1 from Jeffrey Hill <jeffrey.p.hill at nasa dot gov> ---
Created attachment 54552
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=54552&action=edit
Minimal Example of failing operation

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu.org @ 2023-03-23 18:39 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
                 CC|                            |pault at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |87477
   Last reconfirmed|                            |2023-03-23

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---
Good catch. Thanks for the report.

Paul


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87477
[Bug 87477] [meta-bug] [F03] issues concerning the ASSOCIATE statement

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu.org @ 2023-04-18  9:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Blocks|87477                       |
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org

--- Comment #3 from Paul Thomas <pault at gcc dot gnu.org> ---
Since this has nothing to do with the associate construct, I have removed the
blocking of PR87477.

That said, I am onto it :-) I cannot see anything untoward with the produced
code at the moment and, since there is the dependence on whether or not the
subroutine is in a module, I can only surmise that there is some subtle
difference in memory usage.

Paul


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=87477
[Bug 87477] [meta-bug] [F03] issues concerning the ASSOCIATE statement

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (2 preceding siblings ...)
  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
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu.org @ 2023-06-20 12:55 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

--- Comment #4 from Paul Thomas <pault at gcc dot gnu.org> ---
Created attachment 55368
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55368&action=edit
Fix for this PR

I couldn't see what the problem was initially and so I put this PR to one side.

I still have it in my PR87477 (associate meta-bug) folder and so it gets tested
fairly often at the moment. It now stands out as one of three failures out of
37 tests. Since I am putting off the other two since they require a "bitty"
fix, I came back to it and blow me if I didn't see the problem in a few
minutes. The fix took a few more minutes.

If you build gfortran from source, let me know how you get on. I'll submit the
patch a bit later today.

Cheers

Paul

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (3 preceding siblings ...)
  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
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-06-21 16:02 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

--- Comment #5 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:caf0892eea67349d9a1e44590c3440768136fe2b

commit r14-2021-gcaf0892eea67349d9a1e44590c3440768136fe2b
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Wed Jun 21 17:01:57 2023 +0100

    Fortran: Seg fault passing string to type cptr dummy [PR108961].

    2023-06-21  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/108961
            * trans-expr.cc (gfc_conv_procedure_call): The hidden string
            length must not be passed to a formal arg of type(cptr).

    gcc/testsuite/
            PR fortran/108961
            * gfortran.dg/pr108961.f90: New test.

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (4 preceding siblings ...)
  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
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: pault at gcc dot gnu.org @ 2023-06-21 21:07 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Paul Thomas <pault at gcc dot gnu.org> ---
Fixed on trunk and closing.

I will backport to 13-branch in a few weeks.

Thanks for the report

Paul

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (5 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: anlauf at gcc dot gnu.org @ 2023-07-29 20:18 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |anlauf at gcc dot gnu.org

--- Comment #7 from anlauf at gcc dot gnu.org ---
(In reply to Paul Thomas from comment #6)
> I will backport to 13-branch in a few weeks.

Could you please ping me after the backport?

I would like to backport the fix for pr110825 and avoid a merge conflict,
as the changes are adjacent.

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (6 preceding siblings ...)
  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
  8 siblings, 0 replies; 10+ messages in thread
From: paul.richard.thomas at gmail dot com @ 2023-07-30  9:46 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

--- Comment #8 from paul.richard.thomas at gmail dot com <paul.richard.thomas at gmail dot com> ---
Hi Harald,

I have just returned from a trip to the General Atomics DIIID facility
in San Diego and feel like death warmed up :-(

I'll try to get to the backport this afternoon once I have unpacked
and had a nap.

Regards

Paul

On Sat, 29 Jul 2023 at 21:18, anlauf at gcc dot gnu.org
<gcc-bugzilla@gcc.gnu.org> wrote:
>
> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961
>
> anlauf at gcc dot gnu.org changed:
>
>            What    |Removed                     |Added
> ----------------------------------------------------------------------------
>                  CC|                            |anlauf at gcc dot gnu.org
>
> --- Comment #7 from anlauf at gcc dot gnu.org ---
> (In reply to Paul Thomas from comment #6)
> > I will backport to 13-branch in a few weeks.
>
> Could you please ping me after the backport?
>
> I would like to backport the fix for pr110825 and avoid a merge conflict,
> as the changes are adjacent.
>
> --
> You are receiving this mail because:
> You are the assignee for the bug.
> You are on the CC list for the bug.

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

* [Bug fortran/108961] Segfault when associating to pointer from C_F_POINTER
  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
                   ` (7 preceding siblings ...)
  2023-07-30  9:46 ` paul.richard.thomas at gmail dot com
@ 2023-07-30 12:25 ` cvs-commit at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-07-30 12:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108961

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-13 branch has been updated by Paul Thomas <pault@gcc.gnu.org>:

https://gcc.gnu.org/g:1a322145aa60a65bed064fbb5514a193a27bd86f

commit r13-7654-g1a322145aa60a65bed064fbb5514a193a27bd86f
Author: Paul Thomas <pault@gcc.gnu.org>
Date:   Sun Jul 30 13:25:19 2023 +0100

    Fortran: Seg fault passing string to type cptr dummy [PR108961].

    2023-07-30  Paul Thomas  <pault@gcc.gnu.org>

    gcc/fortran
            PR fortran/108961
            * trans-expr.cc (gfc_conv_procedure_call): The hidden string
            length must not be passed to a formal arg of type(cptr).

    gcc/testsuite/
            PR fortran/108961
            * gfortran.dg/pr108961.f90: New test.

^ 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).