public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
@ 2020-12-22 13:57 ` briggs.michaels at gmail dot com
  2020-12-22 13:58 ` briggs.michaels at gmail dot com
                   ` (20 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: briggs.michaels at gmail dot com @ 2020-12-22 13:57 UTC (permalink / raw)
  To: gcc-bugs

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

Michael Briggs <briggs.michaels at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |briggs.michaels at gmail dot com

--- Comment #4 from Michael Briggs <briggs.michaels at gmail dot com> ---
Created attachment 49834
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49834&action=edit
fortran portion of test case

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
  2020-12-22 13:57 ` [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c) briggs.michaels at gmail dot com
@ 2020-12-22 13:58 ` briggs.michaels at gmail dot com
  2020-12-22 14:01 ` briggs.michaels at gmail dot com
                   ` (19 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: briggs.michaels at gmail dot com @ 2020-12-22 13:58 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Michael Briggs <briggs.michaels at gmail dot com> ---
Created attachment 49835
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49835&action=edit
C portion of test case

The second part of an additional test case.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
  2020-12-22 13:57 ` [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c) briggs.michaels at gmail dot com
  2020-12-22 13:58 ` briggs.michaels at gmail dot com
@ 2020-12-22 14:01 ` briggs.michaels at gmail dot com
  2020-12-22 14:03 ` briggs.michaels at gmail dot com
                   ` (18 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: briggs.michaels at gmail dot com @ 2020-12-22 14:01 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Michael Briggs <briggs.michaels at gmail dot com> ---
Comment on attachment 49834
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49834
fortran portion of test case

An additional test case, in two parts: Fortran & C.   The bug appears as:
malloc: *** error for object 0x7fff695a8eb8: pointer being freed was not
allocated

The problem is observed for gcc/gfortran 9.3.0 and 10.2.0

If the intent of "array" is changed from "out" to "inout" the program runs
without any problem.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2020-12-22 14:01 ` briggs.michaels at gmail dot com
@ 2020-12-22 14:03 ` briggs.michaels at gmail dot com
  2021-04-26 11:23 ` jrfsousa at gmail dot com
                   ` (17 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: briggs.michaels at gmail dot com @ 2020-12-22 14:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Michael Briggs <briggs.michaels at gmail dot com> ---
Comment on attachment 49834
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=49834
fortran portion of test case

First part of a two part test case, Fortran & C.

The bug appears as: malloc: *** error for object 0x7fff695a8eb8: pointer being
freed was not allocated

The problem is observed in gcc/gfortran 9.3.0 and 10.2.0

If the intent of "array" is changed from "out" to "inout" the program runs
without any problem.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2020-12-22 14:03 ` briggs.michaels at gmail dot com
@ 2021-04-26 11:23 ` jrfsousa at gmail dot com
  2021-04-26 16:54 ` dominiq at lps dot ens.fr
                   ` (16 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: jrfsousa at gmail dot com @ 2021-04-26 11:23 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
Patch (version 2) posted:

https://gcc.gnu.org/pipermail/fortran/2021-April/055991.html

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2021-04-26 11:23 ` jrfsousa at gmail dot com
@ 2021-04-26 16:54 ` dominiq at lps dot ens.fr
  2021-04-28 12:47 ` jrfsousa at gmail dot com
                   ` (15 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-04-26 16:54 UTC (permalink / raw)
  To: gcc-bugs

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

Dominique d'Humieres <dominiq at lps dot ens.fr> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2021-04-26
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #9 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> Patch (version 2) posted:
>
> https://gcc.gnu.org/pipermail/fortran/2021-April/055991.html

Please assign the PR to yourself when you submit a patch!

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2021-04-26 16:54 ` dominiq at lps dot ens.fr
@ 2021-04-28 12:47 ` jrfsousa at gmail dot com
  2021-04-28 13:53 ` dominiq at lps dot ens.fr
                   ` (14 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: jrfsousa at gmail dot com @ 2021-04-28 12:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
(In reply to Dominique d'Humieres from comment #9)
> > Patch (version 2) posted:
> >
> > https://gcc.gnu.org/pipermail/fortran/2021-April/055991.html
> 
> Please assign the PR to yourself when you submit a patch!

Sorry to bother you, but how do I assign the PR?

I don't think I have the necessary permissions, but I may be missing something
obvious...

Thank you very much.

Best regards,
José Rui

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2021-04-28 12:47 ` jrfsousa at gmail dot com
@ 2021-04-28 13:53 ` dominiq at lps dot ens.fr
  2021-04-28 18:33 ` jrfsousa at gmail dot com
                   ` (13 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: dominiq at lps dot ens.fr @ 2021-04-28 13:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #11 from Dominique d'Humieres <dominiq at lps dot ens.fr> ---
> I don't think I have the necessary permissions, but I may be missing something 
> obvious...

Did you try to click on 'take' in

Assignee:       
Not yet assigned to anyone (edit) (take)

?

If you have write access to git, I'ld be surprised that you have permissions
problem for Bugzilla.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2021-04-28 13:53 ` dominiq at lps dot ens.fr
@ 2021-04-28 18:33 ` jrfsousa at gmail dot com
  2021-04-28 18:49 ` anlauf at gcc dot gnu.org
                   ` (12 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: jrfsousa at gmail dot com @ 2021-04-28 18:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #12 from José Rui Faustino de Sousa <jrfsousa at gmail dot com> ---
(In reply to Dominique d'Humieres from comment #11)
> Did you try to click on 'take' in
> 
> Assignee:	
> Not yet assigned to anyone (edit) (take)
> 

I do not have the "edit" or "take" links and if I click "Not yet assigned to
anyone" it tries to send an email to "unassigned@gcc.gnu.org"...

Thank you very much.

Best regards,
José Rui

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2021-04-28 18:33 ` jrfsousa at gmail dot com
@ 2021-04-28 18:49 ` anlauf at gcc dot gnu.org
  2021-05-07 10:48 ` jrfsousa at gcc dot gnu.org
                   ` (11 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-04-28 18:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #13 from anlauf at gcc dot gnu.org ---
(In reply to José Rui Faustino de Sousa from comment #12)
> I do not have the "edit" or "take" links and if I click "Not yet assigned to
> anyone" it tries to send an email to "unassigned@gcc.gnu.org"...

Did you log in with your @gcc.gnu.org account?

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2021-04-28 18:49 ` anlauf at gcc dot gnu.org
@ 2021-05-07 10:48 ` jrfsousa at gcc dot gnu.org
  2021-05-07 18:23 ` anlauf at gcc dot gnu.org
                   ` (10 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: jrfsousa at gcc dot gnu.org @ 2021-05-07 10:48 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #14 from José Rui Faustino de Sousa <jrfsousa at gcc dot gnu.org> ---
On 28/04/21 18:49, anlauf at gcc dot gnu.org wrote:
> Did you log in with your @gcc.gnu.org account?
> 

Yes, changing the login email seems to have done the trick.

Thank you very much for your help!

Best regards,
José Rui

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2021-05-07 10:48 ` jrfsousa at gcc dot gnu.org
@ 2021-05-07 18:23 ` anlauf at gcc dot gnu.org
  2021-07-01 21:16 ` sandra at gcc dot gnu.org
                   ` (9 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: anlauf at gcc dot gnu.org @ 2021-05-07 18:23 UTC (permalink / raw)
  To: gcc-bugs

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

anlauf at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED

--- Comment #15 from anlauf at gcc dot gnu.org ---
It also helps if you change the status to ASSIGNED... ;-)

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2021-05-07 18:23 ` anlauf at gcc dot gnu.org
@ 2021-07-01 21:16 ` sandra at gcc dot gnu.org
  2021-07-01 22:21 ` kargl at gcc dot gnu.org
                   ` (8 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: sandra at gcc dot gnu.org @ 2021-07-01 21:16 UTC (permalink / raw)
  To: gcc-bugs

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

sandra at gcc dot gnu.org changed:

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

--- Comment #16 from sandra at gcc dot gnu.org ---
There seems to be no actual v2 patch at the link posted previously

https://gcc.gnu.org/pipermail/fortran/2021-April/055991.html

or the recent mail pinging that patch, and the original version at

https://gcc.gnu.org/pipermail/fortran/2020-February/054001.html

doesn't apply cleanly.  Can you repost the patch or attach it to this issue?

I think this PR may be the same issue that is affecting 

gfortran.dg/ts29113/interoperability/cf-out-descriptor-3.f90
gfortran.dg/ts29113/interoperability/cf-out-descriptor-4.f90
gfortran.dg/ts29113/interoperability/fc-out-descriptor-4.f90

from my new TS29113 testsuite

https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574115.html

and I'd like to try out the proposed fix.

My own diagnosis was "Fortran function with C binding fails to automatically
deallocate intent(out) allocated allocatable on entry when called from C". 
These testcases additionally trigger nasty errors from the memory allocator.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (12 preceding siblings ...)
  2021-07-01 21:16 ` sandra at gcc dot gnu.org
@ 2021-07-01 22:21 ` kargl at gcc dot gnu.org
  2021-07-02 14:53 ` sandra at gcc dot gnu.org
                   ` (7 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: kargl at gcc dot gnu.org @ 2021-07-01 22:21 UTC (permalink / raw)
  To: gcc-bugs

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

kargl at gcc dot gnu.org changed:

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

--- Comment #17 from kargl at gcc dot gnu.org ---
> 
> gfortran.dg/ts29113/interoperability/cf-out-descriptor-3.f90
> gfortran.dg/ts29113/interoperability/cf-out-descriptor-4.f90
> gfortran.dg/ts29113/interoperability/fc-out-descriptor-4.f90
> 
> from my new TS29113 testsuite

Hi Sandra,

I have general question.  Why are you using the ts29113
designation for your BIND(C) testing?  ISO/IEC TS 29113:2012
was incorporated into the Fortran 2018 standard.  There 
appears to be a few changes/additions in Fortran 2018
that are not present in TS 29113.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (13 preceding siblings ...)
  2021-07-01 22:21 ` kargl at gcc dot gnu.org
@ 2021-07-02 14:53 ` sandra at gcc dot gnu.org
  2021-08-11 14:11 ` burnus at gcc dot gnu.org
                   ` (6 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: sandra at gcc dot gnu.org @ 2021-07-02 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #18 from sandra at gcc dot gnu.org ---
The short answer re the TS 29113 thing is that it's what the customer who's
funding the work asked us to do.  :-)

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (14 preceding siblings ...)
  2021-07-02 14:53 ` sandra at gcc dot gnu.org
@ 2021-08-11 14:11 ` burnus at gcc dot gnu.org
  2021-10-18  8:29 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-08-11 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #19 from Tobias Burnus <burnus at gcc dot gnu.org> ---
Created attachment 51289
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51289&action=edit
Patch - Free memory in the callee

The attached patch frees the memory in the callee, however:

* integer, allocatable – those are passed as 'integer **dummy'
  I believe those should be passed as CFI descriptor
  -> runs into the assert.

* In the Fortran caller, the freeing is not needed if the the implementation is
in Fortran as the callee frees this. In principle, something like the following
should work (trans-expr; there is one case for scalar and one for arrays):
@@ -6541 +6548,3 @@ gfc_conv_procedure_call
-                 && fsym->attr.intent == INTENT_OUT)
+                 && fsym->attr.intent == INTENT_OUT
+                 && (!sym->attr.is_bind_c
+                     || sym->attr.if_source != IFSRC_DECL))

However, that does not work – and shows that the gfortran → CFI conversion is
completely broken:
    void * cfi.0;
    if (cfi.0 != 0B)
      {
        __builtin_free (cfi.0);
That's uninitialized memory :-(

* Also broken is that the data type for BIND(C) uses the Fortran array
descriptor and not the CFI one – it is currently only used as pointer and later
cast to void* but still that's pretty bad :-(

 * * *

I have still to look at José's patches.

 * * *

In any case, I think that the TYPE handling needs to be fixed first, followed
by moving _gfortran_gfc_desc_to_cfi_desc (and cfi→gfc) from libgfortran to the
front end to generate proper context-aware in-line code.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (15 preceding siblings ...)
  2021-08-11 14:11 ` burnus at gcc dot gnu.org
@ 2021-10-18  8:29 ` cvs-commit at gcc dot gnu.org
  2021-10-21 18:43 ` sandra at gcc dot gnu.org
                   ` (4 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-18  8:29 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #20 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:64f9623765da3306b0ab6a47997dc5d62c2ea261

commit r12-4467-g64f9623765da3306b0ab6a47997dc5d62c2ea261
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Mon Oct 18 09:51:36 2021 +0200

    Fortran: Fix Bind(C) Array-Descriptor Conversion

    gfortran uses internally a different array descriptor ("gfc") as
    Fortran 2018 alias TS291113 defines for C interoperability via
    ISO_Fortran_binding.h ("CFI").  Hence, when calling a C function
    from Fortran, it has to be converted in the callee - and if a
    BIND(C) procedure is written in Fortran, the CFI argument has
    to be converted to gfc in order work with the rest of the FE
    code and the library calls.

    Before this patch, part was handled in the FE generated code and
    other parts in libgfortran.  With this patch, all code is generated
    and CFI is defined as proper type - visible in the debugger and to
    the middle end - avoiding both alias issues and missed optimization
    issues.

    This patch also fixes issues like: intent(out) deallocation in
    the bind(C) callee, using the CFI descriptor also for allocatable
    and pointer scalars and for len=* character strings.
    For 'select rank', it also optimizes the code + avoid accessing
    uninitialized memory if the dummy argument is allocatable/a pointer.
    It additionally rejects passing a descriptorless type(*) to an
    assumed-rank dummy argument. [F2018:C711]

            PR fortran/102086
            PR fortran/92189
            PR fortran/92621
            PR fortran/101308
            PR fortran/101309
            PR fortran/101635
            PR fortran/92482

    gcc/fortran/ChangeLog:

            * decl.c (gfc_verify_c_interop_param): Remove 'sorry' for
            scalar allocatable/pointer and len=*.
            * expr.c (is_CFI_desc): Return true for for those.
            * gfortran.h (CFI_type_kind_shift, CFI_type_mask,
            CFI_type_from_type_kind, CFI_VERSION, CFI_MAX_RANK,
            CFI_attribute_pointer, CFI_attribute_allocatable,
            CFI_attribute_other, CFI_type_Integer, CFI_type_Logical,
            CFI_type_Real, CFI_type_Complex, CFI_type_Character,
            CFI_type_ucs4_char, CFI_type_struct, CFI_type_cptr,
            CFI_type_cfunptr, CFI_type_other): New #define.
            * trans-array.c (CFI_FIELD_BASE_ADDR, CFI_FIELD_ELEM_LEN,
            CFI_FIELD_VERSION, CFI_FIELD_RANK, CFI_FIELD_ATTRIBUTE,
            CFI_FIELD_TYPE, CFI_FIELD_DIM, CFI_DIM_FIELD_LOWER_BOUND,
            CFI_DIM_FIELD_EXTENT, CFI_DIM_FIELD_SM,
            gfc_get_cfi_descriptor_field, gfc_get_cfi_desc_base_addr,
            gfc_get_cfi_desc_elem_len, gfc_get_cfi_desc_version,
            gfc_get_cfi_desc_rank, gfc_get_cfi_desc_type,
            gfc_get_cfi_desc_attribute, gfc_get_cfi_dim_item,
            gfc_get_cfi_dim_lbound, gfc_get_cfi_dim_extent,
gfc_get_cfi_dim_sm):
            New define/functions to access the CFI array descriptor.
            (gfc_conv_descriptor_type): New function for the GFC descriptor.
            (gfc_get_array_span): Handle expr of CFI descriptors and
            assumed-type descriptors.
            (gfc_trans_array_bounds): Remove 'static'.
            (gfc_conv_expr_descriptor): For assumed type, use the dtype of
            the actual argument.
            (structure_alloc_comps): Remove ' ' inside tabs.
            * trans-array.h (gfc_trans_array_bounds, gfc_conv_descriptor_type,
            gfc_get_cfi_desc_base_addr, gfc_get_cfi_desc_elem_len,
            gfc_get_cfi_desc_version, gfc_get_cfi_desc_rank,
            gfc_get_cfi_desc_type, gfc_get_cfi_desc_attribute,
            gfc_get_cfi_dim_lbound, gfc_get_cfi_dim_extent,
gfc_get_cfi_dim_sm):
            New prototypes.
            * trans-decl.c (gfor_fndecl_cfi_to_gfc, gfor_fndecl_gfc_to_cfi):
            Remove global vars.
            (gfc_build_builtin_function_decls): Remove their initialization.
            (gfc_get_symbol_decl, create_function_arglist,
            gfc_trans_deferred_vars): Update for CFI.
            (convert_CFI_desc): Remove and replace by ...
            (gfc_conv_cfi_to_gfc): ... this function
            (gfc_generate_function_code): Call it; create local GFC var for
CFI.
            * trans-expr.c (gfc_maybe_dereference_var): Handle CFI.
            (gfc_conv_subref_array_arg): Handle the if-noncontigous-only copy
in
            when the result should be a descriptor.
            (gfc_conv_gfc_desc_to_cfi_desc): Completely rewritten.
            (gfc_conv_procedure_call): CFI fixes.
            * trans-openmp.c (gfc_omp_is_optional_argument,
            gfc_omp_check_optional_argument): Handle optional
            CFI.
            * trans-stmt.c (gfc_trans_select_rank_cases): Cleanup, avoid
invalid
            code for allocatable/pointer dummies, which cannot be assumed size.
            * trans-types.c (gfc_cfi_descriptor_base): New global var.
            (gfc_get_dtype_rank_type): Skip rank init for rank < 0.
            (gfc_sym_type): Handle CFI dummies.
            (gfc_get_function_type): Update call.
            (gfc_get_cfi_dim_type, gfc_get_cfi_type): New.
            * trans-types.h (gfc_sym_type): Update prototype.
            (gfc_get_cfi_type): New prototype.
            * trans.c (gfc_trans_runtime_check): Make conditions more
consistent
            to avoid '<logical> AND_THEN <long int>' in conditions.
            * trans.h (gfor_fndecl_cfi_to_gfc, gfor_fndecl_gfc_to_cfi): Remove
            global-var declaration.

    libgfortran/ChangeLog:

            * ISO_Fortran_binding.h (CFI_type_cfunptr): Make unique type again.
            * runtime/ISO_Fortran_binding.c (cfi_desc_to_gfc_desc,
            gfc_desc_to_cfi_desc): Add comment that those are no longer called
            by new code.

    libgomp/ChangeLog:

            * testsuite/libgomp.fortran/optional-bind-c.f90: New test.

    gcc/testsuite/ChangeLog:

            * gfortran.dg/ISO_Fortran_binding_4.f90: Extend testcase.
            * gfortran.dg/PR100914.f90: Remove xfail.
            * gfortran.dg/PR100915.c: Expect CFI_type_cfunptr.
            * gfortran.dg/PR100915.f90: Handle CFI_type_cfunptr !=
CFI_type_cptr.
            * gfortran.dg/PR93963.f90: Extend select-rank tests.
            * gfortran.dg/bind-c-intent-out.f90: Change to dg-do run,
            update scan-dump.
            * gfortran.dg/bind_c_array_params_2.f90: Update/extend scan-dump.
            * gfortran.dg/bind_c_char_10.f90: Update scan-dump.
            * gfortran.dg/bind_c_char_8.f90: Remove dg-error "sorry".
            * gfortran.dg/c-interop/allocatable-dummy.f90: Remove xfail.
            * gfortran.dg/c-interop/c1255-1.f90: Likewise.
            * gfortran.dg/c-interop/c407c-1.f90: Update dg-error.
            * gfortran.dg/c-interop/cf-descriptor-5.f90: Remove xfail.
            * gfortran.dg/c-interop/cf-out-descriptor-3.f90: Likewise.
            * gfortran.dg/c-interop/cf-out-descriptor-4.f90: Likewise.
            * gfortran.dg/c-interop/cf-out-descriptor-5.f90: Likewise.
            * gfortran.dg/c-interop/contiguous-2.f90: Likewise.
            * gfortran.dg/c-interop/contiguous-3.f90: Likewise.
            * gfortran.dg/c-interop/deferred-character-1.f90: Likewise.
            * gfortran.dg/c-interop/deferred-character-2.f90: Likewise.
            * gfortran.dg/c-interop/fc-descriptor-3.f90: Likewise.
            * gfortran.dg/c-interop/fc-descriptor-5.f90: Likewise.
            * gfortran.dg/c-interop/fc-descriptor-6.f90: Likewise.
            * gfortran.dg/c-interop/fc-out-descriptor-3.f90: Likewise.
            * gfortran.dg/c-interop/fc-out-descriptor-4.f90: Likewise.
            * gfortran.dg/c-interop/fc-out-descriptor-5.f90: Likewise.
            * gfortran.dg/c-interop/fc-out-descriptor-6.f90: Likewise.
            * gfortran.dg/c-interop/ff-descriptor-5.f90: Likewise.
            * gfortran.dg/c-interop/ff-descriptor-6.f90: Likewise.
            * gfortran.dg/c-interop/fc-descriptor-7.f90: Remove xfail + extend.
            * gfortran.dg/c-interop/fc-descriptor-7-c.c: Update for changes.
            * gfortran.dg/c-interop/shape.f90: Add implicit none.
            * gfortran.dg/c-interop/typecodes-array-char-c.c: Add kind=4 char.
            * gfortran.dg/c-interop/typecodes-array-char.f90: Likewise.
            * gfortran.dg/c-interop/typecodes-array-float128.f90: Remove xfail.
            * gfortran.dg/c-interop/typecodes-scalar-basic.f90: Likewise.
            * gfortran.dg/c-interop/typecodes-scalar-float128.f90: Likewise.
            * gfortran.dg/c-interop/typecodes-scalar-int128.f90: Likewise.
            * gfortran.dg/c-interop/typecodes-scalar-longdouble.f90: Likewise.
            * gfortran.dg/iso_c_binding_char_1.f90: Remove dg-error "sorry".
            * gfortran.dg/pr93792.f90: Turn XFAIL into PASS.
            * gfortran.dg/ISO_Fortran_binding_19.f90: New test.
            * gfortran.dg/assumed_type_12.f90: New test.
            * gfortran.dg/assumed_type_13.c: New test.
            * gfortran.dg/assumed_type_13.f90: New test.
            * gfortran.dg/bind-c-char-descr.f90: New test.
            * gfortran.dg/bind-c-contiguous-1.c: New test.
            * gfortran.dg/bind-c-contiguous-1.f90: New test.
            * gfortran.dg/bind-c-contiguous-2.f90: New test.
            * gfortran.dg/bind-c-contiguous-3.c: New test.
            * gfortran.dg/bind-c-contiguous-3.f90: New test.
            * gfortran.dg/bind-c-contiguous-4.c: New test.
            * gfortran.dg/bind-c-contiguous-4.f90: New test.
            * gfortran.dg/bind-c-contiguous-5.c: New test.
            * gfortran.dg/bind-c-contiguous-5.f90: New test.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (16 preceding siblings ...)
  2021-10-18  8:29 ` cvs-commit at gcc dot gnu.org
@ 2021-10-21 18:43 ` sandra at gcc dot gnu.org
  2021-10-22 11:33 ` burnus at gcc dot gnu.org
                   ` (3 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: sandra at gcc dot gnu.org @ 2021-10-21 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #21 from sandra at gcc dot gnu.org ---
Tobias, did your big patch fully fix this issue so that we can close it?

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (17 preceding siblings ...)
  2021-10-21 18:43 ` sandra at gcc dot gnu.org
@ 2021-10-22 11:33 ` burnus at gcc dot gnu.org
  2021-10-22 21:49 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  21 siblings, 0 replies; 22+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-10-22 11:33 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |NEW

--- Comment #22 from Tobias Burnus <burnus at gcc dot gnu.org> ---
(In reply to sandra from comment #21)
> Tobias, did your big patch fully fix this issue so that we can close it?

I checked the examples – and did run into the following ICE. I think we should
at some point compile all gfortran testcases with -fcheck= and/or
-fsanitize=undefined(,address) and with and without optimization to see whether
it triggers some ICE.

Additionally, I think we might want to do something likewise for the dg-do run
tests.

 * * *

The testcase attachment 47882 of comment 3 still/now fails with:

    9 |   val = 2
      |         1
internal compiler error: in gfc_trans_assignment_1, at
fortran/trans-expr.c:11732

It works when using 'val(:) = 2' - and only fails when compiled with both:
  -fcheck=all -fsanitize=undefined


The fail is for:
11731             /* We should only get array references here.  */
11732             gcc_assert (TREE_CODE (tmp) == POINTER_PLUS_EXPR
11733                         || TREE_CODE (tmp) == ARRAY_REF);

(gdb) p debug(tmp)
(integer(kind=4) *) ((void *) D.4249 + (sizetype) ((S.5 + D.4250) * val->span))

(gdb) p debug_tree(tmp)
 <nop_expr 0x7ffff71a3580
    type <pointer_type 0x7ffff6fc9a80
...
    arg:0 <pointer_plus_expr 0x7ffff6d850a0


Thus, it seems as if we need to strip the nop_expr?

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (18 preceding siblings ...)
  2021-10-22 11:33 ` burnus at gcc dot gnu.org
@ 2021-10-22 21:49 ` cvs-commit at gcc dot gnu.org
  2021-10-22 22:08 ` burnus at gcc dot gnu.org
  2022-01-09 23:26 ` pinskia at gcc dot gnu.org
  21 siblings, 0 replies; 22+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-22 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #23 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Tobias Burnus <burnus@gcc.gnu.org>:

https://gcc.gnu.org/g:24e99e6ec1cc57f3660c00ff677c7feb16aa94d2

commit r12-4632-g24e99e6ec1cc57f3660c00ff677c7feb16aa94d2
Author: Tobias Burnus <tobias@codesourcery.com>
Date:   Fri Oct 22 23:23:06 2021 +0200

    Fortran: Avoid running into assert with -fcheck= + UBSAN

            PR fortran/92621
    gcc/fortran/
            * trans-expr.c (gfc_trans_assignment_1): Add STRIP_NOPS.

    gcc/testsuite/
            * gfortran.dg/bind-c-intent-out-2.f90: New test.

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (19 preceding siblings ...)
  2021-10-22 21:49 ` cvs-commit at gcc dot gnu.org
@ 2021-10-22 22:08 ` burnus at gcc dot gnu.org
  2022-01-09 23:26 ` pinskia at gcc dot gnu.org
  21 siblings, 0 replies; 22+ messages in thread
From: burnus at gcc dot gnu.org @ 2021-10-22 22:08 UTC (permalink / raw)
  To: gcc-bugs

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

Tobias Burnus <burnus at gcc dot gnu.org> changed:

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

--- Comment #24 from Tobias Burnus <burnus at gcc dot gnu.org> ---
FIXED (GCC 12) - including the follow-up issue.

Thanks for the testcases, patches, debugging and patience!

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

* [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c)
       [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
                   ` (20 preceding siblings ...)
  2021-10-22 22:08 ` burnus at gcc dot gnu.org
@ 2022-01-09 23:26 ` pinskia at gcc dot gnu.org
  21 siblings, 0 replies; 22+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-01-09 23:26 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

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

end of thread, other threads:[~2022-01-09 23:26 UTC | newest]

Thread overview: 22+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-92621-4@http.gcc.gnu.org/bugzilla/>
2020-12-22 13:57 ` [Bug fortran/92621] Problems with memory handling with allocatable intent(out) arrays with bind(c) briggs.michaels at gmail dot com
2020-12-22 13:58 ` briggs.michaels at gmail dot com
2020-12-22 14:01 ` briggs.michaels at gmail dot com
2020-12-22 14:03 ` briggs.michaels at gmail dot com
2021-04-26 11:23 ` jrfsousa at gmail dot com
2021-04-26 16:54 ` dominiq at lps dot ens.fr
2021-04-28 12:47 ` jrfsousa at gmail dot com
2021-04-28 13:53 ` dominiq at lps dot ens.fr
2021-04-28 18:33 ` jrfsousa at gmail dot com
2021-04-28 18:49 ` anlauf at gcc dot gnu.org
2021-05-07 10:48 ` jrfsousa at gcc dot gnu.org
2021-05-07 18:23 ` anlauf at gcc dot gnu.org
2021-07-01 21:16 ` sandra at gcc dot gnu.org
2021-07-01 22:21 ` kargl at gcc dot gnu.org
2021-07-02 14:53 ` sandra at gcc dot gnu.org
2021-08-11 14:11 ` burnus at gcc dot gnu.org
2021-10-18  8:29 ` cvs-commit at gcc dot gnu.org
2021-10-21 18:43 ` sandra at gcc dot gnu.org
2021-10-22 11:33 ` burnus at gcc dot gnu.org
2021-10-22 21:49 ` cvs-commit at gcc dot gnu.org
2021-10-22 22:08 ` burnus at gcc dot gnu.org
2022-01-09 23:26 ` pinskia 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).