Paul Thomas - [Patch, fortran] PR30514 and PR30660 (original) (raw)
This is the mail archive of the gcc-patches@gcc.gnu.orgmailing list for the GCC project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
[Patch, fortran] PR30514 and PR30660 - two small fixes and some tidying up
- From: Paul Thomas
- To: Fortran List , gcc-patches
- Date: Sat, 03 Feb 2007 13:29:55 +0100
- Subject: [Patch, fortran] PR30514 and PR30660 - two small fixes and some tidying up
:ADDPATCH fortran:These two small fixes are self explanatory; One replaces a call to gfc_default_initializer with an explicit examination of the components to check if there is a default initializer. Not only is this more efficient but it sidesteps the hidden initializer for allocatable components, which caused the problem. The other fix resets to zero length arrays that are declared with negative length. The testscases are the reporters'.At the same time I have cleared up the warning in resolve.c, associated with gfc_pure_function's "name" argeument not being initialized before it is used.Finally, Dominique flagged to me the fact that actual_array_interface_1.f90 is empty! It has dully been restuffed with the intended test.Bootstrapped and regtested on amd64/Cygwin_NTOK for trunk and, in a week or two, 4.2?Paul
2007-02-03 Paul Thomas pault@gcc.gnu.org
PR fortran/30514
* array.c (match_array_element_spec): If the length of an array is
negative, adjust the uppe limit to make it zero length.
PR fortran/30660
* resolve.c (pure_function, resolve_function): Initialize name to
null to clear up build warnings.
(resolve_fl_variable): Check components explicitly to check for
default initializer, rather than using gfc_default_initializer.
2007-02-03 Paul Thomas pault@gcc.gnu.org
PR fortran/30514
* gfortran.dg/zero_sized_2.f90: New test.
PR fortran/30660
* gfortran.dg/alloc_comp_basics_4.f90: New test.
PR fortran/29820
* gfortran.dg/actual_array_interface_1.f90: Copy source to empty
file.
Index: gcc/fortran/array.c
*** gcc/fortran/array.c (revision 121540)
--- gcc/fortran/array.c (working copy)
*************** match_array_element_spec (gfc_array_spec
*** 319,324 ****
--- 319,333 ----
if (m == MATCH_NO)
return AS_ASSUMED_SHAPE;
+ /* If the size is negative in this dimension, set it to zero. */
+ if ((*lower)->expr_type == EXPR_CONSTANT
+ && (*upper)->expr_type == EXPR_CONSTANT
+ && mpz_cmp ((*upper)->value.integer, (*lower)->value.integer) < 0)
+ {
+ gfc_free_expr (*upper);
+ *upper = gfc_copy_expr (*lower);
+ mpz_sub_ui ((*upper)->value.integer, (*upper)->value.integer, 1);
+ }
return AS_EXPLICIT;
}
Index: gcc/fortran/resolve.c
*** gcc/fortran/resolve.c (revision 121540)
--- gcc/fortran/resolve.c (working copy)
*************** pure_function (gfc_expr *e, const char *
*** 1487,1492 ****
--- 1487,1494 ----
{
int pure;
+ *name = NULL;
+
if (e->symtree != NULL
&& e->symtree->n.sym != NULL
&& e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION)
*************** resolve_function (gfc_expr *expr)
*** 1663,1668 ****
--- 1665,1671 ----
#undef GENERIC_ID
need_full_assumed_size = temp;
+ name = NULL;
if (!pure_function (expr, &name) && name)
{
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 5534,5540 ****
int flag;
int i;
gfc_expr *e;
! gfc_expr *constructor_expr;
const char *auto_save_msg;
auto_save_msg = "automatic object '%s' at %L cannot have the "
--- 5537,5543 ----
int flag;
int i;
gfc_expr *e;
! gfc_component *c;
const char *auto_save_msg;
auto_save_msg = "automatic object '%s' at %L cannot have the "
*************** resolve_fl_variable (gfc_symbol sym, in
*** 5668,5685 ****
}
}
/ 4th constraint in section 11.3: "If an object of a type for which
component-initialization is specified (R429) appears in the
specification-part of a module and does not have the ALLOCATABLE
or POINTER attribute, the object shall have the SAVE attribute." /
!
! constructor_expr = NULL;
! if (sym->ts.type == BT_DERIVED && !(sym->value || flag))
! constructor_expr = gfc_default_initializer (&sym->ts);
!
! if (sym->ns->proc_name
&& sym->ns->proc_name->attr.flavor == FL_MODULE
- && constructor_expr
&& !sym->ns->save_all && !sym->attr.save
&& !sym->attr.pointer && !sym->attr.allocatable)
{
--- 5671,5691 ----
}
}
+ / Do not use gfc_default_initializer to test for a default initializer
+ in the fortran because it generates a hidden default for allocatable
+ components. /
+ c = NULL;
+ if (sym->ts.type == BT_DERIVED && !(sym->value || flag))
+ for (c = sym->ts.derived->components; c; c = c->next)
+ if (c->initializer)
+ break;
+
/ 4th constraint in section 11.3: "If an object of a type for which
component-initialization is specified (R429) appears in the
specification-part of a module and does not have the ALLOCATABLE
or POINTER attribute, the object shall have the SAVE attribute." */
! if (c && sym->ns->proc_name
&& sym->ns->proc_name->attr.flavor == FL_MODULE
&& !sym->ns->save_all && !sym->attr.save
&& !sym->attr.pointer && !sym->attr.allocatable)
{
Index: gcc/testsuite/gfortran.dg/actual_array_interface_1.f90
*** gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 (revision 121540) --- gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 (working copy) *************** *** 0 **** --- 1,27 ---- + ! { dg-do compile } + ! Tests the fix for PR29490, in which the creation of the + ! interface expression for the first argument of the call to + ! 'john' would cause an ICE because GFC_TYPE_ARRAY_LBOUND + ! was NULL. + ! + ! Contributed by Philip Mason pmason@ricardo.com + ! + !--------------------------------- + program fred + !--------------------------------- + real :: dezz(1:10) + real, allocatable :: jack(:) + ! + allocate(jack(10)); jack = 9. + dezz = john(jack,1) + print*,'dezz = ',dezz + + contains + !--------------------------------- + function john(t,il) + !--------------------------------- + real :: t(il:) + real :: john(1:10) + john = 10. + end function john + end Index: gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90
*** gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90 (revision 0) --- gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90 (revision 0) *************** *** 0 **** --- 1,19 ---- + ! { dg-do compile } + ! Tests the fix for PR30660 in which gfortran insisted that g_dest + ! should have the SAVE attribute because the hidden default + ! initializer for the allocatable component was being detected. + ! + ! Contributed by Toon Moene toon@moene.indiv.nluug.nl + ! + MODULE types_m + TYPE grib_t + REAL,DIMENSION(:),ALLOCATABLE :: vdata + END TYPE + END MODULE + + MODULE globals_m + USE types_m + TYPE(grib_t) g_dest ! output field + END MODULE + ! { dg-final { cleanup-modules "types_m globals_m" } } + Index: gcc/testsuite/gfortran.dg/zero_sized_2.f90
*** gcc/testsuite/gfortran.dg/zero_sized_2.f90 (revision 0) --- gcc/testsuite/gfortran.dg/zero_sized_2.f90 (revision 0)
*** 0 **** --- 1,13 ----
- ! { dg-do compile }
- ! Tests the fix for PR30514 in which the bounds on m would cause an
- ! error and the rest would cause the compiler to go into an infinite
- ! loop.
- ! Contributed by Tobias Burnus burnus@gcc.gnu.org
- !
- integer :: i(2:0), j(1:0), m(1:-1)
- integer, parameter :: k(2:0) = 0, l(1:0) = 0
- i = k
- j = l
- m = 5
- end
- Follow-Ups:
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |