[Bug nptl/21513] New: pthread_cleanup_push macro generates warning when -Wclobbered is set

pcarroll at codesourcery dot com sourceware-bugzilla@sourceware.org
Tue May 23 23:25:00 GMT 2017


https://sourceware.org/bugzilla/show_bug.cgi?id=21513

            Bug ID: 21513
           Summary: pthread_cleanup_push macro generates warning when
                    -Wclobbered is set
           Product: glibc
           Version: 2.24
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: nptl
          Assignee: unassigned at sourceware dot org
          Reporter: pcarroll at codesourcery dot com
                CC: drepper.fsp at gmail dot com
  Target Milestone: ---

There is an open issue filed against the Gcc Middle-End - Bugzilla #61118.
In this issue, it is noted that the use of the pthread_cleanup_push macro from
pthread.h will generate 2 warnings when -Wclobbered is set.  
The warnings are for the '__cancel_routine' and '__cancel_arg' variables that
are created as part of the macro definition.
The warning occurs because of the presence of a sigsetjmp() call after those 2
variables are defined.

As is noted in the Bugzilla issue, one solution to the issue would be to fix
the Gcc Middle-End, so as to recognize that the pthread_cleanup_push macro is
coming from a system header and thus suppress the warning.

In the absence of a GCC fix, another possible solution is to modify the macro
definitions in pthread.h so as to mark those variables as 'volatile'.
The changes would be made to both pthread_cleanup_push and
pthread_cleanup_push_defer_np macro definitions.  The changes would make the
macros look something like this:

# define pthread_cleanup_push(routine, arg) \
  do {                                                                        \
    __pthread_unwind_buf_t __cancel_buf;                                      \
    void (* volatile __cancel_routine) (void *) = (routine);                  \
    void * volatile __cancel_arg = (arg);                                     \
    :

Since those variables are now reloaded whenever they are used and thus will not
be clobbered by the setjmp, the compilation will be quiet.
An interesting side effect is that, for an ARM compilation, the resulting
object file for the Bugzilla #61118 test case generated 24 less bytes of text,
with a few less memory references.

An alternative to using 'volatile' could potentially involve using '#pragma GCC
diagnostic' or '_Pragma("GCC diagnostic")' to have the compiler ignore the
warning for those 2 macros, but my attempts to use those failed.
And that would only be valid if those warnings are truly irrelevant to these
macros, in that those variables could never be clobbered.

These warnings become more important when customers use -Werror and expect no
warnings at compilation time.

-- 
You are receiving this mail because:
You are on the CC list for the bug.


More information about the Glibc-bugs mailing list