Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28446 Discussions

ICE with bounds violation in constant expression

New Contributor II


this snippet of invalid Fortran crashes current ifort/ifx:

program p
  implicit none
  integer :: i
  integer, parameter :: a(0) = 0
  integer, parameter :: b(*) = [(a(i:i), i=0,0)]  ! ICE-on-invalid

 I get:

% ifort ifort-bounds.f90
ifort-bounds.f90(1): catastrophic error: **Internal compiler error: internal abort** Please report this error along with the circumstances in which it occurred in a Software Problem Report.  Note: File and line given may not be explicit cause of this error.
compilation aborted for ifort-bounds.f90 (code 1)

and a more extended traceback with ifx.





5 Replies

@Harald1, thank you for reporting this. I know I say this often; thank you, too, for the simple reproducer.

I filed a bug report, CMPLRLLVM-47855. I'll let you know when there's a fix.

Glad this is not a show-stopper for you!

0 Kudos
Honored Contributor III

Harald, Barbara,

While ICE shouldn't happen, isn't

    integer, parameter :: a(0) = 0

also an erroneous statement?

While a zero sized array is supported, wouldn't the initializer (=0) be in error. I suppose they may be considered valid as array=scalar sets the initializer into the size of the array, and size being zero would result in nothing done. However, this presents a paradox in that the array does not contain all 0's.

In the first parameter the (0) is the size of the array.

An error should have been reported on the a(i) in the next statement, when i=0 as this would be an index out of bounds.

Jim Dempsey

New Contributor II

In Fortran, you can assign a scalar to an array of any rank and shape, even if its size is zero.

Similarly, you can have a "named constant" (e.g. F2023, 8.5.13 PARAMETER attribute) with a value defined by a constant expression which is a scalar for any rank and shape.

Sometimes one just needs such a constant object of the right type, kind, rank (and value) in a program...

(Fortran even allows loops with zero trip counts...)


0 Kudos
Honored Contributor III

I wasn't objecting to a zero sized array.

I wasn't objecting to indexing a zero sized array with the expectation that an out of bounds error can be raised (in this case at compile time)

I was objecting to:

you>>value defined...

me>this presents a paradox in that the array does not contain all 0's

IOW the value is not defined.

The ICE shouldn't happen, and thanks for bringing this up for Intel to address.

Jim Dempsey


0 Kudos
New Contributor II

There is no paradox.  If the lhs has size zero, then there is nothing to do, and the initializer is effectively empty.


Of course one can write the declaration using an array constructor on the rhs, like:


integer, parameter :: a(0) = [ integer :: ]


Things may get cumbersome for arrays of higher rank.  So one could either write


  integer, parameter :: b(0,42) = 0




integer, parameter :: b(0,42) = reshape ([ integer :: ], shape=shape (b))


The scalar initializer is even plain Fortran 90, while the array constructor with type-spec is Fortran 2003.  I find the versions with a scalar initializer much more readable.

(For experts in code obfuscation, there are other funny initializers possible for rank > 1, using e.g. spread).


0 Kudos