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

Off-by-one regression with deferred-length character string in structure constructor

jwmwalrus
New Contributor I
333 Views

Hi.

Although I'm still using the 2023.2.4 version of ifort (and icc), I decided to evaluate the viability of newest ifx.

After the shock of the false positives caused by "-check uninit", I noticed something that seems like a regression.

The following code

module mod1
    implicit none

contains
    subroutine parse_args(args)
        character(*), intent(inout) :: args

        integer :: i, iline, nline, ndash
        character(:), allocatable :: line

        type :: token_type
            logical :: is_flag = .false.
            character(:), allocatable :: val
        end type

        type(token_type), allocatable :: tokens(:)

        line = trim(args)//new_line('')
        tokens = [token_type ::]
        print*,'args=',line

        iline = 0
        nline = len(line)
        ndash = 0
        do while (iline < nline); iline = iline+1
            select case (line(iline:iline))
            case ('-')
                ndash = ndash+1
            case (new_line(''))
                exit
            case default
                if (ndash == 1) then
                    do i = iline, nline
                       if (line(i:i) == new_line('')) exit

                       print*,'line(i:i)=',line(i:i)
                       tokens = [tokens, token_type(.true., line(i:i))]
                    enddo
                    ndash = 0
                endif
            end select
        enddo

        do i = 1, size(tokens)
            print*,'token #', i, ', is_flag=',tokens(i)%is_flag,&
                ', val=',tokens(i)%val
        enddo
    end subroutine
end module mod1

use mod1

implicit none

character(7) :: args
args = '-0'
call parse_args(args)
end

Has the correct output when compiled with ifort 2023.2.4:

(ins)$ ifort -V main2.f90 && ./a.out 
Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel(R) 64, Version 2021.10.0 Build 20230609_000000
Copyright (C) 1985-2023 Intel Corporation.  All rights reserved.

 Intel(R) Fortran 2021.10.0-1769.02
GNU ld (GNU Binutils for Debian) 2.42
 args=-0

 line(i:i)=0
 token #           1 , is_flag= T , val=0

But with the latest ifx, the value assigned to tokens(1)%val through the structure constructor is incorrect:

$ ifx -V main2.f90 && ./a.out 
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.

 Intel(R) Fortran 24.0-1472.3
GNU ld (GNU Binutils for Debian) 2.42
 args=-0

 line(i:i)=0
 token #           1 , is_flag= T , val=-

And when trying to use the latest ifort, I get an ICE:

$ ifort -V main2.f90 && ./a.out 
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: remark #10448: Intel(R) Fortran Compiler Classic (ifort) is now deprecated and will be discontinued late 2024. Intel recommends that customers transition now to using the LLVM-based Intel(R) Fortran Compiler (ifx) for continued Windows* and Linux* support, new language support, new language features, and optimizations. Use '-diag-disable=10448' to disable this message.
 Intel(R) Fortran 2021.12.0-1472
0_1167

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 main2.f90 (code 1)

 

That's it.

 

 

 

2 Replies
Barbara_P_Intel
Employee
288 Views

Thanks for reporting these issues. I see the same thing with the latest internal build of the ifx and ifort, too. I filed a bug report, CMPLRLLVM-57421. We'll let you know when it's fixed.



0 Kudos
Barbara_P_Intel
Employee
197 Views

WOW! The Fortran compiler engineers are cranking out the bug fixes!

Look for the fix for this one in the 2024.2 release that is planned for mid-2024.



Reply