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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2024-11-03
                 CC|                            |pault at gcc dot gnu.org

--- Comment #2 from Paul Thomas <pault at gcc dot gnu.org> ---

> One hacky "fix" is to give the temporary a leading underscore, thus avoiding
> finalization altogether:
> --- a/gcc/fortran/class.cc
> +++ b/gcc/fortran/class.cc
> @@ -1152,7 +1152,7 @@ finalize_component (gfc_expr *expr, gfc_symbol
> *derived, gfc_component *comp,
>        gcc_assert (c);
>  
>        /* Set scalar argument for storage_size.  */
> -      gfc_get_symbol ("comp_byte_stride", sub_ns, &byte_stride);
> +      gfc_get_symbol ("_comp_byte_stride", sub_ns, &byte_stride);
>        byte_stride->ts = e->ts;
>        byte_stride->attr.flavor = FL_VARIABLE;
>        byte_stride->attr.value = 1;
> 
> This regtests cleanly on current trunk and seems to fix the issue. However,
> since I'm only taking first baby steps in gfortran development, I have no
> clue what the significance of the leading underscore is and what sort of
> other side effects this change could have.
> 

I consider this to be a perfectly acceptable fix, since (1) it works and (2)
comp_byte_stride has no business being finalized! With this fix in place,
gfortran gives the same result as ifort.

Do you want to apply the fix or shall I do the honours?

Your testcase exposes another gfortran bug, by the way! The lines 'write(*,*)
"B:", self%cptr' are invalid because, as ifort puts it, "A derived-type object
in an input/output list cannot have inaccessible components unless a suitable
user-defined input/output procedure is available." The correct workaround is:
if (.not. self%cptr_invalid) write(*,*) "A:", transfer (self%cptr,
C_LONG_LONG). This is now pr117430.

Paul

Reply via email to