[Cython] GCC 4.6 unused-but-set-variable warnings

Vitja Makarov vitja.makarov at gmail.com
Fri Jul 29 08:34:35 CEST 2011


2011/7/29 Stefan Behnel <stefan_ml at behnel.de>:
> [moving this here from cython-users]
>
> Nikolaus Rath, 13.06.2011 16:59:
>>
>> Stefan Behnel writes:
>>>
>>> Nikolaus Rath, 13.06.2011 01:18:
>>>>
>>>> Stefan Behnel writes:
>>>>>
>>>>> Nikolaus Rath, 03.06.2011 23:24:
>>>>>>
>>>>>> Cython 0.14 generated code triggers lots of  unused-but-set-variable
>>>>>> warnings (which are new in GCC 4.6).
>>>>>
>>>>> Hmm, that's annoying. We actually generate a lot of useless "dangling
>>>>> reset to 0" statements for safety (and also as a bit of a "now unused"
>>>>> hint to the C compiler).
>>>>>
>>>>> We could get rid of most of them based on control flow analysis, but I
>>>>> actually like having them there, just in case we accidentally generate
>>>>> broken code at some point. A NULL pointer is a lot safer than an
>>>>> arbitrarily dangling address, especially when it comes to CPython heap
>>>>> allocated memory (which doesn't necessarily get freed, so you may not
>>>>> get a quick segfault but a read from dead memory).
>>>>
>>>> I don't quite understand. The way to get rid of the warnings is to
>>>> remove the unnecessary variables. How can this result in a dangling
>>>> address? You'll get a syntax error from gcc about using an undeclared
>>>> variable.
>>>
>>> Ah, sorry. I misunderstood the meaning of the warning message as
>>> pointing at unnecessary assignments in general. Could you post a C
>>> code snippet (and the corresponding Cython code) that triggers this? I
>>> don't have gcc 4.6 available for testing.
>>
>> Sure. It's apparently triggered by unused function arguments:
>>
>> $ cat test.pyx
>> class Operations(object):
>>     def handle_exc(self, fn, exc):
>>         pass
>>
>> $ cython test.pyx
>>
>> $ gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall
>> -Wstrict-prototypes -fPIC -I/usr/include/python2.6 -c test.c -o test.o
>> -D_FILE_OFFSET_BITS=64 -I/usr/include/fuse -Werror -Wall -Wextra
>> -Wconversion -Wno-unused-parameter -Wno-sign-conversion -fno-strict-aliasing
>> test.c:
>> test.c:454:13: warning: variable ‘__pyx_v_exc’ set but not used
>> [-Wunused-but-set-variable]
>> test.c:453:13: warning: variable ‘__pyx_v_fn’ set but not used
>> [-Wunused-but-set-variable]
>> test.c:452:13: warning: variable ‘__pyx_v_self’ set but not used
>> [-Wunused-but-set-variable]
>
> http://trac.cython.org/cython_trac/ticket/704
>
> I think this is something that the control flow analysis could deal with.
> Basically, every parameter that turns out to be unused in the function (and
> this most likely only happens with parameters) could be ignored, unless it
> requires a type conversion with potential side effects. In that (unlikely)
> case, we could still drop the final assignment to the variable itself.
>

There is entry.cf_unused flag it's set when the whole entry is not used.

-- 
vitja.


More information about the cython-devel mailing list