fortran66のブログ

fortran について書きます。

【メモ帳】ifort bug; call by value 引数に定数式を入れると即死

call by value で定義した dummy argument

ifort で call by value で定義した仮引数に、実引数として定数式を与えて書き換えようとすると、segmentation fault が出て死にます。たんなる定数なら問題ないですし、変数のからんだ式でも大丈夫です。

やっぱり、引数は call by reference に限るw

なお次世代 llvm 版の ifx の release 版なら大丈夫。debug だと駄目。

lfortran を調べるつもりが ifort で死亡。

最小実行例

program bug
    implicit none
    print *, f(2)
    print *, f(2*2)
contains
    integer function f(n)
        integer, value :: n
        f = n
        n = 1
    end function f
end

ifort

(lf) hp8@HP8:~$ ifort --version
ifort (IFORT) 2021.1 Beta 20200827
Copyright (C) 1985-2020 Intel Corporation.  All rights reserved.

(lf) hp8@HP8:~$ ifort -traceback bug.f90
(lf) hp8@HP8:~$ ./a.out
           2
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source
a.out              0000000000403A1A  Unknown               Unknown  Unknown
libpthread-2.27.s  00007F57C7313980  Unknown               Unknown  Unknown
a.out              0000000000402B65  MAIN__                      4  bug.f90
a.out              0000000000402AC2  Unknown               Unknown  Unknown
libc-2.27.so       00007F57C6D2DBF7  __libc_start_main     Unknown  Unknown
a.out              00000000004029AA  Unknown               Unknown  Unknown

ifx

(lf) hp8@HP8:~$ ifx --version
ifx (IFORT) 2021.1 Beta 20200827
Copyright (C) 1985-2020 Intel Corporation. All rights reserved.

(lf) hp8@HP8:~$ ifx bug.f90
(lf) hp8@HP8:~$ ./a.out
           2
           4

(lf) hp8@HP8:~$ ifx -g bug.f90
(lf) hp8@HP8:~$ ./a.out
           2
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image              PC                Routine            Line        Source
a.out              0000000000404B8A  Unknown               Unknown  Unknown
libpthread-2.27.s  00007FDD507D7980  Unknown               Unknown  Unknown
a.out              0000000000403CEA  Unknown               Unknown  Unknown
a.out              0000000000403C66  Unknown               Unknown  Unknown
a.out              0000000000403B82  Unknown               Unknown  Unknown
libc-2.27.so       00007FDD503F5BF7  __libc_start_main     Unknown  Unknown
a.out              0000000000403A6A  Unknown               Unknown  Unknown

lfortran

(lf) hp8@HP8:~$ lfortran --version
LFortran version: 0.14.0
Platform: Linux
Default target: x86_64-unknown-linux-gnu
(lf) hp8@HP8:~$ lfortran bug.f90
(lf) hp8@HP8:~$ ./a.out
2
4

gfortran

hp8@HP8:~$ gfortran-11 --version
GNU Fortran (Ubuntu 11.1.0-1ubuntu1~20.04) 11.1.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

hp8@HP8:~$ gfortran-11 bug.f90
hp8@HP8:~$ ./a.out
           2
           4

flang

hp8@HP8:~$ flang --version
flang version 13.0.0
hp8@HP8:~$ flang bug.f90
hp8@HP8:~$ ./a.out
           2
           4


www.youtube.com