Bug 83683 - eoshift accepts wrong-length boundary
Summary: eoshift accepts wrong-length boundary
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Thomas Koenig
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-01-04 13:55 UTC by Thomas Koenig
Modified: 2018-01-04 21:07 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2018-01-04 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Koenig 2018-01-04 13:55:23 UTC
The following should be rejected:

program main
  implicit none
  integer :: i
  character(len=3) :: e(2,3,4)

  e = reshape([(repeat(achar(i),3),i=iachar('a'),iachar('a')+2*3*4-1)],  shape(e))
  print *,eoshift(e,1,boundary="1")

end program main

From the F2003 standard 13.7.52:

"BOUNDARY (optional) shall be of the same type and type parameters as ARRAY"
Comment 1 Thomas Koenig 2018-01-04 15:21:21 UTC
Another thing that is incorrectly accepted, also with
-fcheck=bounds:

program main
  implicit none
  integer :: n
  integer :: i,n1, n2, n3
  character(len=3), parameter :: e(2,3,4) = reshape([(repeat(achar(i),3),i=iachar('a'),iachar('a')+2*3*4-1)], &
       shape(e))
  character(len=3), parameter :: bnd2(3,5) = reshape([(repeat(achar(i),3),i=iachar('A'),iachar('A')+3*5-1)], &
       shape(bnd2))
  character(len=3) :: f2(2,3,4) ! = eoshift(e,shift=-1,boundary=bnd2);

  n = -1
  f2 = eoshift(e,shift=n,boundary=bnd2);  ! bnd2 has wrong bounds

  print '(*(1H",A,1H",:","))',f2
end program main
Comment 2 Thomas Koenig 2018-01-04 21:04:55 UTC
Author: tkoenig
Date: Thu Jan  4 21:04:23 2018
New Revision: 256265

URL: https://gcc.gnu.org/viewcvs?rev=256265&root=gcc&view=rev
Log:
2018-01-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/83683
	PR fortran/45689
	* check.c (gfc_check_eoshift): Check for string length and
	for conformance of boundary.
	* intrinsic.c (add_functions): Add gfc_simplify_eoshift.
	* intrinsic.h: Add prototype for gfc_simplify_eoshift.
	* simplify.c (gfc_simplify_eoshift): New function.

2018-01-04  Thomas Koenig  <tkoenig@gcc.gnu.org>

	PR fortran/83683
	PR fortran/45689
	* gfortran.dg/eoshift_8.f90: New test.
	* gfortran.dg/simplify_eoshift_1.f90: New test.


Added:
    trunk/gcc/testsuite/gfortran.dg/eoshift_8.f90
    trunk/gcc/testsuite/gfortran.dg/simplify_eoshift_1.f90
Modified:
    trunk/gcc/fortran/ChangeLog
    trunk/gcc/fortran/check.c
    trunk/gcc/fortran/intrinsic.c
    trunk/gcc/fortran/intrinsic.h
    trunk/gcc/fortran/simplify.c
    trunk/gcc/testsuite/ChangeLog
Comment 3 Thomas Koenig 2018-01-04 21:07:29 UTC
Fixed, closing.