Bug 21161 - "clobbered by longjmp" warning ignores the data flow
Summary: "clobbered by longjmp" warning ignores the data flow
Status: NEW
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.0.0
: P2 enhancement
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks:
 
Reported: 2005-04-22 11:07 UTC by bruno
Modified: 2012-09-29 22:25 UTC (History)
2 users (show)

See Also:
Host:
Target: powerpc-*-*, x86_64-*-*
Build:
Known to work:
Known to fail: 4.6.3
Last reconfirmed: 2012-01-11 00:00:00


Attachments
source file bug.c (3.21 KB, text/plain)
2005-04-22 11:08 UTC, bruno
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bruno 2005-04-22 11:07:36 UTC
The warning 
     argument 'obj' might be clobbered by 'longjmp' or 'vfork' 
does not take into account the facts that 
     1) When longjmp() is called, setjmp() returns a non-null value, 
     2) In this case, when setjmp() returns a non-null value, 'obj' is 
        reset before being used. 
 
$ gcc -v 
Using built-in specs. 
Target: powerpc-apple-darwin7.8.0 
Configured with: /Users/bruno/data/work/gcc-4.0.0-20050410/configure 
--prefix=/Volumes/UserData/experimental-macos --enable-shared 
--enable-version-specific-runtime-libs --enable-languages=c,c++ 
Thread model: posix 
gcc version 4.0.0 20050410 (prerelease) 
$ gcc -W -O -c bug.c  
bug.c: In function 'update_instance': 
bug.c:220: warning: argument 'obj' might be clobbered by 'longjmp' or 'vfork' 
 
Expected: no warning.
Comment 1 bruno 2005-04-22 11:08:38 UTC
Created attachment 8709 [details]
source file bug.c
Comment 2 Andrew Pinski 2005-08-23 02:12:20 UTC
The issue here is that obj is a parameter (argument) which gets assigned always the register r4 but I 
could be wrong.  It might be a true warning and the warning does not ignore flow control but I have not 
looked into that far.
Comment 3 Richard Biener 2012-01-11 13:06:21 UTC
Confirmed.
Comment 4 Thorsten Glaser 2012-09-29 22:25:14 UTC
Confirmed, happens in mksh now (but not with 4.6 or 4.7), reduced testcase:

tg@zigo:~/b/mksh-40.9.20120630 $ /usr/lib/gcc-snapshot/bin/gcc --version                                        
gcc (Debian 20120915-1) 4.8.0 20120915 (experimental) [trunk revision 191353]
Copyright (C) 2012 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

tg@zigo:~/b/mksh-40.9.20120630 $ /usr/lib/gcc-snapshot/bin/gcc -O2 -Wextra -c t.c                               
t.c: In function 'hereinval':
t.c:12:27: warning: argument 'content' might be clobbered by 'longjmp' or 'vfork' [-Wclobbered]
 int hereinval(const char *content, int sub, char **resbuf) {
                           ^
tg@zigo:~/b/mksh-40.9.20120630 $ cat t.c
#include <setjmp.h>
#include <string.h>
struct source {
        int foo;
        const char *str;
} *source = NULL;
jmp_buf jb;
extern char *evalstr(void);
extern struct source *pushs(void);
extern void newenv(void);
extern void quitenv(void);
int hereinval(const char *content, int sub, char **resbuf) {
        const char *ccp;
        struct source *s, *osource;

        osource = source;
        newenv();
        if (setjmp(jb)) {
                source = osource;
                quitenv();
                return (-2);
        }
        if (sub) {
                s = pushs();
                s->str = content;
                source = s;
                /* ... */
                ccp = evalstr();
                source = osource;
        } else
                ccp = content;

        *resbuf = strdup(ccp);
        return (0);
}