RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1185673 - -Wclobber produces useless, incorrect warnings for setjmp/longjmp hazards
Summary: -Wclobber produces useless, incorrect warnings for setjmp/longjmp hazards
Keywords:
Status: CLOSED UPSTREAM
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: gcc
Version: 6.6
Hardware: x86_64
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Jakub Jelinek
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2015-01-25 19:34 UTC by Tom Lane
Modified: 2015-02-12 14:36 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2015-02-12 14:36:32 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Test program demonstrating two misbehaviors of -Wclobbered warnings (589 bytes, text/x-csrc)
2015-01-25 19:34 UTC, Tom Lane
no flags Details


Links
System ID Private Priority Status Summary Last Updated
GNU Compiler Collection 65041 0 'P3' 'REOPENED' 'Improve -Wclobbered' 2019-11-26 15:03:34 UTC

Description Tom Lane 2015-01-25 19:34:39 UTC
Created attachment 983991 [details]
Test program demonstrating two misbehaviors of -Wclobbered warnings

Description of problem:
I wish that -Wclobbered would warn me about code that fails to meet the restrictions specified for safe use of setjmp/longjmp, namely (quoting from longjmp man page)

       The values of automatic variables  are  unspecified  after  a  call  to
       longjmp() if they meet all the following criteria:
       *  they are local to the function that made the corresponding setjmp(3)
          call;
       *  their  values  are  changed  between  the  calls  to  setjmp(3)  and
          longjmp(); and
       *  they are not declared as volatile.

-Wclobbered is advertised as meeting this need, but it not only fails to warn about unsafe situations, but it generates useless warnings about perfectly safe situations.

Version-Release number of selected component (if applicable):
gcc-4.4.7-11.el6.x86_64
(also observed on current Fedora 20, gcc 4.8.3)

How reproducible:
100%

Steps to Reproduce:
Compile the attached test program with "gcc -Wall -Wclobbered -O2 -c setjmptest.c"

Actual results:
setjmptest.c:15: warning: variable 'a2' might be clobbered by 'longjmp' or 'vfork'

Expected results:
I should get a warning about fd (which is at risk) and not about a2 (which is not).

Additional info:
The compiled code is evidently optimized on the assumption that someotherfunc() cannot cause transfer of control into the else-block: the assignment "fd = -1" is removed, and so is the "if (fd >= 0)" test.  I am not whining about that: I am whining about the compiler's failure to warn me that it might do this.

Comment 2 Tom Lane 2015-01-25 19:52:51 UTC
Note that the test program is stripped down as much as possible.  If you want to complain that the external functions couldn't cause such a longjmp for lack of access to jbuf, save your breath: in the real application where I'm seeing this type of problem, they definitely do have access.  (For the record, the test case is stripped down from an actual missing-volatile-marker bug in Postgres 9.4.0.  But investigation says that gcc's clobber warnings have been pretty divorced from reality as far back as 2.95.3.)

Comment 3 Jakub Jelinek 2015-01-25 20:11:38 UTC
-Wclobbered warns about vars and arguments at risk, those that are live across the setjmp and live in registers.  fd in this case is allocated to memory (because it is live across several calls), and therefore not a problem.

Comment 4 Tom Lane 2015-01-25 20:13:48 UTC
Yes, it's in memory, but the optimizations I mentioned make the code unsafe, so I need the warning to tell me to put "volatile" on the variable declaration.

Comment 5 Tom Lane 2015-01-25 20:17:38 UTC
Also, the bigger picture here is that we would like gcc to warn about non-spec-compliant code of this type, even if the code gcc chooses to generate is not at risk.  We develop mostly with gcc but we expect the code to run on non-gcc compilers; so a missing "volatile" poses a risk of bad code generation on other compilers even if gcc generated code that works fine.

Comment 6 Jakub Jelinek 2015-01-25 20:22:47 UTC
In any case, filing a request against RHEL6 doesn't make much sense, we definitely can't change what gcc produces with existing warning flags for warnings in released versions of gcc - many people use -Werror and any such changes could break their code.

Comment 7 Tom Lane 2015-01-25 20:27:07 UTC
Well, how to respond to this bug report is your decision.  I would be satisfied if there were a long-run solution (ie, something in the next gcc release).

Comment 10 Jeff Law 2015-02-12 14:36:32 UTC
Tom,

We're going to track this issue directly upstream rather than in Red Hat's BZ since the work necessary for this enhancement needs to first occur upstream.

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65041


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