Bug 31627 - [4.1/4.2 only] -bounds-check doesn't check lower bound of assumed-sized array
Summary: [4.1/4.2 only] -bounds-check doesn't check lower bound of assumed-sized array
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 normal
Target Milestone: 4.3.0
Assignee: Francois-Xavier Coudert
URL: http://gcc.gnu.org/ml/fortran/2007-05...
Keywords: accepts-invalid, diagnostic, patch
Depends on:
Blocks: Fortran_bounds_checking
  Show dependency treegraph
 
Reported: 2007-04-18 19:19 UTC by Francois-Xavier Coudert
Modified: 2007-05-22 10:28 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 4.3.0
Known to fail: 4.2.0 4.1.3
Last reconfirmed: 2007-04-18 19:19:42


Attachments
Tentative patch for this bug (1.80 KB, patch)
2007-05-04 21:32 UTC, Francois-Xavier Coudert
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Francois-Xavier Coudert 2007-04-18 19:19:23 UTC
The following code should tell us we have an out-of-bounds access at runtime:

$ cat a.f90 
subroutine foo(a)
  integer a(*), i
  i = 0
  a(i) = 42
end subroutine foo

program test
  integer x(42)
  call foo(x)
end program test
$ gfortran a.f90 -fbounds-check && ./a.out
Comment 1 Francois-Xavier Coudert 2007-05-04 21:32:30 UTC
Created attachment 13509 [details]
Tentative patch for this bug

Not yet fully tested, nor regtested, but it should do the deed.
Comment 2 Francois-Xavier Coudert 2007-05-22 10:27:40 UTC
Subject: Bug 31627

Author: fxcoudert
Date: Tue May 22 09:27:15 2007
New Revision: 124940

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=124940
Log:
	PR fortran/31627

	* trans-array.c (gfc_trans_array_bound_check): Take extra argument to
	indicate whether we should check the upper bound in that dimension.
	(gfc_conv_array_index_offset): Check only the lower bound of the
	last dimension for assumed-size arrays.
	(gfc_conv_array_ref): Likewise.
	(gfc_conv_ss_startstride): Likewise.

	* gfortran.dg/bounds_check_7.f90: New test.

Added:
    trunk/gcc/testsuite/gfortran.dg/bounds_check_7.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/trans-array.c
    trunk/gcc/testsuite/ChangeLog

Comment 3 Francois-Xavier Coudert 2007-05-22 10:28:23 UTC
Fixed on mainline.