From 8fa9e73e6db0ff05447f5547df925fdcb4733d05 Mon Sep 17 00:00:00 2001 From: Sandra Loosemore Date: Sun, 19 Sep 2021 17:23:58 -0700 Subject: Fortran: Fix testcases that violate C838, + revealed ICE The three test cases fixed in this patch violated F2018 C838, which only allows passing an assumed-rank argument to an assumed-rank dummy. Wrapping the call in "select rank" revealed a null pointer dereference which is fixed by guarding the use of the result of GFC_DECL_SAVED_DESCRIPTOR similar to what is already done elsewhere. 2021-09-19 Sandra Loosemore gcc/fortran/ * trans-stmt.c (trans_associate_var): Check that result of GFC_DECL_SAVED_DESCRIPTOR is not null before using it. gcc/testsuite/ * gfortran.dg/assumed_rank_18.f90 (g): Wrap call to h in select rank. * gfortran.dg/assumed_type_10.f90 (test_array): Likewise for call to test_lib. * gfortran.dg/assumed_type_11.f90 (test_array): Likewise. --- gcc/fortran/trans-stmt.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'gcc/fortran') diff --git a/gcc/fortran/trans-stmt.c b/gcc/fortran/trans-stmt.c index 11df186..a8ff473 100644 --- a/gcc/fortran/trans-stmt.c +++ b/gcc/fortran/trans-stmt.c @@ -1788,9 +1788,10 @@ trans_associate_var (gfc_symbol *sym, gfc_wrapped_block *block) /* Go straight to the class data. */ if (sym2->attr.dummy && !sym2->attr.optional) { - class_decl = DECL_LANG_SPECIFIC (sym2->backend_decl) ? - GFC_DECL_SAVED_DESCRIPTOR (sym2->backend_decl) : - sym2->backend_decl; + class_decl = sym2->backend_decl; + if (DECL_LANG_SPECIFIC (class_decl) + && GFC_DECL_SAVED_DESCRIPTOR (class_decl)) + class_decl = GFC_DECL_SAVED_DESCRIPTOR (class_decl); if (POINTER_TYPE_P (TREE_TYPE (class_decl))) class_decl = build_fold_indirect_ref_loc (input_location, class_decl); -- cgit v1.1