Bug 111339 - bounds-check does not detect nonconforming functions
Summary: bounds-check does not detect nonconforming functions
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: fortran (show other bugs)
Version: 4.3.0
: P3 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on: 31059
Blocks: Fortran_bounds_checking 37802
  Show dependency treegraph
 
Reported: 2023-09-08 09:29 UTC by Mikael Morin
Modified: 2023-09-08 19:50 UTC (History)
7 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2023-09-08 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mikael Morin 2023-09-08 09:29:45 UTC
+++ This bug was initially created as a clone of Bug #31059 +++

Gfortran does not report an error if an allocatable array is set to a function of larger size, for example in the code below.

program p
  integer, allocatable :: ivec(:)
  ivec = [1, 2]
  ! ivec(:) = func()         ! case 1 (already diagnosed)
  ! ivec(:) = ivec + func()  ! case 2
  ! ivec(:) = func() + ivec  ! case 3
contains
  function func()
    integer :: func(3)
    func = [7, 8, 9]
  end function func
end

Uncomment either case 1, case 2 or case 3, and see if the program leads to a runtime error with -fcheck=bounds.
Case 1 is diagnosed, but not case 2 and neither case 3.
Comment 1 anlauf 2023-09-08 19:50:53 UTC
The use of the intrinsic TRANSFER produces the equivalent of a function
but with non-constant size, derived from pr34740, also not detected:

program p
  real, allocatable :: ivec(:)
  real              :: jvec(3) = [1,2,3]
  ivec    = [1.,2.]
  ivec(:) = transfer (jvec, [1.])
end

Detected by NAG, but not by Intel.