Skip to content

Bug fix: Allocatable argument 'x' is not allocated #472 #474

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

Merged
merged 7 commits into from
Jul 25, 2021

Conversation

14NGiestas
Copy link
Member

There is a unreliable behaviour when dealing with negative size at runtime in GCC 11, this bug fix is addressing this issue.

program main
    implicit none
    real, allocatable :: x(:)

    x = compile_time()
    print*, allocated(x) ! T
    print*, size(x)      ! 0

    x = runtime(100)
    print*, allocated(x) ! T
    print*, size(x)      ! 100

    x = runtime(-100)
    print*, allocated(x) ! F -> this is a problem!
    print*, size(x)      ! 0

    x = runtime(0)
    print*, allocated(x) ! T
    print*, size(x)      ! 0

    x = fix_runtime(-100)
    print*, allocated(x) ! T
    print*, size(x)      ! 0

contains

    function compile_time() result(res)
        real :: res(-100)
    end function

    function runtime(n) result(res)
        integer, intent(in) :: n
        real :: res(n)
    end function

    function fix_runtime(n) result(res)
        integer, intent(in) :: n
        real :: res(merge(n, 0, n > 0))
    end function

end program

Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. The declaration should be also changed in stdlib_math.fypp.

@14NGiestas
Copy link
Member Author

I believe I should guard the logspace as well, to avoid any further trouble.

@14NGiestas 14NGiestas requested a review from jvdp1 July 23, 2021 15:32
Copy link
Member

@jvdp1 jvdp1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for these changes.

@jvdp1 jvdp1 requested review from ejovo13 and awvwgk July 23, 2021 16:08
Copy link
Contributor

@ejovo13 ejovo13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Elegant solution. Thank you for reporting this and working to clean it up so quickly. I also appreciate the fact that through this bug's discussion I have learned about the intrinsic function merge and its use cases compared to the stdlib optval.

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Thank you for the fix.

Copy link
Member

@awvwgk awvwgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for sharing. Looks good to me.

@14NGiestas
Copy link
Member Author

Maybe this two should also be guarded.

@jvdp1
Copy link
Member

jvdp1 commented Jul 25, 2021

Thank you @14NGiestas for this bug fix. I'll merge it.

Fixes #472

@jvdp1 jvdp1 merged commit ce3a106 into fortran-lang:master Jul 25, 2021
@14NGiestas 14NGiestas deleted the patch-3 branch July 25, 2021 18:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants