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

Compiler bug: value attribute not working

Lionel_Guez
Beginner
446 Views

Hello. Here is a test execution:

$ ifort --version
ifort (IFORT) 2021.9.0 20230302
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ cat test_value_attribute.f90
module func_value_attr_m
implicit none
type polyline
integer n_points
logical closed
real, allocatable:: points(:,
end type polyline
contains
logical function func_value_attr(p)
type(polyline), value:: p
p%points(:, 3) = [1., 2.]
func_value_attr = sum(p%points) >= 0.
end function func_value_attr
end module func_value_attr_m
program test_value_attribute
use func_value_attr_m, only: polyline, func_value_attr
implicit none
type(polyline) p
real points(2, 3)
points = 0.
p = polyline(n_points = 3, closed = .false., points = points)
print *, func_value_attr(p)
print *, "p%points = ", p%points
end program test_value_attribute

$ ifort test_value_attribute.f90

$ a.out
T
p%points = 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00
1.000000 2.000000

This is a compiler bug. The variable "p" should not be modified by the call to the function, since the dummy argument has the value attribute.

 

Would you correct this bug?

0 Kudos
1 Solution
jdelia
New Contributor I
401 Views

Hi Lionel_Guez :

Try with

$ ifx --version
ifx (IFX) 2024.0.2 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ ifx -error-limit 4 -e03 -fimf-arch-consistency=true -fimf-precision=high -finline-functions -fpp -ipo -mtune=generic -m64 -mavx -parallel-source-info=1 -qopenmp -qmkl -xHost -O2 -qopt-report=3 -parallel-source-info -std18 -fp-model consistent -WB -warn all -o testcase-0195-ifx.exe testcase-0195.f90 # (your source code)

$ $ testcase-0195-ifx.exe
T
p%points = 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00
0.0000000E+00 0.0000000E+00

Regards.

Jorge D'Elia

View solution in original post

5 Replies
Arjen_Markus
Honored Contributor I
437 Views

You misunderstand the purpose of the value attribute: it does not protect against local changes of an argument. Instead it protect against the actual argument being changed, while you still can change it in a subprogram. If you want to ensure that the dummy argument cannot be changed, use the intent(in) attribute.

The "value" attribute is also useful if you interface with C: rather than passing by reference, it allows you to pass an argument by value.

0 Kudos
Lionel_Guez
Beginner
435 Views

Thank you for your answer. I am sorry but I think you are wrong. Here is a quote from the  Fortran 2003 standard, § 12.4.1.2:

 

"If the dummy argument has the VALUE attribute it becomes associated with a definable anonymous data object whose initial value is that of the actual argument. Subsequent changes to the value or definition status of the dummy argument do not affect the actual argument."

 

Applied to my test program, the above specification says that a change to the value of the dummy argument "p" shall not affect the variable "p" in the main program.

0 Kudos
Arjen_Markus
Honored Contributor I
426 Views

Oh, I misread your message. The actual argument is changed, where that should not happen. Hm.

0 Kudos
jdelia
New Contributor I
402 Views

Hi Lionel_Guez :

Try with

$ ifx --version
ifx (IFX) 2024.0.2 20231213
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ ifx -error-limit 4 -e03 -fimf-arch-consistency=true -fimf-precision=high -finline-functions -fpp -ipo -mtune=generic -m64 -mavx -parallel-source-info=1 -qopenmp -qmkl -xHost -O2 -qopt-report=3 -parallel-source-info -std18 -fp-model consistent -WB -warn all -o testcase-0195-ifx.exe testcase-0195.f90 # (your source code)

$ $ testcase-0195-ifx.exe
T
p%points = 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00
0.0000000E+00 0.0000000E+00

Regards.

Jorge D'Elia

Lionel_Guez
Beginner
383 Views

Thanks. The most recent version I have access to is:

$ ifx --version
ifx (IFX) 2023.1.0 20230320
Copyright (C) 1985-2023 Intel Corporation. All rights reserved.

$ ifx test_value_attribute.f90

$ a.out
T
p%points = 0.0000000E+00 0.0000000E+00 0.0000000E+00 0.0000000E+00
1.000000 2.000000

So the bug has been fixed somewhere between versions 2023.1.0 and 2024.0.2. That is good to know. Thanks again.

0 Kudos
Reply