Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29329 Discussions

Correct Intel option(s) to detect out-of-bounds

Matt_Thompson
Novice
585 Views

All,

A colleague of mine whipped up this code:

 

program omg
  implicit none
  integer, dimension(:), allocatable :: arr

  allocate(arr(2:1))   ! some allocations are designed to give a size of zero
  write(6,*) size(arr) ! and this is what happens
  arr(1) = 2           ! but why doesn't the ifort bounds checker detect this as out-of-bounds?
  write(6,*) arr(0)    ! or even this?
  print*, lbound(arr), ubound(arr)

end program omg

 

and when we run with NAG Fortran, we get an error:

 

@$ nagfor -C=all test.F90
NAG Fortran Compiler Release 7.2(Shin-Urayasu) Build 7201
[NAG Fortran Compiler normal termination]
mathomp4@gs6101-bucy ~/F90Files/OutOfBounds
@$ ./a.out
 0
Runtime Error: test.F90, line 7: Subscript 1 of ARR (value 1) is out of range (2:1)
Program terminated by fatal error
Aborted (core dumped)

 

 With GCC 13.2, an error:

 

@$ gfortran --version
GNU Fortran (GCC) 13.2.0
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

@$ gfortran -O0 -g -fcheck=all test.F90
@$ ./a.out
           0
At line 7 of file test.F90
Fortran runtime error: Index '1' of dimension 1 of array 'arr' below lower bound of 2

Error termination. Backtrace:
#0  0x400a31 in omg
	at /home/mathomp4/F90Files/OutOfBounds/test.F90:7
#1  0x400d1e in main
	at /home/mathomp4/F90Files/OutOfBounds/test.F90:11

 

However, we can't seem to get Intel to trigger on it. Neither ifort:

@$ ifort -diag-disable=10448 -V
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.12.0 Build 20240222_000000
Copyright (C) 1985-2024 Intel Corporation.  All rights reserved.

@$ ifort -check all  -init=snan,arrays -diag-disable=10448 test.F90
@$ ./a.out
           0
    22667968
           1           0

Nor ifx:

@$ ifx -V
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.1.0 Build 20240308
Copyright (C) 1985-2024 Intel Corporation. All rights reserved.

@$ ifx -check all  -init=snan,arrays test.F90
@$ ./a.out
           0
           0
           1           0

 

seem to. My guess is I'm just not passing in the right option. We usually use `-check all -init=snan,arrays` for most of our debugging runs, but they don't seem to trip this.

Labels (1)
0 Kudos
0 Replies
Reply