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]

[gfortran,patch] Add simplification for LBOUND/UBOUND without DIM argument


Hi all,

This fixes an ICE on valid code (PR 31591) due to UBOUND/LBOUND intrinsics not being simplified when there is not DIM argument provided, ie the result of UBOUND/LBOUND is an array. The following code is an example:

  real :: x(5,5)
  integer, parameter :: a(2) = ubound(x)
  print *, a
  end

This patch is simple. I move the one-dimensional simplification into a new function, simplify_bound_dim. This function is simply used for unidimensional simplication (when DIM is present). For multidimensional simplification, this function is used for each dimension of the array, and if all dimensions can be simplified, we create a constructor for the result. The only subtle issue revealed by testing is indicated by a comment:


+      if (upper && as->type == AS_ASSUMED_SIZE)
+       {
+         /* An error message will be emitted in
+            check_assumed_size_reference (resolve.c).  */
+         return &gfc_bad_expr;
+       }

This avoids emitting this error message twice. I tried hard but couldn't trigger a case where we would not go later into check_assumed_size_reference(), thus it's simpler that way.

Bootstrapped && regtested on i686-linux and x86_64-linux, OK for mainline?

FX


:ADDPATCH fortran:



2007-04-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>


	PR fortran/31591
	* simplify.c (simplify_bound_dim): New function.
	(simplify_bound): Use the above. Perform simplification of LBOUND
	and UBOUND when DIM argument is not present.


2007-04-29 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>


	PR fortran/31591
	* gfortran.dg/bound_simplification_1.f90: New test.


Attachment: bound_simplify.diff
Description: Binary data


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