Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
Announcements
FPGA community forums and blogs have moved to the Altera Community. Existing Intel Community members can sign in with their current credentials.
29304 Discussions

ICE due to use of intrinsic keyword, generic subroutine, passing optional argument to WAIT, or...?

jwmwalrus
New Contributor I
1,280 Views

Hi.

The following code

module mod1
    use ISO_FORTRAN_ENV

    implicit none

    generic, public :: load_file_as_stream => load_file_as_stream_char

    generic, public :: split_string => split_string_char

    generic, public :: redirect_command_line => &
        redirect_command_line_string, &
        redirect_command_line_array

contains
    subroutine redirect_command_line_string(command, output, DISCARD_STDERR, WAIT, EXITSTAT, CMDSTAT, CMDMSG)
        use IFPORT, only: UNLINK

        character(*), intent(in) :: command
        character(:), allocatable, intent(out) :: output
        logical, optional, intent(in) :: DISCARD_STDERR
        logical, optional, intent(in) :: WAIT
        integer, optional, intent(out) :: EXITSTAT
        integer, optional, intent(out) :: CMDSTAT
        character(*), optional, intent(out) :: CMDMSG

        logical :: discard_stderr_
        integer :: stat
        character(:), allocatable :: redirect_to, fileout
        character(256) :: err

        redirect_to = '/tmp/redirect-command-line-2525'
        fileout = redirect_to

        discard_stderr_ = .false.
        if (PRESENT(DISCARD_STDERR)) discard_stderr_ = DISCARD_STDERR

        if (discard_stderr_) then
            redirect_to = ' 2>/dev/null | cat >> '//redirect_to
        else
            redirect_to = ' >> '//redirect_to
        endif

        call EXECUTE_COMMAND_LINE(command//redirect_to, &
                                 WAIT = WAIT, &
                                 EXITSTAT = EXITSTAT, &
                                 CMDSTAT = CMDSTAT, &
                                 CMDMSG = CMDMSG)

        err = ''
        call load_file_as_stream(fileout, output, ERROR = err)
        if (err == '') stat = UNLINK(fileout)
    end subroutine

    subroutine redirect_command_line_array(command, output, DELIM, DISCARD_STDERR, WAIT, EXITSTAT, CMDSTAT, CMDMSG)
        character(*), intent(IN) :: command
        character(*), allocatable, intent(out) :: output(:)
        character(*), optional, intent(in) :: DELIM
        logical, optional, intent(in) :: DISCARD_STDERR
        logical, optional, intent(in) :: WAIT
        integer, optional, intent(out) :: EXITSTAT
        integer, optional, intent(out) :: CMDSTAT
        character(*), optional, intent(out) :: CMDMSG

        character(:), allocatable :: text, delim_

        delim_ = NEW_LINE('')
        if (PRESENT(DELIM)) then
            if (DELIM /= '') delim_ = DELIM
        endif

        call redirect_command_line(command, text, &
                                 DISCARD_STDERR = DISCARD_STDERR, &
                                 WAIT = WAIT, &
                                 EXITSTAT = EXITSTAT, &
                                 CMDSTAT = CMDSTAT, &
                                 CMDMSG = CMDMSG)

        call split_string(text, delim_, output)
    end subroutine

    subroutine load_file_as_stream_char(path, stream, ERROR)
        character(*), intent(in) :: path
        character(:), allocatable, intent(out) :: stream
        character(*), optional, intent(inout) :: ERROR
    end subroutine

    pure subroutine split_string_char(string, delimiter, array)
        character(*), intent(in) :: string
        character(*), intent(in) :: delimiter
        character(*), allocatable, intent(out) :: array(:)
    end subroutine
end module mod1

causes an ICE when compiled (on Debian 12) with the latest version of ifx:

(ins)$ ifx -V -c mod1.f90 
Intel(R) Fortran Compiler for applications running on Intel(R) 64, Version 2024.0.2 Build 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

 Intel(R) Fortran 24.0-1238.2
          #0 0x000000000232d4ea
          #1 0x0000000002394d07
          #2 0x0000000002394cd6
          #3 0x0000000002299f76
          #4 0x000000000229bed4
          #5 0x00000000023275e6
          #6 0x0000000002321576
          #7 0x00000000023241bb
          #8 0x000000000239971c
          #9 0x0000000002399fca
         #10 0x00000000023e3215
         #11 0x00000000023e37f5
         #12 0x00000000023e5f6d
         #13 0x00000000023e3215
         #14 0x00000000023e37f5
         #15 0x00000000023e0f02
         #16 0x00000000023e3215
         #17 0x00000000023e05ba
         #18 0x00000000023e3215
         #19 0x00000000022703e6
         #20 0x000000000226fd9e
         #21 0x0000000002452dbe
         #22 0x00007f27cf7426ca
         #23 0x00007f27cf742785 __libc_start_main + 133
         #24 0x00000000020ab129

mod1.f90(44): error #5623: **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.
                                 WAIT = WAIT, &
----------------------------------------^
compilation aborted for mod1.f90 (code 3)

Since I'm not really sure what's going on here (see the post's subject), the only workaround is to use the 2023.2.3-20 version on the same machine (so libc is not the issue).

Labels (1)
0 Kudos
4 Replies
TobiasK
Moderator
1,252 Views

@jwmwalrus

 

Thanks for reporting that, I will forward it to the developers to get rid of the ICE.

However, I have to admit, I have to check the standard about passing optional variables to other functions.

 

a quick workaround:

 

 

    wait_=.true.
    if(present(wait))wait_=wait
    call EXECUTE_COMMAND_LINE(command//redirect_to, &
                 WAIT = WAIT_, &
                 EXITSTAT = EXITSTAT, &
                 CMDSTAT = CMDSTAT, &
                 CMDMSG = CMDMSG)

 

 

 

0 Kudos
jwmwalrus
New Contributor I
1,231 Views

Hi @TobiasK . Thanks for the response.

 

AFAIK, there's no issue in passing optionals to optionals ---otherwise, I've been using it wrong for the past 25+ years, hehehe.

In the case of EXECUTE_COMMAND_LINE, the only non-optional argument is the first one. And, as you showed with the workaround, only the WAIT argument causes the ICE ---hence my doubts as to whether the ICE was caused by the keyword itself, since it's also used as an asynchronous statement. 

0 Kudos
TobiasK
Moderator
1,217 Views

yes you are right, as long as the optional argument is never passed to an non-optional argument it is fine. The bug report is with the developers already.

By the way, I changed the workaround to wait_=.true. since that is the default behavior....

0 Kudos
TobiasK
Moderator
949 Views

@jwmwalrus

good news, we have implemented a fix and it will be included in a future release, most likely oneAPI 2024.2


Best

Tobais


0 Kudos
Reply