Bug 24239 - spurious warning about clobbered variables w.r.t. longjmp
Summary: spurious warning about clobbered variables w.r.t. longjmp
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.1
: P2 minor
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-10-06 15:49 UTC by Daniel Villeneuve
Modified: 2005-11-26 07:54 UTC (History)
2 users (show)

See Also:
Host:
Target: i386-redhat-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2005-11-26 07:54:49


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Daniel Villeneuve 2005-10-06 15:49:17 UTC
The test for emitting a warning about "variables that might be clobbered by a call to longjmp or vfork" is overly pessimistic (unless I miss something from the C89/C99 standards).

In my opinion, the following code fragment should not get the warning, but it does when compiled with `gcc -O -W':
<code>
#include <setjmp.h>

extern int f(void);
extern int g(int);
extern jmp_buf jb;

int f(void)
{
  int j;

  j = 0;
  if( !setjmp(jb) ) {
    g(j);
  }
  else {
    j = -1;
  }

  return j;
}
</code>

I have also other variants that get the warning without deserving it (IMO).

Here is one relevant paragraph from ISO 9899 7.13.2.1:

<C99-quote>All accessible objects have values, and all other components of the abstract machine have state, as of the time the longjmp function was called, except that the values of objects of automatic storage duration that are local to the function containing the invocation of the corresponding setjmp macro that do not have volatile-qualified type and have been changed between the setjmp invocation and longjmp call are indeterminate.</C99-quote>

Feel free to contact me (I could try to contribute, at least for providing more test programs).

Thanks for your great work!

PS: the warning code in is gcc/function.c, which is why I've guessed about the component.
Comment 1 Andrew Pinski 2005-10-09 03:46:24 UTC
I think this is fixed on 4.0.
Comment 2 Daniel Villeneuve 2005-10-11 12:28:09 UTC
Indeed, in gcc-4.0.1, the previous code chunk does not elicit a warning.
However, a slightly modified version still gets a warning (tested
on RHEL-4, with <gcc version 4.0.1 20050727 (Red Hat 4.0.1-4.EL4.2)>).

<c-code>
#include <setjmp.h>

extern int f(void);
extern int g(int);
extern jmp_buf jb;
extern int i;

int f(void)
{
  int j;

  if( i > 10 ) j = i;
  else j = i + 10;

  if( !setjmp(jb) ) {
    g(j);
  }
  else {
    j = -1;
  }

  return j;
}
</c-code>
Comment 3 Gabriel Dos Reis 2005-11-26 07:54:49 UTC
(In reply to comment #2)
> Indeed, in gcc-4.0.1, the previous code chunk does not elicit a warning.
> However, a slightly modified version still gets a warning (tested
> on RHEL-4, with <gcc version 4.0.1 20050727 (Red Hat 4.0.1-4.EL4.2)>).

I can reproduce the behaviourwith mainline GCC (4.2.x)