Re: [PATCH 08/14] fortran: use _P() defines from tree.h
On Sun, 14 May 2023 15:10:12 +0200 Mikael Morin wrote: > Le 14/05/2023 à 01:23, Bernhard Reutner-Fischer via Gcc-patches a écrit : > > From: Bernhard Reutner-Fischer > > > > gcc/fortran/ChangeLog: > > > > * trans-array.cc (is_pointer_array): Use _P() defines from tree.h. > > (gfc_conv_scalarized_array_ref): Ditto. > > (gfc_conv_array_ref): Ditto. > > * trans-decl.cc (gfc_finish_decl): Ditto. > > (gfc_get_symbol_decl): Ditto. > > * trans-expr.cc (gfc_trans_pointer_assignment): Ditto. > > (gfc_trans_arrayfunc_assign): Ditto. > > (gfc_trans_assignment_1): Ditto. > > * trans-intrinsic.cc (gfc_conv_intrinsic_minmax): Ditto. > > (conv_intrinsic_ieee_value): Ditto. > > * trans-io.cc (gfc_convert_array_to_string): Ditto. > > * trans-openmp.cc (gfc_omp_is_optional_argument): Ditto. > > (gfc_trans_omp_clauses): Ditto. > > * trans-stmt.cc (gfc_conv_label_variable): Ditto. > > * trans.cc (gfc_build_addr_expr): Ditto. > > (get_array_span): Ditto. > > OK from the fortran side. > > Thanks Thanks, i'll push it during the weekend. I've fed gfortran.h into the script and found some CLASS_DATA spots, see attached bootstrapped and tested patch. Do we want to have that? If so, i'd write a proper ChangeLog, of course. Thanks! diff --git a/gcc/fortran/class.cc b/gcc/fortran/class.cc index 9d0c802b867..1466b07e260 100644 --- a/gcc/fortran/class.cc +++ b/gcc/fortran/class.cc @@ -889,7 +889,7 @@ copy_vtab_proc_comps (gfc_symbol *declared, gfc_symbol *vtype) vtab = gfc_find_derived_vtab (declared); - for (cmp = vtab->ts.u.derived->components; cmp; cmp = cmp->next) + for (cmp = CLASS_DATA (vtab); cmp; cmp = cmp->next) { if (gfc_find_component (vtype, cmp->name, true, true, NULL)) continue; @@ -1078,7 +1078,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp, gfc_component *c; vtab = gfc_find_derived_vtab (comp->ts.u.derived); - for (c = vtab->ts.u.derived->components; c; c = c->next) + for (c = CLASS_DATA (vtab); c; c = c->next) if (strcmp (c->name, "_final") == 0) break; @@ -1143,7 +1143,7 @@ finalize_component (gfc_expr *expr, gfc_symbol *derived, gfc_component *comp, { gfc_component *c; - for (c = comp->ts.u.derived->components; c; c = c->next) + for (c = CLASS_DATA (comp); c; c = c->next) finalize_component (e, comp->ts.u.derived, c, stat, fini_coarray, code, sub_ns); gfc_free_expr (e); @@ -1675,7 +1675,7 @@ generate_finalization_wrapper (gfc_symbol *derived, gfc_namespace *ns, gfc_component *comp; vtab = gfc_find_derived_vtab (derived->components->ts.u.derived); - for (comp = vtab->ts.u.derived->components; comp; comp = comp->next) + for (comp = CLASS_DATA (vtab); comp; comp = comp->next) if (comp->name[0] == '_' && comp->name[1] == 'f') { ancestor_wrapper = comp->initializer; @@ -2752,7 +2752,7 @@ yes: { /* Return finalizer expression. */ gfc_component *final; - final = vtab->ts.u.derived->components->next->next->next->next->next; + final = CLASS_DATA (vtab)->next->next->next->next->next; gcc_assert (strcmp (final->name, "_final") == 0); gcc_assert (final->initializer && final->initializer->expr_type != EXPR_NULL); diff --git a/gcc/fortran/data.cc b/gcc/fortran/data.cc index d29eb12c1b1..f907bb35eb1 100644 --- a/gcc/fortran/data.cc +++ b/gcc/fortran/data.cc @@ -730,7 +730,7 @@ formalize_structure_cons (gfc_expr *expr) if (!cur || cur->n.component == NULL) return; - for (order = expr->ts.u.derived->components; order; order = order->next) + for (order = CLASS_DATA (expr); order; order = order->next) { cur = find_con_by_component (order, expr->value.constructor); if (cur) diff --git a/gcc/fortran/dependency.cc b/gcc/fortran/dependency.cc index b398b29a642..864470afdec 100644 --- a/gcc/fortran/dependency.cc +++ b/gcc/fortran/dependency.cc @@ -1253,7 +1253,7 @@ check_data_pointer_types (gfc_expr *expr1, gfc_expr *expr2) if (sym1->ts.type == BT_DERIVED && !seen_component_ref) { - for (cm1 = sym1->ts.u.derived->components; cm1; cm1 = cm1->next) + for (cm1 = CLASS_DATA (sym1); cm1; cm1 = cm1->next) { if (cm1->ts.type == BT_DERIVED) return false; diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index aa01a4d3d22..a6b4ef0a0bf 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -2671,7 +2671,7 @@ check_alloc_comp_init (gfc_expr *e) gcc_assert (e->expr_type == EXPR_STRUCTURE); gcc_assert (e->ts.type == BT_DERIVED || e->ts.type == BT_CLASS); - for (comp = e->ts.u.derived->components, + for (comp = CLASS_DATA (e), ctor = gfc_constructor_first (e->value.constructor); comp; comp = comp->next, ctor = gfc_constructor_next (ctor)) { @@ -5061,7 +5061,7 @@ component_initializer (gfc_component *c, bool generate) else if (c->ts.type == BT_DERIVED || c->t
Re: [PATCH 08/14] fortran: use _P() defines from tree.h
Le 18/05/2023 à 17:18, Bernhard Reutner-Fischer a écrit : On Sun, 14 May 2023 15:10:12 +0200 Mikael Morin wrote: Le 14/05/2023 à 01:23, Bernhard Reutner-Fischer via Gcc-patches a écrit : From: Bernhard Reutner-Fischer gcc/fortran/ChangeLog: * trans-array.cc (is_pointer_array): Use _P() defines from tree.h. (gfc_conv_scalarized_array_ref): Ditto. (gfc_conv_array_ref): Ditto. * trans-decl.cc (gfc_finish_decl): Ditto. (gfc_get_symbol_decl): Ditto. * trans-expr.cc (gfc_trans_pointer_assignment): Ditto. (gfc_trans_arrayfunc_assign): Ditto. (gfc_trans_assignment_1): Ditto. * trans-intrinsic.cc (gfc_conv_intrinsic_minmax): Ditto. (conv_intrinsic_ieee_value): Ditto. * trans-io.cc (gfc_convert_array_to_string): Ditto. * trans-openmp.cc (gfc_omp_is_optional_argument): Ditto. (gfc_trans_omp_clauses): Ditto. * trans-stmt.cc (gfc_conv_label_variable): Ditto. * trans.cc (gfc_build_addr_expr): Ditto. (get_array_span): Ditto. OK from the fortran side. Thanks Thanks, i'll push it during the weekend. I've fed gfortran.h into the script and found some CLASS_DATA spots, see attached bootstrapped and tested patch. Do we want to have that? Some of it makes sense, but not all of it. It is a macro to access the _data component of a class container. So for class-related stuff it makes sense to use CLASS_DATA, and typically there will be a check that the type is BT_CLASS before. But for cases where we loop over all of the components of a type that is not necessarily a class container, it doesn't make sense to use CLASS_DATA. So I suggest to only keep the following hunks. diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc index aa01a4d3d22..a6b4ef0a0bf 100644 --- a/gcc/fortran/expr.cc +++ b/gcc/fortran/expr.cc @@ -5847,9 +5847,9 @@ gfc_get_corank (gfc_expr *e) if (!gfc_is_coarray (e)) return 0; - if (e->ts.type == BT_CLASS && e->ts.u.derived->components) -corank = e->ts.u.derived->components->as -? e->ts.u.derived->components->as->corank : 0; + if (e->ts.type == BT_CLASS && CLASS_DATA (e)) +corank = CLASS_DATA (e)->as +? CLASS_DATA (e)->as->corank : 0; else corank = e->symtree->n.sym->as ? e->symtree->n.sym->as->corank : 0; diff --git a/gcc/fortran/resolve.cc b/gcc/fortran/resolve.cc index 9c92958a397..6e26fb07ddd 100644 --- a/gcc/fortran/resolve.cc +++ b/gcc/fortran/resolve.cc @@ -15176,7 +15176,7 @@ resolve_component (gfc_component *c, gfc_symbol *sym) /* Check type-spec if this is not the parent-type component. */ if (((sym->attr.is_class && (!sym->components->ts.u.derived->attr.extension -|| c != sym->components->ts.u.derived->components)) + || c != CLASS_DATA (sym->components))) || (!sym->attr.is_class && (!sym->attr.extension || c != sym->components))) && !sym->attr.vtype @@ -15189,7 +15189,7 @@ resolve_component (gfc_component *c, gfc_symbol *sym) component. */ if (super_type && ((sym->attr.is_class - && c == sym->components->ts.u.derived->components) + && c == CLASS_DATA (sym->components)) || (!sym->attr.is_class && c == sym->components)) && strcmp (super_type->name, c->name) == 0) c->attr.access = super_type->attr.access; @@ -15435,7 +15435,7 @@ resolve_fl_derived0 (gfc_symbol *sym) return false; } - c = (sym->attr.is_class) ? sym->components->ts.u.derived->components + c = (sym->attr.is_class) ? CLASS_DATA (sym->components) : sym->components; success = true; diff --git a/gcc/fortran/simplify.cc b/gcc/fortran/simplify.cc index a7b4784d73a..6ba2040e61c 100644 --- a/gcc/fortran/simplify.cc +++ b/gcc/fortran/simplify.cc @@ -3116,28 +3116,28 @@ gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold) /* Return .false. if the dynamic type can never be an extension. */ if ((a->ts.type == BT_CLASS && mold->ts.type == BT_CLASS && !gfc_type_is_extension_of - (mold->ts.u.derived->components->ts.u.derived, -a->ts.u.derived->components->ts.u.derived) + (CLASS_DATA (mold)->ts.u.derived, +CLASS_DATA (a)->ts.u.derived) && !gfc_type_is_extension_of - (a->ts.u.derived->components->ts.u.derived, -mold->ts.u.derived->components->ts.u.derived)) + (CLASS_DATA (a)->ts.u.derived, +CLASS_DATA (mold)->ts.u.derived)) || (a->ts.type == BT_DERIVED && mold->ts.type == BT_CLASS && !gfc_type_is_extension_of - (mold->ts.u.derived->components->ts.u.derived, + (CLASS_DATA (mold)->ts.u.derived, a->ts.u.derived)) || (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED &&
Re: [PATCH v2] Fortran: Narrow return types [PR78798]
On Sun, 14 May 2023 14:27:42 +0200 Mikael Morin wrote: > Le 10/05/2023 à 18:47, Bernhard Reutner-Fischer via Fortran a écrit : > > From: Bernhard Reutner-Fischer > > > > gcc/fortran/ChangeLog: > > > > PR fortran/78798 > > * array.cc (compare_bounds): Use narrower return type. > > (gfc_compare_array_spec): Likewise. > > (is_constant_element): Likewise. > > (gfc_constant_ac): Likewise. > (...) > > --- > > Bootstrapped without new warnings and regression tested on > > x86_64-linux with no regressions, OK for trunk? > > > (...) > > diff --git a/gcc/fortran/check.cc b/gcc/fortran/check.cc > > index b348bda6e6c..4e3aed84b9d 100644 > > --- a/gcc/fortran/check.cc > > +++ b/gcc/fortran/check.cc > > @@ -1156,7 +1156,7 @@ dim_rank_check (gfc_expr *dim, gfc_expr *array, int > > allow_assumed) > > dimension bi, returning 0 if they are known not to be identical, > > and 1 if they are identical, or if this cannot be determined. */ > > > > -static int > > +static bool > > identical_dimen_shape (gfc_expr *a, int ai, gfc_expr *b, int bi) > > { > > mpz_t a_size, b_size; > > To be consistent, please change as well the local variable "ret" used as > return value from int to bool. > > > diff --git a/gcc/fortran/cpp.cc b/gcc/fortran/cpp.cc > > index c3b7c7f7bd9..d7890a97287 100644 > > --- a/gcc/fortran/cpp.cc > > +++ b/gcc/fortran/cpp.cc > > @@ -297,7 +297,7 @@ gfc_cpp_init_options (unsigned int > > decoded_options_count, > > gfc_cpp_option.deferred_opt_count = 0; > > } > > > > -int > > +bool > > gfc_cpp_handle_option (size_t scode, const char *arg, int value > > ATTRIBUTE_UNUSED) > > { > > int result = 1; > > Same here, change the type of variable "result". > > (...) > > diff --git a/gcc/fortran/dependency.cc b/gcc/fortran/dependency.cc > > index a648d5c7903..b398b29a642 100644 > > --- a/gcc/fortran/dependency.cc > > +++ b/gcc/fortran/dependency.cc > (...) > > > @@ -1091,7 +1091,7 @@ gfc_check_argument_dependency (gfc_expr *other, > > sym_intent intent, > > /* Like gfc_check_argument_dependency, but check all the arguments in > > ACTUAL. > > FNSYM is the function being called, or NULL if not known. */ > > > > -int > > +bool > > gfc_check_fncall_dependency (gfc_expr *other, sym_intent intent, > > gfc_symbol *fnsym, gfc_actual_arglist *actual, > > gfc_dep_check elemental) > > Why not change the associated subfunctions > (gfc_check_argument_dependency, gfc_check_argument_var_dependency) as well ? I have left these subfunctions alone for now to get the other hunks out of the way. I have adjusted the patch according to your other comments and pushed it as r14-973-gc072df1ab14450. Thanks! > > (...) > > @@ -2098,7 +2098,7 @@ ref_same_as_full_array (gfc_ref *full_ref, gfc_ref > > *ref) > > there is some kind of overlap. > > 0 : array references are identical or not overlapping. */ > > > > -int > > +bool > > gfc_dep_resolver (gfc_ref *lref, gfc_ref *rref, gfc_reverse *reverse, > > bool identical) > > { > > The function comment states that the function may return 2, which > doesn't seem to be the case any more. So please update the comment. > > (...)> diff --git a/gcc/fortran/symbol.cc b/gcc/fortran/symbol.cc > > index 221165d6dac..b4b36e27d75 100644 > > --- a/gcc/fortran/symbol.cc > > +++ b/gcc/fortran/symbol.cc > > @@ -3216,7 +3216,7 @@ gfc_find_symtree_in_proc (const char* name, > > gfc_namespace* ns) > > any parent namespaces if requested by a nonzero parent_flag. > > Returns nonzero if the name is ambiguous. */ > > > > -int > > +bool > > gfc_find_sym_tree (const char *name, gfc_namespace *ns, int parent_flag, > >gfc_symtree **result) > > { > > Maybe change nonzero to true in the comment? > > (...) > > OK with all the above fixed. > > Thanks. >