Message ID | trinity-e125c0ac-3af1-4556-801c-891141101000-1630095269900@3c-app-gmx-bap05 |
---|---|
State | New |
Headers | show |
Series | PR fortran/87737 - ICE tree check: expected ssa_name, have addr_expr in remap_gimple_op_r, at tree-inline.c:923 | expand |
Hi Harald, It looks good to me. OK for mainline. You might even consider backporting to 11-branch. Best regards Paul On Fri, 27 Aug 2021 at 21:15, Harald Anlauf via Fortran <fortran@gcc.gnu.org> wrote: > Dear all, > > the ICE in the original testcase does no longer occur but leads to an > error in a later stage of compilation, and we accepted invalid code. > (Cross-checked with other compilers, such as Intel and NAG). > > F2018 states: > > 15.6.2.6 ENTRY statement > > (3) ... If the characteristics of the result of the function named in the > ENTRY statement are the same as the characteristics of the result of the > function named in the FUNCTION statement, their result names identify the > same > entity, although their names need not be the same. Otherwise, they are > storage > associated and shall all be nonpointer, nonallocatable scalar variables > that > are default integer, default real, double precision real, default complex, > or > default logical. > > We thus better reject the testcase example during resolution with an > appropriate error message. (I hope the chosen one is fine enough.) > > Regtested on x86_64-pc-linux-gnu. OK for mainline? > > Thanks, > Harald > > > Fortran - reject function entries with mismatched characteristics > > gcc/fortran/ChangeLog: > > PR fortran/87737 > * resolve.c (resolve_entries): For functions of type CHARACTER > tighten the checks for matching characteristics. > > gcc/testsuite/ChangeLog: > > PR fortran/87737 > * gfortran.dg/entry_24.f90: New test. > >
diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 5b9ba43780e..f641d0d4dae 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -804,6 +804,15 @@ resolve_entries (gfc_namespace *ns) the same string length, i.e. both len=*, or both len=4. Having both len=<variable> is also possible, but difficult to check at compile time. */ + else if (ts->type == BT_CHARACTER + && (el->sym->result->attr.allocatable + != ns->entries->sym->result->attr.allocatable)) + { + gfc_error ("Function %s at %L has entry %s with mismatched " + "characteristics", ns->entries->sym->name, + &ns->entries->sym->declared_at, el->sym->name); + return; + } else if (ts->type == BT_CHARACTER && ts->u.cl && fts->u.cl && (((ts->u.cl->length && !fts->u.cl->length) ||(!ts->u.cl->length && fts->u.cl->length)) diff --git a/gcc/testsuite/gfortran.dg/entry_24.f90 b/gcc/testsuite/gfortran.dg/entry_24.f90 new file mode 100644 index 00000000000..9773597f4e1 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/entry_24.f90 @@ -0,0 +1,20 @@ +! { dg-do compile } +! PR fortran/87737 - improve check on function entry characteristics + +function f() ! { dg-error "mismatched characteristics" } + character(:), allocatable :: f + character(1) :: g + f = 'f' + return +entry g() + g = 'g' +end + +function f2() ! { dg-error "mismatched characteristics" } + character(1) :: f2 + character(1), allocatable :: g2 + f2 = 'f' + return +entry g2() + g2 = 'g' +end