Message ID | CAGkQGi+mLLMim_WcfD1kbR9KARb1f5Gngg=nE9Sax1Po=aMG0g@mail.gmail.com |
---|---|
State | New |
Headers | show |
Series | [fortran] PR99602 - [11 regression] runtime error: pointer actual argument not associated | expand |
Hi Paul, On 16.03.21 17:42, Paul Richard Thomas via Gcc-patches wrote: > Fortran: Fix runtime errors for class actual arguments [PR99602]. > * trans-array.c (gfc_conv_procedure_call): For class formal > arguments, use the _data field attributes for runtime errors. > * gfortran.dg/pr99602.f90: New test. Shouldn't there be also a testcase which triggers this run-time error? I might have messed up my testcase, but I think it should trigger? (Attached is an attempt to pass the nullified pointer as actual argument to a non-pointer argument; otherwise it is the same testcase as before.) Otherwise, at a glance, it looked sensible. Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
Hi Tobias,
> Shouldn't there be also a testcase which triggers this run-time error?
The testcase is there, it simply has the wrong dg-foo:
! { dg-do compile }
which should be
! { dg-do run }
*-*-*
There are certainly more cases which should insert checks but currently don't, like:
subroutine p (mm)
implicit none
type :: m_t
end type m_t
type, extends (m_t) :: m2_t
end type m2_t
class(m_t), pointer :: mm
select type (mm)
type is (m2_t)
print *, "m2_t"
end select
end
We've still two or three weeks to solve this before 11-release! :-)
Harald
Hi Paul, hi all fortran@/gcc-patch@ reader, it looks as if you replied with your patch submission to the wrong email address – and your re-submission ended up at https://gcc.gnu.org/PR99602#c17 On 16.03.21 18:08, Tobias Burnus wrote: > On 16.03.21 17:42, Paul Richard Thomas via Gcc-patches wrote: >> Fortran: Fix runtime errors for class actual arguments [PR99602]. >> * trans-array.c (gfc_conv_procedure_call): For class formal >> arguments, use the _data field attributes for runtime errors. >> * gfortran.dg/pr99602.f90: New test. > Shouldn't there be also a testcase which triggers this run-time error? Note: The new submission consists of a new testcase (now two) and the actual patch; the new testcase removes 'pointer' from the dummy argument of prepare_m2_proc/prepare_whizard_m2 and checks via the -ftree-original-dump that there is now run-time check code inserted when passing a (nullified) pointer to a nonpointer dummy argument. Compared to previous patch, 'fsym_attr.pointer = fsym_attr.class_pointer' is new, before it was 'fsym_attr.pointer = fsym_attr.pointer'. Paul Richard Thomas wrote in PR99602: > Good morning all, > > I have attached the revised patch and an additional testcase. I had totally > forgotten about the class pointer gotcha. > > OK for master? > > Paul > > Fortran: Fix runtime errors for class actual arguments [PR99602 <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99602>]. LGTM – thanks for the patch. I am wondering whether the second testcase should be a 'dg-do run' test instead of 'compile' to ensure that the error is indeed triggered (currently, it only checks the tree dump that a check is inserted). What do you think? [If you do so, you need a dg-shouldfail + dg-output, cf. e.g. pointer_check_5.f90.] Thanks, Tobias ----------------- Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank Thürauf
Hi Tobias, Thanks for the review. I am resisting dg-run for this patch simply because the testsuite already takes an oppressive amount of time to run. That the runtime error is present in the code should be sufficient IMHO. Regards Paul On Thu, 18 Mar 2021 at 08:46, Tobias Burnus <tobias@codesourcery.com> wrote: > Hi Paul, hi all fortran@/gcc-patch@ reader, > > it looks as if you replied with your patch submission to the wrong email > address – and your re-submission ended up at > https://gcc.gnu.org/PR99602#c17 > > On 16.03.21 18:08, Tobias Burnus wrote: > > On 16.03.21 17:42, Paul Richard Thomas via Gcc-patches wrote: > >> Fortran: Fix runtime errors for class actual arguments [PR99602]. > >> * trans-array.c (gfc_conv_procedure_call): For class formal > >> arguments, use the _data field attributes for runtime errors. > >> * gfortran.dg/pr99602.f90: New test. > > Shouldn't there be also a testcase which triggers this run-time error? > > Note: The new submission consists of a new testcase (now two) and the > actual patch; the new testcase removes 'pointer' from the dummy argument > of prepare_m2_proc/prepare_whizard_m2 and checks via the > -ftree-original-dump that there is now run-time check code inserted when > passing a (nullified) pointer to a nonpointer dummy argument. > > Compared to previous patch, 'fsym_attr.pointer = > fsym_attr.class_pointer' is new, before it was 'fsym_attr.pointer = > fsym_attr.pointer'. > > Paul Richard Thomas wrote in PR99602: > > > Good morning all, > > > > I have attached the revised patch and an additional testcase. I had > totally > > forgotten about the class pointer gotcha. > > > > OK for master? > > > > Paul > > > > Fortran: Fix runtime errors for class actual arguments [PR99602 < > https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99602>]. > > LGTM – thanks for the patch. > > I am wondering whether the second testcase should be a 'dg-do run' test > instead of 'compile' to ensure that the error is indeed triggered > (currently, it only checks the tree dump that a check is inserted). What > do you think? [If you do so, you need a dg-shouldfail + dg-output, cf. > e.g. pointer_check_5.f90.] > > Thanks, > > Tobias > > ----------------- > Mentor Graphics (Deutschland) GmbH, Arnulfstrasse 201, 80634 München > Registergericht München HRB 106955, Geschäftsführer: Thomas Heurung, Frank > Thürauf >
diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index bffe0808dff..0cf17008b05 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -6663,6 +6663,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, char *msg; tree cond; tree tmp; + symbol_attribute fsym_attr; + + if (fsym) + { + if (fsym->ts.type == BT_CLASS && !UNLIMITED_POLY (fsym)) + fsym_attr = CLASS_DATA (fsym)->attr; + else + fsym_attr = fsym->attr; + } if (e->expr_type == EXPR_VARIABLE || e->expr_type == EXPR_FUNCTION) attr = gfc_expr_attr (e); @@ -6685,17 +6694,17 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, tree present, null_ptr, type; if (attr.allocatable - && (fsym == NULL || !fsym->attr.allocatable)) + && (fsym == NULL || !fsym_attr.allocatable)) msg = xasprintf ("Allocatable actual argument '%s' is not " "allocated or not present", e->symtree->n.sym->name); else if (attr.pointer - && (fsym == NULL || !fsym->attr.pointer)) + && (fsym == NULL || !fsym_attr.pointer)) msg = xasprintf ("Pointer actual argument '%s' is not " "associated or not present", e->symtree->n.sym->name); else if (attr.proc_pointer - && (fsym == NULL || !fsym->attr.proc_pointer)) + && (fsym == NULL || !fsym_attr.proc_pointer)) msg = xasprintf ("Proc-pointer actual argument '%s' is not " "associated or not present", e->symtree->n.sym->name); @@ -6719,15 +6728,15 @@ gfc_conv_procedure_call (gfc_se * se, gfc_symbol * sym, else { if (attr.allocatable - && (fsym == NULL || !fsym->attr.allocatable)) + && (fsym == NULL || !fsym_attr.allocatable)) msg = xasprintf ("Allocatable actual argument '%s' is not " "allocated", e->symtree->n.sym->name); else if (attr.pointer - && (fsym == NULL || !fsym->attr.pointer)) + && (fsym == NULL || !fsym_attr.pointer)) msg = xasprintf ("Pointer actual argument '%s' is not " "associated", e->symtree->n.sym->name); else if (attr.proc_pointer - && (fsym == NULL || !fsym->attr.proc_pointer)) + && (fsym == NULL || !fsym_attr.proc_pointer)) msg = xasprintf ("Proc-pointer actual argument '%s' is not " "associated", e->symtree->n.sym->name); else