Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Beginner
241 Views

Incorrect output

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) =
1 reshape([(repeat(achar(i),3),i=iachar('a'),iachar('a')+2*3-1)],
2 shape(e))

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
print '(6a3)',f1
print '(6a3)',f2
if(any(f1/=f2)) stop "compiler error!"
end
Can anybody look into it?

0 Kudos
11 Replies
Highlighted
Valued Contributor III
229 Views

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?

 

0 Kudos
Highlighted
Valued Contributor III
228 Views

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.

 

0 Kudos
Highlighted
Beginner
222 Views

Andrew_4619, I have ifort 19.1.2.254 under Linux Fedora 32.

Did you try the same program with another compiler, say gnu gfortran.

With gfortran the code runs just fine.

0 Kudos
Highlighted
Beginner
221 Views

With ifort I get

bbbdddfff

bbb   ddd   fff

while with gfortran I get

bbbdddfff

bbbdddfff

as it should be.

0 Kudos
Highlighted
Valued Contributor III
216 Views

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 

0 Kudos
Highlighted
Beginner
185 Views

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.

0 Kudos
Highlighted
Valued Contributor III
172 Views

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

Highlighted
Beginner
155 Views

Andrew, running your testy program with ifort I get

0000

2020

with gnu fortran I get

2020

****

 

I think my original code is a better test case.

 

 

 

0 Kudos
Highlighted
Valued Contributor III
144 Views

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.

0 Kudos
Highlighted
Valued Contributor III
99 Views

This was accepted as invalid compiler behaviour and logged as CMPLRIL0-33239

0 Kudos
Highlighted
Beginner
92 Views

Thank you for the help, Andrew.

0 Kudos