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

Generator Function with Yield in condition causes maybe-uninitialized warning with GCC #3430

WillAyd opened this issue Mar 14, 2020 · 1 comment · Fixed by #3517 or #3522


Copy link

WillAyd commented Mar 14, 2020

Here is a sample function in question:

def first_or_last(int[:] values, bint first):
    cdef Py_ssize_t i

    if first:
        i = -1
        yield values[i]
        i = 0
        yield values[i]

In both cases, i should always be initialized when used, but gcc emits something along the lines of

hello.c: In function ‘__pyx_gb_5hello_2generator’:
hello.c:2326:32: warning: ‘__pyx_t_2’ may be used uninitialized in this function [-Wmaybe-uninitialized]
     __pyx_cur_scope->__pyx_t_0 = __pyx_t_2;

Moving the yields outside of the branches works fine, but this is a problem showing up in a larger function where I don't know that that is possible

I've attached the generated code. I think this is an issue where the generator saving the state of the function but not entirely sure

Copy link

scoder commented Apr 14, 2020

The warning seems correct: that temp variable is only used in the first branch and not in the second. There is no reason why it would need to get stored away in the closure there.

It could be that some state from the first branch leaks into the second during the code generation phase, e.g. an unreleased temp variable. Needs some more debugging there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
2 participants