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

kargls at comcast dot net changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #59830|0                           |1
        is obsolete|                            |

--- Comment #5 from kargls at comcast dot net ---
Created attachment 59873
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=59873&action=edit
New diff

The attached diff is the WIP, and unfortunately, where I will stop.  I cannot
resolve the issue of an uninitialized variables.  Consider, this simple
program:

   program foo

   use iso_c_binding, only : c_null_char, c_char, f_c_string

   implicit none

   logical, volatile :: asis
   integer i
   character(len=6, kind=c_char), volatile :: s1
   character(len=:, kind=c_char), allocatable :: ss2

   ss2 = f_c_string(s1, .true.)
   i = len_trim(s1) + 1
   if (len(ss2) /= i) stop 3

   end program foo

with the attached patch I get

gfcx -o z -fdump-tree-original -fno-realloc-lhs f_c_string.f90

(note -fno-realloc-lhs simply isolates the problems)

    character(kind=1) str.0[7];     // <-- This 7 is tlen.1
    integer(kind=8) tlen.1;         // <-- obviously, tlen.1
    character(kind=1) * tstr.2;
    character(kind=1) * pstr.3;
    void * restrict D.4787;
    integer(kind=8) D.4788;
    integer(kind=8) D.4789;
    void * D.4790;
    void * D.4791;

    D.4788 = tlen.1 + 1;          // <-- Whoops, tlen.1 is unset!


gfcx -o z -fdump-tree-original f_c_string.f90
(this shows the real issue and the allocation of 64T of memory!)

    character(kind=1) str.0[7];     // <-- This 7 is tlen.1
    integer(kind=8) tlen.1;         // <-- obviously, tlen.1
    character(kind=1) * tstr.2;
    character(kind=1) * pstr.3;
    void * restrict D.4787;
    integer(kind=8) D.4788;
    integer(kind=8) D.4789;
    void * D.4790;
    void * D.4791;
    //
    // The following is reallocation on assignment.  Notice tlen.1 is unset!
    //
    if (ss2 != 0B) goto L.1;
    ss2 = (character(kind=1)[1:.ss2] *)
       __builtin_malloc (MAX_EXPR <(sizetype) (tlen.1 + 1), 1>);
    goto L.2;
    L.1:;
    if (tlen.1 + 1 == .ss2) goto L.2;
    ss2 = (character(kind=1)[1:.ss2] *)
       __builtin_realloc ((void *) ss2, MAX_EXPR <(sizetype) (tlen.1 + 1), 1>);
    L.2:;
    .ss2 = tlen.1 + 1;


If someone smarter than I wants to pick up the pieces, I would much appreciate
it.

Reply via email to