[Patch, fortran] PR83344 - Use of uninitialized memory with ASSOCIATE and strings
Paul Richard Thomas
paul.richard.thomas@gmail.com
Sun Feb 18 21:01:00 GMT 2018
Hi Janne and Thomas,
1) The patch is attached now - sorry!
2) The commented out part of associate_22.f90 is not yet fixed. I am
working on it.
3) I will take a look at PR83975 tomorrow night.
Paul
On 18 February 2018 at 16:08, Janne Blomqvist <blomqvist.janne@gmail.com> wrote:
> On Sun, Feb 18, 2018 at 5:48 PM, Paul Richard Thomas
> <paul.richard.thomas@gmail.com> wrote:
>> Bootstraps and regtests on FC27/x86_64 - OK for trunk?
>
> Hi,
>
> thanks for looking into this!
>
> 1. The patch itself is missing...
>
> 2. Could you uncomment the commented out part of associate_22.f90 and
> check that the tree-original dump is sensible.
>
> 3. Same for the testcases posted to PR 83975. I suspect (err, hope)
> that this patch would fix those as well. If so, please add that PR to
> the ChangeLog entries as well.
>
>>
>> Paul
>>
>> 2018-02-18 Paul Thomas <pault@gcc.gnu.org>
>>
>> PR fortran/83344
>> * resolve.c (resolve_assoc_var): Character associate names that
>> have no length expression that have variable targets and are
>> not deferred length have assumed length.
>> * trans-decl.c (gfc_get_symbol_decl): Set 'length' to
>> gfc_index_zero_node for character associate names, whose string
>> length is a PARM_DECL.
>>
>> 2018-02-18 Paul Thomas <pault@gcc.gnu.org>
>>
>> PR fortran/83344
>> * gfortran.dg/associate_36.f90: New test.
>
>
>
> --
> Janne Blomqvist
--
"If you can't explain it simply, you don't understand it well enough"
- Albert Einstein
-------------- next part --------------
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c (revision 257787)
--- gcc/fortran/resolve.c (working copy)
*************** resolve_assoc_var (gfc_symbol* sym, bool
*** 8656,8662 ****
sym->ts.u.cl->length =
gfc_get_int_expr (gfc_charlen_int_kind, NULL,
target->value.character.length);
! else
gfc_error ("Not Implemented: Associate target with type character"
" and non-constant length at %L", &target->where);
}
--- 8656,8663 ----
sym->ts.u.cl->length =
gfc_get_int_expr (gfc_charlen_int_kind, NULL,
target->value.character.length);
! /* If the target is a variable, it is an assumed length dummy. */
! else if (target->expr_type != EXPR_VARIABLE)
gfc_error ("Not Implemented: Associate target with type character"
" and non-constant length at %L", &target->where);
}
Index: gcc/fortran/trans-decl.c
===================================================================
*** gcc/fortran/trans-decl.c (revision 257787)
--- gcc/fortran/trans-decl.c (working copy)
*************** gfc_get_symbol_decl (gfc_symbol * sym)
*** 1712,1718 ****
if (sym->attr.associate_var
&& sym->ts.u.cl->backend_decl
! && VAR_P (sym->ts.u.cl->backend_decl))
length = gfc_index_zero_node;
else
length = gfc_create_string_length (sym);
--- 1712,1719 ----
if (sym->attr.associate_var
&& sym->ts.u.cl->backend_decl
! && (VAR_P (sym->ts.u.cl->backend_decl)
! || TREE_CODE (sym->ts.u.cl->backend_decl) == PARM_DECL))
length = gfc_index_zero_node;
else
length = gfc_create_string_length (sym);
Index: gcc/testsuite/gfortran.dg/associate_36.f90
===================================================================
*** gcc/testsuite/gfortran.dg/associate_36.f90 (nonexistent)
--- gcc/testsuite/gfortran.dg/associate_36.f90 (working copy)
***************
*** 0 ****
--- 1,28 ----
+ ! { dg-do run }
+ !
+ ! Test the fix for PR83344.
+ !
+ ! Contributed by <Janne Blomqvist <jb@gcc.gnu.org>
+ !
+ program foo
+ implicit none
+ character(len=1) a
+ character(len=2) b
+ character(len=3) c
+ a = 'a'
+ call bah(a, len (a))
+ b = 'bb'
+ call bah(b, len (b))
+ c = 'ccc'
+ call bah(c, len (c))
+ contains
+ subroutine bah(x, clen)
+ implicit none
+ integer :: clen
+ character(len=*), intent(in) :: x
+ associate(y => x)
+ if (len(y) .ne. clen) stop 1
+ if (y .ne. x) stop 2
+ end associate
+ end subroutine bah
+ end program foo
More information about the Gcc-patches
mailing list