public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/58488] New: -Wuninitialized is useless for a variable whose address is later taken
@ 2013-09-20 23:55 eblake at redhat dot com
  2013-09-22 10:49 ` [Bug c/58488] " manu at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: eblake at redhat dot com @ 2013-09-20 23:55 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=58488

            Bug ID: 58488
           Summary: -Wuninitialized is useless for a variable whose
                    address is later taken
           Product: gcc
           Version: 4.8.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: eblake at redhat dot com

Here's a simple example of where -Wuninitialized is rather useless at default
optimization:

$ cat foo.c
#include <stdlib.h>

int main(void) {
    char *oops;
    free(oops);
    void *other =
#ifdef RELIABLE
        NULL
#else
        &oops
#endif
        ;
    return !other;
}

$ gcc -Werror -Wall -Wuninitialized -o foo -c foo.c
$ gcc -Werror -Wall -Wuninitialized -o foo -c foo.c -DRELIABLE
foo.c: In function ‘main’:
foo.c:5:9: error: ‘oops’ is used uninitialized in this function
[-Werror=uninitialized]
     free(oops);
         ^
cc1: all warnings being treated as errors
$ gcc -Werror -Wall -Wuninitialized -o foo -c foo.c -O2
foo.c: In function ‘main’:
foo.c:5:9: error: ‘oops’ is used uninitialized in this function
[-Werror=uninitialized]
     free(oops);
         ^
cc1: all warnings being treated as errors
$ gcc -Werror -Wall -Wuninitialized -o foo -c foo.c -DRELIABLE -O2
foo.c: In function ‘main’:
foo.c:5:9: error: ‘oops’ is used uninitialized in this function
[-Werror=uninitialized]
     free(oops);
         ^
cc1: all warnings being treated as errors

I understand that -O2 enables better uninitialization checks, but I find it
quite awkward that even without -O2, the mere taking an address of a variable
hides it from the uninit checker.  My end goal is to have a macro that does a
one-shot evaluation of its argument:

#define FREE(x) { typeof(x) *_x = &(x); free(*_x); *_x = NULL; }

for safety, but that macro kills -Wuninit checking by virtue of the fact that
it takes the address of the pointer.  Even if I limit myself to a macro that
evaluates its argument more than once (and forcing me to audit code to avoid
FREE(side-effects) - if only there were a way to make the compiler
automatically barf if it encounters side effects in a macro argument), I am
unable to come up with a way to get the uninit checking that gcc provides
regardless of optimization without also having the safety of ensuring the
pointer isn't abused after the fact.
>From gcc-bugs-return-430330-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Fri Sep 20 23:58:50 2013
Return-Path: <gcc-bugs-return-430330-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 17795 invoked by alias); 20 Sep 2013 23:58:50 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 17759 invoked by uid 55); 20 Sep 2013 23:58:47 -0000
From: "danglin at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/56791] [4.8/4.9 Regression] Segmentation fault in stage2 gengenrtl -- Incorrect instruction sequence generated by reload
Date: Fri, 20 Sep 2013 23:58:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: middle-end
X-Bugzilla-Version: 4.8.0
X-Bugzilla-Keywords: build, wrong-code
X-Bugzilla-Severity: normal
X-Bugzilla-Who: danglin at gcc dot gnu.org
X-Bugzilla-Status: UNCONFIRMED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.8.2
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-56791-4-RGGoxbFAnn@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-56791-4@http.gcc.gnu.org/bugzilla/>
References: <bug-56791-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2013-09/txt/msg01570.txt.bz2
Content-length: 471

http://gcc.gnu.org/bugzilla/show_bug.cgi?idV791

--- Comment #4 from John David Anglin <danglin at gcc dot gnu.org> ---
Author: danglin
Date: Fri Sep 20 23:58:43 2013
New Revision: 202807

URL: http://gcc.gnu.org/viewcvs?rev 2807&root=gcc&view=rev
Log:
    PR middle-end/56791
    * config/pa/pa.c (pa_option_override): Disable auto increment and
    decrement instructions until reload is completed.


Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/pa/pa.c


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-30 20:47 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-20 23:55 [Bug c/58488] New: -Wuninitialized is useless for a variable whose address is later taken eblake at redhat dot com
2013-09-22 10:49 ` [Bug c/58488] " manu at gcc dot gnu.org
2013-09-23 16:16 ` eblake at redhat dot com
2013-09-23 16:31 ` jakub at gcc dot gnu.org
2013-10-30 20:47 ` law at redhat dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).