Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

spurious failure of parse_header in load_npy due to no value assigned to an intent(out) argument. #706

Closed
degawa opened this issue Apr 23, 2023 · 0 comments · Fixed by #708
Assignees
Labels
bug Something isn't working

Comments

@degawa
Copy link
Contributor

degawa commented Apr 23, 2023

Description

An example of stdlib_io, example_loadnpy, terminated with an error when built using NAG Fortran with the release profile.

>fpm run --compiler nagfor --profile release --example example_loadnpy
Project is up to date
 Failed to read array from file 'example.npy'
ERROR STOP

Expected Behaviour

I expected the example to run and finish as successfully as it did under the following configurations:

  • gfortran with the debug and release profiles
  • Intel Fortran with the debug and release profiles
  • NAG Fortran with the debug profile
>fpm run --compiler gfortran --profile debug --example example_loadnpy   
Project is up to date

>fpm run --compiler gfortran --profile release --example example_loadnpy
Project is up to date

>fpm run --compiler ifort --profile debug --example example_loadnpy
Project is up to date

>fpm run --compiler ifort --profile release --example example_loadnpy 
Project is up to date

>fpm run --compiler nagfor --profile debug --example example_loadnpy
Project is up to date

Version of stdlib

31f5a8b

Platform and Architecture

Windows 10 22H2 64bit, gfortran 11.2 bundled with quickstart Fortran on Windows, Intel Fortran 2021.5.0, NAG Fortran 7.1 Build 7117, fpm 0.7.0 alpha

Additional Information

I print-debugged to determine the cause of this error, and I found that parse_header called in get_descriptor is considered a failure because stat is 1.
No error occurred in parse_header; stat is always 0. However, stat becomes 1 when returned to get_descriptor.
Several print statements reveal this strange behavior.

  • in get_descriptor
        print *,"before calling perse_header", stat
        call parse_header(header, major, stat, msg)
        print *,"after calling perse_header",stat
        if (stat /= 0) return
  • in parse_header
        integer :: minor

        print *,"at the top of perse_header", stat
...

        print *,"at the end of perse_header", stat
    end subroutine parse_header
>fpm run --compiler nagfor --profile debug --example example_loadnpy
Project is up to date
 before calling perse_header 0
 at the top of perse_header 0
 at the end of perse_header 0
 after calling perse_header 0

>fpm run --compiler nagfor --profile release --example example_loadnpy 
Project is up to date
 before calling perse_header 0
 at the top of perse_header 0
 at the end of perse_header 0
 after calling perse_header 1
 Failed to read array from file 'example.npy'
ERROR STOP

In parse_header, stat is not assigned any value if no error occurs. stat having the intent(out) attribute may become undefined according to the Fortran standard:

The INTENT (OUT) attribute for a nonpointer dummy argument specifies that the dummy argument becomes undefined on invocation of the procedure, except for any subcomponents that are default-initialized (7.5.4.6).

I cannot say whether this behavior is a NAG Fortran's bug, but adding a statement stat = 0 to specify that no error occurred in parse_header avoids this spurious failure.

+        stat = 0
    end subroutine parse_header
@degawa degawa added the bug Something isn't working label Apr 23, 2023
14NGiestas added a commit that referenced this issue May 4, 2023
Co-authored-by: degawa <degawa.tomohiro@gmail.com>
@14NGiestas 14NGiestas self-assigned this May 4, 2023
@jvdp1 jvdp1 closed this as completed in #708 May 5, 2023
jvdp1 added a commit that referenced this issue May 5, 2023
Fixes #706 - failure due unassigned value to a intent(out) variable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants