逻辑操作顺序(潜在的 ifort 错误)
Order of logical operations (potential ifort bug)
在英特尔论坛上将其报告为编译器错误之前,我想知道以下内容是否符合标准。我的问题是:逻辑运算的顺序在 Fortran 中总是固定的吗?
! main.f90
interface
subroutine f(x)
logical, intent(in), optional :: x
end subroutine f
end interface
call f(.false.)
call f(.true.)
call f()
end program
! f.f90
subroutine f(x)
logical, intent(in), optional :: x
print*, present(x) .and. x
end subroutine f
gfortran main.f90 f.f90 && ./a.out
打印
F
T
F
ifort main.f90 f.f90 && ./a.out
打印
F
T
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 0000000000476D75 Unknown Unknown Unknown
a.out 0000000000474997 Unknown Unknown Unknown
a.out 0000000000444264 Unknown Unknown Unknown
a.out 0000000000444076 Unknown Unknown Unknown
a.out 0000000000425176 Unknown Unknown Unknown
a.out 00000000004027A0 Unknown Unknown Unknown
libpthread.so.0 00007F3560702E80 Unknown Unknown Unknown
a.out 0000000000402633 Unknown Unknown Unknown
a.out 000000000040260F Unknown Unknown Unknown
a.out 00000000004025AE Unknown Unknown Unknown
libc.so.6 00007F3560371710 Unknown Unknown Unknown
a.out 00000000004024A9 Unknown Unknown Unknown
我正在使用 GCC 5.3.0 和 Ifort 16.0.2。
不,Fortran 标准不保证计算逻辑表达式的顺序。就像数学表达式一样,编译器可以自由地将它们重新排序为在 'real logic'(或 'real mathematics')的完美世界中等效但在计算机的不完美世界中不等效的顺序。
您可以执行这样的评估顺序:
if (.not. present(x)) then
print*, .false.
else
print*, x
end if
我的标准草案副本包括条款
7.1.5.4.2 Evaluation of logical intrinsic operations
Once the interpretation of a logical intrinsic operation is established, the
processor may evaluate any other expression that is logically
equivalent, provided that the integrity of parentheses in any
expression is not violated.
我对标准的解释是程序不符合标准,因为它引用了一个不存在的可选参数。请参阅第 12.5.2.12 节 3 (1) 的规定。因为 .and.
运算符的操作数的评估顺序未定义 x
可能在不存在时被引用。
在英特尔论坛上将其报告为编译器错误之前,我想知道以下内容是否符合标准。我的问题是:逻辑运算的顺序在 Fortran 中总是固定的吗?
! main.f90
interface
subroutine f(x)
logical, intent(in), optional :: x
end subroutine f
end interface
call f(.false.)
call f(.true.)
call f()
end program
! f.f90
subroutine f(x)
logical, intent(in), optional :: x
print*, present(x) .and. x
end subroutine f
gfortran main.f90 f.f90 && ./a.out
打印
F
T
F
ifort main.f90 f.f90 && ./a.out
打印
F
T
forrtl: severe (174): SIGSEGV, segmentation fault occurred
Image PC Routine Line Source
a.out 0000000000476D75 Unknown Unknown Unknown
a.out 0000000000474997 Unknown Unknown Unknown
a.out 0000000000444264 Unknown Unknown Unknown
a.out 0000000000444076 Unknown Unknown Unknown
a.out 0000000000425176 Unknown Unknown Unknown
a.out 00000000004027A0 Unknown Unknown Unknown
libpthread.so.0 00007F3560702E80 Unknown Unknown Unknown
a.out 0000000000402633 Unknown Unknown Unknown
a.out 000000000040260F Unknown Unknown Unknown
a.out 00000000004025AE Unknown Unknown Unknown
libc.so.6 00007F3560371710 Unknown Unknown Unknown
a.out 00000000004024A9 Unknown Unknown Unknown
我正在使用 GCC 5.3.0 和 Ifort 16.0.2。
不,Fortran 标准不保证计算逻辑表达式的顺序。就像数学表达式一样,编译器可以自由地将它们重新排序为在 'real logic'(或 'real mathematics')的完美世界中等效但在计算机的不完美世界中不等效的顺序。
您可以执行这样的评估顺序:
if (.not. present(x)) then
print*, .false.
else
print*, x
end if
我的标准草案副本包括条款
7.1.5.4.2 Evaluation of logical intrinsic operations
Once the interpretation of a logical intrinsic operation is established, the processor may evaluate any other expression that is logically equivalent, provided that the integrity of parentheses in any expression is not violated.
我对标准的解释是程序不符合标准,因为它引用了一个不存在的可选参数。请参阅第 12.5.2.12 节 3 (1) 的规定。因为 .and.
运算符的操作数的评估顺序未定义 x
可能在不存在时被引用。