Hi Tobias, > > This works as expected with Intel and AOCC, but gives a > > syntax error with every gfortran tested because of match.c: > > > > alloc_opt_list: > > m = gfc_match (" stat = %v", &tmp); > > I think we can simply change that one to %e; the definable > check should ensure that any non variable (in the Fortran sense) > is rejected. > > And we should update the comment for %v / match_variable to state > that it does not include function references. I've updated this for ALLOCATE/DEALLOCATE and STAT/ERRMSG, see attached patch. This required updating the error messages of two existing files in the testsuite. > Also affected: Some I/O items, a bunch of other stat=%v and > errmsg=%v. We should rather open a separate PR on auditing the related uses of gfc_match. > Talking about errmsg: In the same function, the same check is > done for errmsg as for stat – hence, the patch should update > also errmsg. Done. > >> Additionally, I have to admit that I do not understand the > >> following existing condition, which you did not touch: > >> > >> if ((stat->ts.type != BT_INTEGER > >> && !(stat->ref && (stat->ref->type == REF_ARRAY > >> || stat->ref->type == REF_COMPONENT))) > >> || stat->rank > 0) > >> gfc_error ("Stat-variable at %L must be a scalar INTEGER " > >> "variable", &stat->where); > >> > >> I mean the ts.type != BT_INTEGER and stat->rank != 0 is clear, > >> but what's the reason for the refs? > > Well, that needs to be answered by Steve (see commit 3759634). > > (https://gcc.gnu.org/g:3759634f3208cbc1226bec19d22cbff989a287c3 (svn > r145331)) > > The reason for the ref checks is unclear and seem to be wrong. The added > testcases also only use 'x' (real) and n or i (integer) as input, i.e. > they do not exercise this. I did not look for the patch email for reasoning. Well, there is some text in the standard that I added in front of the for loops, and this code is now exercised in the new testcase. Regtested on x86_64-pc-linux-gnu. OK? Thanks, Harald Fortran: ICE in resolve_allocate_deallocate for invalid STAT argument gcc/fortran/ChangeLog: PR fortran/101564 * match.c (gfc_match): Fix comment for %v code. (gfc_match_allocate, gfc_match_deallocate): Replace use of %v code by %e in gfc_match to allow for function references as STAT and ERRMSG arguments. * resolve.c (resolve_allocate_deallocate): Avoid NULL pointer dereferences and shortcut for bad STAT and ERRMSG argument to (DE)ALLOCATE. gcc/testsuite/ChangeLog: PR fortran/101564 * gfortran.dg/allocate_stat_3.f90: New test. * gfortran.dg/allocate_stat.f90: Adjust error messages. * gfortran.dg/implicit_11.f90: Adjust error messages.