classification
Title: gcc 4.7 unused-but-set warnings on Python/thread_pthread.h
Type: compile error Stage: resolved
Components: Build Versions: Python 3.4, Python 3.2, Python 3.3, Python 2.7
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: jcea Nosy List: bruno.dupuis, christian.heimes, jcea, python-dev
Priority: normal Keywords: easy, patch

Created on 2012-12-01 02:41 by bruno.dupuis, last changed 2012-12-05 13:42 by python-dev. This issue is now closed.

Files
File name Uploaded Description Edit
z.diff jcea, 2012-12-01 05:09 review
z2.diff jcea, 2012-12-01 05:15 review
Messages (7)
msg176737 - (view) Author: Bruno Dupuis (bruno.dupuis) Date: 2012-12-01 02:41
Looks like #10951, but for another version of gcc.

I get these warnings:

 In file included from Python/thread.c:86:0:
 Python/thread_pthread.h: In function ‘PyThread_free_lock’:
 Python/thread_pthread.h:304:17: attention : variable ‘error’ set but not used [-Wunused-but-set-variable]
 Python/thread_pthread.h: In function ‘PyThread_acquire_lock_timed’:
 Python/thread_pthread.h:335:17: attention : variable ‘error’ set but not used [-Wunused-but-set-variable]
 Python/thread_pthread.h: In function ‘PyThread_release_lock’:
 Python/thread_pthread.h:386:17: attention : variable ‘error’ set but not used [-Wunused-but-set-variable]

I tried to remove the variables, but the build crash as they are used in

 #define CHECK_STATUS(name)  if (status != 0) { perror(name); error = 1; }

looks like a gcc 4.7.2 bug.
msg176738 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-12-01 05:08
The warning is legitimate. "error" is set to 0 at the beginning and it will be set to 1 if an error occurred (via CHECK_STATUS macro). But the variable "error" is never used in the function. So it is set, but never actually used in the function.

The obvious thing to do is to use the variable. For instance, with an "if (error) {}" do nothing construction.

Please, review the patch. I will commit it if another core developer thinks it is ok.

Python 2.7, 3.2, 3.3 and 3.4 affected.

It you think there is a better way of handling this, let me know.

PS: With the default compilation parameters (-O3), that empty "if" is optimized out, as it should.
msg176739 - (view) Author: Jesús Cea Avión (jcea) * (Python committer) Date: 2012-12-01 05:15
Another patch proposal, not sure about which is cleaner.
msg176740 - (view) Author: Bruno Dupuis (bruno.dupuis) Date: 2012-12-01 10:14
I don't agree. Trash build logs are bad, trash code (I mean, in terms of utility, not quality :-) ) is far worst IMHO.

The purpose of this bug, to me, is to try to find a neat way to suppress the warnings without touching the code, and if we can't, wich is probable, we just tell the world : "Yeah, we know this bug, it's not ours and it has no inpact".

Anyway, I do not know the official policy for this kind of problem, but I really think we should avoid adding dead code as a workaround for every bug of every supported version of each supported compiler.
msg176774 - (view) Author: Roundup Robot (python-dev) Date: 2012-12-02 07:39
New changeset 280469ce6669 by Christian Heimes in branch '3.2':
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
http://hg.python.org/cpython/rev/280469ce6669

New changeset 470785a9fdd5 by Christian Heimes in branch '3.3':
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
http://hg.python.org/cpython/rev/470785a9fdd5

New changeset 33b070ef0bad by Christian Heimes in branch 'default':
Issue #16588: Silence unused-but-set warnings in Python/thread_pthread.h
http://hg.python.org/cpython/rev/33b070ef0bad
msg176775 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2012-12-02 07:45
Jesús, I've used a slightly different comment in my patch.

Python 3.3 and 3.4 now compile the core and modules without any warnings. 3.2 still has some warnings.
msg176982 - (view) Author: Roundup Robot (python-dev) Date: 2012-12-05 13:42
New changeset 0adfbafe8a99 by Jesus Cea in branch '2.7':
Closes #16588: Silence unused-but-set warnings in Python/thread_pthread.h
http://hg.python.org/cpython/rev/0adfbafe8a99
History
Date User Action Args
2012-12-05 13:42:18python-devsetmessages: + msg176982
2012-12-05 13:40:29jceasetstatus: open -> closed
type: compile error
resolution: fixed
stage: patch review -> resolved
2012-12-05 13:39:38jceasetstatus: closed -> open
type: compile error -> (no value)
stage: resolved -> patch review
resolution: fixed -> (no value)
versions: + Python 2.7
2012-12-02 07:45:15christian.heimessetstatus: open -> closed

type: compile error
versions: + Python 3.2, Python 3.4
nosy: + christian.heimes

messages: + msg176775
resolution: fixed
stage: patch review -> resolved
2012-12-02 07:39:43python-devsetnosy: + python-dev
messages: + msg176774
2012-12-01 10:14:02bruno.dupuissetmessages: + msg176740
versions: - Python 2.7, Python 3.2, Python 3.4
2012-12-01 05:15:42jceasetmessages: + msg176739
2012-12-01 05:15:02jceasetfiles: + z2.diff
2012-12-01 05:10:25jceasettitle: gcc 4.7 ilegitimate unused-but-set warnings on Python/thread_pthread.h -> gcc 4.7 unused-but-set warnings on Python/thread_pthread.h
2012-12-01 05:09:42jceasetfiles: + z.diff
keywords: + patch
2012-12-01 05:08:33jceasetassignee: jcea
versions: + Python 2.7, Python 3.2, Python 3.4
keywords: + easy
nosy: + jcea

messages: + msg176738
stage: patch review
2012-12-01 02:41:38bruno.dupuiscreate