Bug 626329 - nested pthread_cleanup_push() does not work with -Wshadow -Werror
nested pthread_cleanup_push() does not work with -Wshadow -Werror
Status: CLOSED WONTFIX
Product: Fedora
Classification: Fedora
Component: gcc (Show other bugs)
17
All Linux
low Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Fedora Extras Quality Assurance
: Reopened
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2010-08-23 04:18 EDT by Stas Sergeev
Modified: 2013-08-01 14:25 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2013-08-01 14:24:59 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Stas Sergeev 2010-08-23 04:18:48 EDT
Description of problem:
I am using -Wshadow when compiling my progs,
as this looks like a usefull diagnostic to me.
I think glibc have to be friendly to -Wshadow -Werror.
The following program won't compile though:
---
#include <pthread.h>

static void foo(void *arg)
{
}

int main()
{
    pthread_cleanup_push(foo, NULL);
    {
	pthread_cleanup_push(foo, NULL);
	pthread_cleanup_pop(1);
    }
    pthread_cleanup_pop(1);
    return 0;
}
---

cc1: warnings being treated as errors
pthcln.c: In function 'main':
pthcln.c:11: error: declaration of '__cancel_buf' shadows a previous local
pthcln.c:9: error: shadowed declaration is here
pthcln.c:11: error: declaration of '__cancel_routine' shadows a previous local
pthcln.c:9: error: shadowed declaration is here
pthcln.c:11: error: declaration of '__cancel_arg' shadows a previous local
pthcln.c:9: error: shadowed declaration is here
pthcln.c:11: error: declaration of 'not_first_call' shadows a previous local
pthcln.c:9: error: shadowed declaration is here

Version-Release number of selected component (if applicable):


How reproducible:
glibc-2.12-3.x86_64

Steps to Reproduce:
1. Compile the above test-case with -Wshadow -Werror
  
Actual results:
Does not compile

Expected results:
Does compile

Additional info:
Comment 1 Andreas Schwab 2010-09-21 10:15:37 EDT
That cannot be fixed without compiler support, perhaps through a declaration attribute to suppress the warning.
Comment 2 Stas Sergeev 2010-09-21 10:23:20 EDT
I think an attribute is a perfectly sane solution.
Is there one already, or should be implemented in gcc?
Or maybe pragma?
I am asking because I have the same problem with an own macros.
Comment 3 Jakub Jelinek 2010-09-21 10:28:26 EDT
Usually __COUNTER__ macro can be used for that kind of things, if you suffix your local vars with a macro argument and pass __COUNTER__ to that argument from a wrapper macro.  Unfortunately, for pthread_cleanup_push/pop that doesn't work too well, because pthread_cleanup_pop is a separate macro and needs to access corresponding pthread_cleanup_push variables.
Comment 4 Jakub Jelinek 2010-09-21 10:39:32 EDT
GCC 4.6 also has _Pragma ("GCC diagnostic {push,pop,ignored \"-Wshadow\"}"),
unfortunately as this is a macro expansion it doesn't work well unless glibc disabled all -Wshadow warnings in between pthread_cleanup_push and pthread_cleanup_pop:

#define A \
  {							\
    _Pragma ("GCC diagnostic push");			\
    _Pragma ("GCC diagnostic ignored \"-Wshadow\"");	\
    int var = 6;
#define B \
    var++; _Pragma ("GCC diagnostic pop"); }

void foo (void)
{
  A;
    A;
    B;
  B;
}
Comment 5 Stas Sergeev 2010-09-21 10:55:01 EDT
Many thanks!

Maybe a naive question, but what if I redefine
the macros in your example in the following way:

---
#define A \
  {       \
    _Pragma ("GCC diagnostic push");   \
    _Pragma ("GCC diagnostic ignored \"-Wshadow\""); \
    int var = 6; \
    _Pragma ("GCC diagnostic pop");

#define B \
    var++;
---

Will there still be a problem then?
Comment 6 Jakub Jelinek 2010-09-21 11:05:52 EDT
Yes, that won't work, because GCC currently (AFAIK Dodji Seketeli is working on it, but it won't work for -save-temps/ccache etc. anyway) doesn't preserve macro expansion locations.  So, all tokens from the macro A expansion get the same location (the location where in the source the macro is used).  As GCC diagnostic macro works by setting up a range of locations for which the warning is ignored/errored on/warned etc., if ignored and pop have the same location, it means -Wshadow will still complain.
Comment 7 Stas Sergeev 2010-09-21 14:34:49 EDT
How about treating the "ignore and
pop on the same location" as "ignore
till the next line"? Or is it too much of
a hack? Just an idea. Maybe a bad one. :)
Comment 8 Stas Sergeev 2010-09-22 06:34:07 EDT
Hi Jakub.

Sorry for bothering you with an obviously
support questions, but I am trying what you
have suggested, and the following doesn't
work:

---
#define M(i) i ## __COUNTER__

int main()
{
    int M(i), M(i);
    return 0;
}
---
counter.c:5: error: redeclaration of 'i__COUNTER__' with no linkage
counter.c:5: note: previous declaration of 'i__COUNTER__' was here
counter.c:5: warning: unused variable 'i__COUNTER__'

Could you please hint me at what am I missing here?
Comment 9 Jakub Jelinek 2010-09-22 06:49:27 EDT
#define M_2(i, cntr) i##cntr
#define M_1(i, cntr) M_2(i, cntr)
#define M(i) M_1(i, __COUNTER__)

int main()
{
  int M(i), M(i);
  return 0;
}
Comment 10 Stas Sergeev 2010-09-22 07:29:13 EDT
Thank you!
Comment 11 Bug Zapper 2011-06-01 06:46:04 EDT
This message is a reminder that Fedora 13 is nearing its end of life.
Approximately 30 (thirty) days from now Fedora will stop maintaining
and issuing updates for Fedora 13.  It is Fedora's policy to close all
bug reports from releases that are no longer maintained.  At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '13'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 13's end of life.

Bug Reporter: Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 13 is end of life.  If you 
would still like to see this bug fixed and are able to reproduce it 
against a later version of Fedora please change the 'version' of this 
bug to the applicable version.  If you are unable to change the version, 
please add a comment here and someone will do it for you.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events.  Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.

The process we are following is described here: 
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 12 Aravind vijayan 2011-11-08 10:04:07 EST
Thank you for the bug report,i think your problem was revolved let me close this bug.



-- 
Fedora Bugzappers volunteer triage team
https://fedoraproject.org/wiki/BugZappers
Comment 13 Stas Sergeev 2011-11-08 10:37:40 EST
How?
In what version of <what> is this fixed?
I don't have a fedora-16 here to check but I am
pretty sure it is not fixed as of yet, so any proof?
Comment 14 Stas Sergeev 2011-11-08 12:00:00 EST
Lets get this open until the fix is confirmed.
I don't think this could have silently fix itself.
Comment 15 Aravind vijayan 2011-11-08 23:01:37 EST
(In reply to comment #12)
> Thank you for the bug report,i think your problem was revolved let me close
> this bug.
> 
> 
> 
> -- 
> Fedora Bugzappers volunteer triage team
> https://fedoraproject.org/wiki/BugZappers

Sorry for the careless activity, while loitering through bugs, when i saw that:

(In reply to comment #10)
> Thank you!

I do not  even pay a  time slice to go through the data and just closed the bug i am thankful to you for your valuable replay..

 "Lets get this open until the fix is confirmed."
Comment 16 Fedora End Of Life 2012-08-07 16:13:00 EDT
This message is a notice that Fedora 15 is now at end of life. Fedora
has stopped maintaining and issuing updates for Fedora 15. It is
Fedora's policy to close all bug reports from releases that are no
longer maintained. At this time, all open bugs with a Fedora 'version'
of '15' have been closed as WONTFIX.

(Please note: Our normal process is to give advanced warning of this
occurring, but we forgot to do that. A thousand apologies.)

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, feel free to reopen
this bug and simply change the 'version' to a later Fedora version.

Bug Reporter: Thank you for reporting this issue and we are sorry that
we were unable to fix it before Fedora 15 reached end of life. If you
would still like to see this bug fixed and are able to reproduce it
against a later version of Fedora, you are encouraged to click on
"Clone This Bug" (top right of this page) and open it against that
version of Fedora.

Although we aim to fix as many bugs as possible during every release's
lifetime, sometimes those efforts are overtaken by events. Often a
more recent Fedora release includes newer upstream software that fixes
bugs or makes them obsolete.

The process we are following is described here:
http://fedoraproject.org/wiki/BugZappers/HouseKeeping
Comment 17 Stas Sergeev 2013-03-15 12:34:21 EDT
Can this now be fixed with -ftrack-macro-expansion?
Comment 18 Fedora End Of Life 2013-07-04 02:47:01 EDT
This message is a reminder that Fedora 17 is nearing its end of life.
Approximately 4 (four) weeks from now Fedora will stop maintaining
and issuing updates for Fedora 17. It is Fedora's policy to close all
bug reports from releases that are no longer maintained. At that time
this bug will be closed as WONTFIX if it remains open with a Fedora 
'version' of '17'.

Package Maintainer: If you wish for this bug to remain open because you
plan to fix it in a currently maintained version, simply change the 'version' 
to a later Fedora version prior to Fedora 17's end of life.

Bug Reporter:  Thank you for reporting this issue and we are sorry that 
we may not be able to fix it before Fedora 17 is end of life. If you 
would still like  to see this bug fixed and are able to reproduce it 
against a later version  of Fedora, you are encouraged  change the 
'version' to a later Fedora version prior to Fedora 17's end of life.

Although we aim to fix as many bugs as possible during every release's 
lifetime, sometimes those efforts are overtaken by events. Often a 
more recent Fedora release includes newer upstream software that fixes 
bugs or makes them obsolete.
Comment 19 Fedora End Of Life 2013-08-01 14:25:03 EDT
Fedora 17 changed to end-of-life (EOL) status on 2013-07-30. Fedora 17 is 
no longer maintained, which means that it will not receive any further 
security or bug fix updates. As a result we are closing this bug.

If you can reproduce this bug against a currently maintained version of 
Fedora please feel free to reopen this bug against that version.

Thank you for reporting this bug and we are sorry it could not be fixed.

Note You need to log in before you can comment on or make changes to this bug.