From: Paul Thomas Date: Sat, 3 Feb 2007 13:38:42 +0000 (+0000) Subject: re PR fortran/30514 ([4.1 only] zero-sized array wrongly rejected: integer :: i(1... X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=36f7dcae093c3ed596010a4bf88ce731a7d6236e;p=platform%2Fupstream%2Fgcc.git re PR fortran/30514 ([4.1 only] zero-sized array wrongly rejected: integer :: i(1:-1)) 2007-02-03 Paul Thomas PR fortran/30514 * array.c (match_array_element_spec): If the length of an array is negative, adjust the upper 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): Look at components explicitly to check for default initializer, rather than using gfc_default_initializer. 2007-02-03 Paul Thomas 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. From-SVN: r121541 --- diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index 0b25674..1883288 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,15 @@ +2007-02-03 Paul Thomas + + PR fortran/30514 + * array.c (match_array_element_spec): If the length of an array is + negative, adjust the upper 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): Look at components explicitly to check for + default initializer, rather than using gfc_default_initializer. + 2007-02-02 Steven G. Kargl PR fortran/30683 diff --git a/gcc/fortran/array.c b/gcc/fortran/array.c index 76dee50..895bccc 100644 --- a/gcc/fortran/array.c +++ b/gcc/fortran/array.c @@ -319,6 +319,15 @@ match_array_element_spec (gfc_array_spec *as) 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; } diff --git a/gcc/fortran/resolve.c b/gcc/fortran/resolve.c index 41e13b0..84d42ee 100644 --- a/gcc/fortran/resolve.c +++ b/gcc/fortran/resolve.c @@ -1487,6 +1487,8 @@ pure_function (gfc_expr *e, const char **name) { int pure; + *name = NULL; + if (e->symtree != NULL && e->symtree->n.sym != NULL && e->symtree->n.sym->attr.proc == PROC_ST_FUNCTION) @@ -1663,6 +1665,7 @@ resolve_function (gfc_expr *expr) #undef GENERIC_ID need_full_assumed_size = temp; + name = NULL; if (!pure_function (expr, &name) && name) { @@ -5534,7 +5537,7 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) int flag; int i; gfc_expr *e; - gfc_expr *constructor_expr; + gfc_component *c; const char *auto_save_msg; auto_save_msg = "automatic object '%s' at %L cannot have the " @@ -5668,18 +5671,21 @@ resolve_fl_variable (gfc_symbol *sym, int mp_flag) } } + /* 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." */ - - constructor_expr = NULL; - if (sym->ts.type == BT_DERIVED && !(sym->value || flag)) - constructor_expr = gfc_default_initializer (&sym->ts); - - if (sym->ns->proc_name + if (c && 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) { diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 67b1ae9..89c4441 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,15 @@ +2007-02-03 Paul Thomas + + 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. + 2007-02-02 Steven G. Kargl PR fortran/30683 diff --git a/gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 b/gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 index e69de29..bc020a3 100644 --- a/gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 +++ b/gcc/testsuite/gfortran.dg/actual_array_interface_1.f90 @@ -0,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 +! + !--------------------------------- + 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 diff --git a/gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90 b/gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90 new file mode 100644 index 0000000..c910b70 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/alloc_comp_basics_4.f90 @@ -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 +! +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" } } + diff --git a/gcc/testsuite/gfortran.dg/zero_sized_2.f90 b/gcc/testsuite/gfortran.dg/zero_sized_2.f90 new file mode 100644 index 0000000..eda2de2 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/zero_sized_2.f90 @@ -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 +! +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 +