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

Bugs and ICE with transfer and character substring

Rodrigo_R_
Beginner
376 Views

I was writing a procedure to reverse characters on a string and found some bugs and even Internal Compiler Errors.

Consider this case:

program reverse
  implicit none
  character(20), parameter :: input = 'Forward'
  integer i
  character(len(input)), parameter :: output = &
     transfer([(input(i:i),i=len_trim(input),1,-1)],trim(input))
  print *, input, '#', len(input)
  print *, output, '#', len(output)
end program reverse

My expected output was:

 Forward             #          20
 drawroF             #          20

But I got this:

 Forward             #          20
 drawroF#           7


I am getting a len=7 character parameter despite of declaring it as len=20. The trimmed length overwrites the declared length for some reason.

Then, I tried changing the code to remove all trimming, like this:

program reverse
  implicit none
  character(20), parameter :: input = 'Forward'
  integer i
  character(len(input)), parameter :: output = &
     transfer([(input(i:i),i=len(input),1,-1)],input)
  print *, input, '#', len(input)
  print *, output, '#', len(output)
end program reverse

 

But this produces an "internal error" on the line of the character declaration. Changing this line again to:

  character(len(input)), parameter :: output = &
     transfer([character::(input(i:i),i=len(input),1,-1)],input)

Now produces a "catastrophic error: **Internal compiler error: segmentation violation signal raised**".

0 Kudos
3 Replies
Rodrigo_R_
Beginner
376 Views

Additional info: I do get the desired output if I remove the `parameter` specifier from it.

0 Kudos
Juergen_R_R
Valued Contributor I
376 Views

Interesting code. Your first variant also introduces an ICE with the PGI compiler, nagfor and gfortran show the length as 20, but gfortran removes all blanks and prints only 7 characters, while nagfor prints 20 characters. Intel - as you noted - shows the length as 7 and prints only 7. An ICE (Internal Compiler Error) is always an error of the compiler, so please report this to Intel Online Support Center.

0 Kudos
mecej4
Honored Contributor III
376 Views

I can see the first error with a number of versions of IFort - Windows. Even Compaq Visual Fortran 6.6C has this error.

With Intel Fortran 14.0.6 (Windows), the second and third versions of the test program get compiled with no errors and the output is correct.

 

0 Kudos
Reply