Re: [PATCH, fortran] PR89782 READ/WRITE of a character array when it is a parameter
On Sat, Jun 22, 2019 at 11:49:25AM -0700, Jerry DeLisle wrote: > On 6/22/19 11:32 AM, Steve Kargl wrote: > > On Sat, Jun 22, 2019 at 11:23:48AM -0700, Jerry DeLisle wrote: > >> > >> 2019-06-22 Jerry DeLisle > >> > >>PR fortran/89782 > >>* io.c (gfc_resolve_dt): Check that internal units are not > >>character PARAMETER. > > > > This part of the patch is missing. > > > >> > >>* gfortran.dg/io_constraints.f90: New test. > >> > > > > this part looks fine, but depends on the missing part. > > > > Sorry about that, I missed the HEAD in "git diff HEAD". > > Jerry > > diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c > index 425c2b86899..cd21c6bcf82 100644 > --- a/gcc/fortran/io.c > +++ b/gcc/fortran/io.c > @@ -3328,6 +3328,14 @@ gfc_resolve_dt (gfc_dt *dt, locus *loc) > return false; > } > > + if (e->symtree && e->symtree->n.sym->attr.flavor == FL_PARAMETER > + && e->ts.type == BT_CHARACTER) > +{ > + gfc_error ("UNIT specification at %L must " > + "not be a character PARAMETER", >where); > + return false; > +} > + > if (gfc_resolve_expr (e) > && (e->ts.type != BT_INTEGER > && (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE))) Looks good. Thanks for the patch. -- Steve
Re: [PATCH, fortran] PR89782 READ/WRITE of a character array when it is a parameter
On 6/22/19 11:32 AM, Steve Kargl wrote: On Sat, Jun 22, 2019 at 11:23:48AM -0700, Jerry DeLisle wrote: 2019-06-22 Jerry DeLisle PR fortran/89782 * io.c (gfc_resolve_dt): Check that internal units are not character PARAMETER. This part of the patch is missing. * gfortran.dg/io_constraints.f90: New test. this part looks fine, but depends on the missing part. Sorry about that, I missed the HEAD in "git diff HEAD". Jerry diff --git a/gcc/fortran/io.c b/gcc/fortran/io.c index 425c2b86899..cd21c6bcf82 100644 --- a/gcc/fortran/io.c +++ b/gcc/fortran/io.c @@ -3328,6 +3328,14 @@ gfc_resolve_dt (gfc_dt *dt, locus *loc) return false; } + if (e->symtree && e->symtree->n.sym->attr.flavor == FL_PARAMETER + && e->ts.type == BT_CHARACTER) +{ + gfc_error ("UNIT specification at %L must " + "not be a character PARAMETER", >where); + return false; +} + if (gfc_resolve_expr (e) && (e->ts.type != BT_INTEGER && (e->ts.type != BT_CHARACTER || e->expr_type != EXPR_VARIABLE)))
Re: [PATCH, fortran] PR89782 READ/WRITE of a character array when it is a parameter
On Sat, Jun 22, 2019 at 11:23:48AM -0700, Jerry DeLisle wrote: > > 2019-06-22 Jerry DeLisle > > PR fortran/89782 > * io.c (gfc_resolve_dt): Check that internal units are not > character PARAMETER. This part of the patch is missing. > > * gfortran.dg/io_constraints.f90: New test. > this part looks fine, but depends on the missing part. -- Steve 20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4 20161221 https://www.youtube.com/watch?v=IbCHE-hONow
[PATCH, fortran] PR89782 READ/WRITE of a character array when it is a parameter
Hi all, The front-end is not consistently checking for errors with character parameters as internal units. The reason is we never actually checked for this before. In some cases an error message is triggered from other unrelated causes or sometimes no error is given at all. This is fixed by the attached patch that adds the check in gfc_resolve_dt. I had to place the check before the unit expression is resolved because somewhere in gfc_resolve_expr the attribute information does not trigger for at least one test case (lost?). All cases I found are included in the test case. Regression tested on x86_64-pc-linux-gnu. OK for trunk? Regards, Jerry 2019-06-22 Jerry DeLisle PR fortran/89782 * io.c (gfc_resolve_dt): Check that internal units are not character PARAMETER. * gfortran.dg/io_constraints.f90: New test. ! { dg-do compile } program pr89782 character(len=*),parameter :: VALUES(*)=[character(len=10) :: 'NaN','NAN','nan','Inf','INF','inf','Infinity'] character(len=*),parameter :: VALUE='NaN' real(4) :: var do i=1,size(VALUES) read(VALUES(i),*) float ! { dg-error "character PARAMETER" } write(VALUES(i),*)float ! { dg-error "character PARAMETER" } enddo read(var,*)float! { dg-error "INTEGER expression or a CHARACTER" } read(VALUE,*)float ! { dg-error "character PARAMETER" } write(VALUE,*)float ! { dg-error "character PARAMETER" } end program pr89782