The following program produces an incorrect output.
Runs fine if compiled with gnu gfortran
! ifort produces incorrect computation on initialization expression
! must be compiled and run
character(len=3), parameter :: e(2,3) =
character(len=3), parameter :: f1(2,3) = eoshift(e,1) !this is bad
character(len=3) :: f2(2,3)
f2 = eoshift(e,1) !this is good
if(any(f1/=f2)) stop "compiler error!"
Can anybody look into it?
I compiled with Intel® Visual Fortran Compiler - extension version 19.1.0055.15, Package ID: w_comp_lib_2020.1.216. F1 and F2 were the same. What version did you use and what compile options?
Actually I will qualify as I just looked at f1 and f2 in the debugger and they are the same. The problem comes with ( f1 /= f2 )
f1 and f2 are the same with alternate null strings ifort returns ( "null string" /= "null string" ) as true. I don't know what the standards say but maybe that expression is undefined behaviour.
Program testy character(len=3), parameter :: e(2,3) =reshape([(repeat(achar(i),3),i=iachar('a'),iachar('a')+2*3-1)],shape(e)) character(len=3), parameter :: f1(2,3) = eoshift(e,1) !this is bad character(len=3) :: f2(2,3) logical :: logi(2,3) f2 = eoshift(e,1) !this is good print '(6a3)',f1 print '(6a3)',f2 logi = (f1 /= f2 ) if( any(f1/=f2) ) print *,"compiler error!" end
Further digging, I am wrong. F1(2,1) contains 000000 hex whilst f2(2,1) has 202020 ( space char)
So in summary the parameter eoshift zeros the new elements and the variable assignment fills them with space character. That seems like a bug to me.
Andrew_4619, I have ifort 188.8.131.52 under Linux Fedora 32.
Did you try the same program with another compiler, say gnu gfortran.
With gfortran the code runs just fine.
Yes if you read the last line of my previous post, that is crux of the matter. In ifort one initialisation sets the string memory locations to zero and the other sets it to three space characters. This seem like a bug to me. File a ticket with support. You could simplify the test case a bit further
I did open a ticket, number 04793750, but Intel rejected it,
because I only have a 30 days license.
If an Intel engineer reads this, please do something.
To be honest that sucks big time and seems to be the norm. If that is indeed a bug and I believe it is one, I would expect a vendor to log it irrespective of if you have support or not. You are not asking for support just giving up the error.
Program testy character(2), parameter :: e(2) = [ 'aa','bb' ] character(2), parameter :: f1(2) = eoshift(e,1) character(2) :: f2(2) f2 = eoshift( e, 1 ) print '(Z4.4)', transfer( f1(2), 0_4 ) ! prints 0000 print '(Z4.4)', transfer( f2(2), 0_4 ) ! prints 2020 end program testy
I will submit a ticket for the test case above:
edit : Your Support request number is 04795094
The bug report is for ifort. The bug is that f1 and f2 do not have the same data. The reproducer is minimalist and demonstrates the problem. Irrespective of that, the ticket also has a hyperlinks to the forum thread as background.