This is the mail archive of the gcc-patches@gcc.gnu.org mailing 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] PR23091 and PR24168


:ADDPATCH fortran:

These two came up during my first trawl through the buglist for initializer PRs. They both came up throught keywords I was employing for the search.

PR23091 is trivial; in resolving automatic objects, check that they do not have the SAVE attribute. Note that global SAVEs are meant not to include anything than valid variables.

PR24168 is a small (1 line in its essentials) patch which was less than trivial to lay hands on! It turned out that the problem in dealing with:

f = spread(cshift((/ (i, i = 1, nx) /), nx/2) * 2, 2, ny)
was not the scalarizer, not the intrinsics but rather the multiplication by 2! The simplifier was not passing on the rank correctly, when simplifying binary operator expressions, and, in consequence, there was a type/rank mismatch between lhs and rhs, in the assignment.


Regtested on FC5/Athlon1700. OK for trunk and 4.1?

Paul

2006-06-06 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/23091
   * resolve.c (resolve_fl_variable): Error if an automatic
   object has the SAVE attribute.

   PR fortran/24168
   * expr.c (simplify_intrinsic_op): Transfer the rank and
   the locus to the simplified expression.

2006-06-06 Paul Thomas <pault@gcc.gnu.org>

   PR fortran/23091
   * gfortran.dg/saved_automatic_1.f90: New test.

   PR fortran/24168
   * gfortran.dg/array_simplify_1.f90: New test.


Index: gcc/testsuite/gfortran.dg/array_simplify_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/array_simplify_1.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/array_simplify_1.f90	(revision 0)
***************
*** 0 ****
--- 1,16 ----
+ ! { dg-do compile }
+ ! Tests the fix for PR24168, in which line   would return
+ ! Error: Incompatible ranks 2 and 1 in assignment at (1)
+ ! This came about because the simplification of the binary
+ ! operation, in the first actual argument of spread, was not
+ ! returning the rank of the result.  Thus the error could
+ ! be generated with any operator and other intrinsics than
+ ! cshift.
+ !
+ ! Contributed by Steve Kargl  <kargl@gcc.gnu.org>
+ !
+  integer, parameter :: nx=2, ny=2
+  real, dimension(nx, ny) :: f
+  f = spread(2 * cshift((/ 1, 2 /), nx/2), 2, ny)
+ end
+ 
Index: gcc/testsuite/gfortran.dg/saved_automatic_1.f90
===================================================================
*** gcc/testsuite/gfortran.dg/saved_automatic_1.f90	(revision 0)
--- gcc/testsuite/gfortran.dg/saved_automatic_1.f90	(revision 0)
***************
*** 0 ****
--- 1,21 ----
+ ! { dg-do compile }
+ ! Tests patch for PR23091, in which autmatic objects caused
+ ! an ICE if they were given the SAVE attribute.
+ !
+ ! Contributed by Valera Veryazov  <valera.veryazov@teokem.lu.se>
+ !
+ Subroutine My(n1)
+   integer :: myArray(n1)
+   character(n1) :: ch
+   save      ! OK because only allowed objects are saved globally.
+   call xxx(myArray, ch)
+   return
+   end
+ 
+ Subroutine Thy(n1)
+   integer, save :: myArray(n1) ! { dg-error "SAVE attribute" }
+   character(n1), save :: ch ! { dg-error "SAVE attribute" }
+   call xxx(myArray, ch)
+   return
+   end
+ 
Index: gcc/fortran/expr.c
===================================================================
*** gcc/fortran/expr.c	(revision 114421)
--- gcc/fortran/expr.c	(working copy)
*************** simplify_intrinsic_op (gfc_expr * p, int
*** 869,874 ****
--- 869,876 ----
        return FAILURE;
      }
  
+   result->rank = p->rank;
+   result->where = p->where;
    gfc_replace_expr (p, result);
  
    return SUCCESS;
Index: gcc/fortran/resolve.c
===================================================================
*** gcc/fortran/resolve.c	(revision 114421)
--- gcc/fortran/resolve.c	(working copy)
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 4877,4882 ****
--- 4877,4886 ----
    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 "
+ 		  "SAVE attribute";
  
    if (resolve_fl_var_and_proc (sym, mp_flag) == FAILURE)
      return FAILURE;
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 4907,4912 ****
--- 4911,4922 ----
  	  return FAILURE;
  	}
  
+       if (e && sym->attr.save && !gfc_is_constant_expr (e))
+ 	{
+ 	  gfc_error (auto_save_msg, sym->name, &sym->declared_at);
+ 	  return FAILURE;
+ 	}
+ 
        if (!gfc_is_constant_expr (e)
  	    && !(e->expr_type == EXPR_VARIABLE
  	    && e->symtree->n.sym->attr.flavor == FL_PARAMETER)
*************** resolve_fl_variable (gfc_symbol *sym, in
*** 4940,4945 ****
--- 4950,4962 ----
  	      break;
  	    }
  	}
+ 
+       /* Also, they must not have the SAVE attribute.  */
+       if (flag && sym->attr.save)
+ 	{
+ 	  gfc_error (auto_save_msg, sym->name, &sym->declared_at);
+ 	  return FAILURE;
+ 	}
    }
  
    /* Reject illegal initializers.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]