From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 37976 invoked by alias); 20 Apr 2015 10:37:24 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 37698 invoked by uid 48); 20 Apr 2015 10:37:20 -0000 From: "joe at perches dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65812] New: gcc 4.9.1 doesn't warn about uninitialized variable use declared in a switch/case statement when compiled with -O Date: Mon, 20 Apr 2015 10:37:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: joe at perches dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2015-04/txt/msg01602.txt.bz2 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D65812 Bug ID: 65812 Summary: gcc 4.9.1 doesn't warn about uninitialized variable use declared in a switch/case statement when compiled with -O Product: gcc Version: 4.9.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: joe at perches dot com Created attachment 35365 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D35365&action=3Dedit sample code Here is a small example: $ cat t.c struct foo { int bar[100]; }; void foo_1(void) { unsigned int m; extern struct foo *array[100]; struct foo *a =3D array[m]; a =3D a; } void foo_2(void) { int i =3D 1; switch (i) { case 1: { unsigned int m; extern struct foo *array[100]; struct foo *a =3D array[m]; a =3D a; break; } } } $ gcc warns properly about both foo_1 and foo_2 without -O $ gcc -c -Wall t.c t.c: In function =E2=80=98foo_1=E2=80=99: t.c:9:14: warning: =E2=80=98m=E2=80=99 is used uninitialized in this functi= on [-Wuninitialized] struct foo *a =3D array[m]; ^ t.c: In function =E2=80=98foo_2=E2=80=99: t.c:21:15: warning: =E2=80=98m=E2=80=99 may be used uninitialized in this f= unction [-Wmaybe-uninitialized] struct foo *a =3D array[m]; ^ $ but gcc warns about foo_1 but not foo_2 with -O $ gcc -c -Wall -O t.c t.c: In function =E2=80=98foo_1=E2=80=99: t.c:9:14: warning: =E2=80=98m=E2=80=99 is used uninitialized in this functi= on [-Wuninitialized] struct foo *a =3D array[m]; ^ $ gcc -v Using built-in specs. COLLECT_GCC=3D/usr/bin/gcc COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-linux-gnu/4.9/lto-wrapper Target: x86_64-linux-gnu Configured with: ../src/configure -v --with-pkgversion=3D'Ubuntu 4.9.1-16ub= untu6' --with-bugurl=3Dfile:///usr/share/doc/gcc-4.9/README.Bugs --enable-languages=3Dc,c++,java,go,d,fortran,objc,obj-c++ --prefix=3D/usr --program-suffix=3D-4.9 --enable-shared --enable-linker-build-id --libexecdir=3D/usr/lib --without-included-gettext --enable-threads=3Dposix --with-gxx-include-dir=3D/usr/include/c++/4.9 --libdir=3D/usr/lib --enable-= nls --with-sysroot=3D/ --enable-clocale=3Dgnu --enable-libstdcxx-debug --enable-libstdcxx-time=3Dyes --enable-gnu-unique-object --disable-vtable-v= erify --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=3Dgtk --enable-gtk-cairo --with-java-home=3D/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64/jre --enable-java-= home --with-jvm-root-dir=3D/usr/lib/jvm/java-1.5.0-gcj-4.9-amd64 --with-jvm-jar-dir=3D/usr/lib/jvm-exports/java-1.5.0-gcj-4.9-amd64 --with-arch-directory=3Damd64 --with-ecj-jar=3D/usr/share/java/eclipse-ecj.= jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=3Di686 --with-abi=3Dm64 --with-multilib-list=3Dm32,m64,mx32 --enable-multilib --with-tune=3Dgeneric --enable-checking=3Drelease --build=3Dx86_64-linux-gnu --host=3Dx86_64-linux-gnu --target=3Dx86_64-linux-gnu Thread model: posix gcc version 4.9.1 (Ubuntu 4.9.1-16ubuntu6) >>From gcc-bugs-return-484051-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Apr 20 10:38:10 2015 Return-Path: Delivered-To: listarch-gcc-bugs@gcc.gnu.org Received: (qmail 38951 invoked by alias); 20 Apr 2015 10:38:10 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Delivered-To: mailing list gcc-bugs@gcc.gnu.org Received: (qmail 38824 invoked by uid 48); 20 Apr 2015 10:38:05 -0000 From: "mpolacek at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/65673] Compound literal with initializer for zero-sized array drops other initializers Date: Mon, 20 Apr 2015 10:38:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 4.9.1 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: mpolacek at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: 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: 2015-04/txt/msg01603.txt.bz2 Content-length: 835 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65673 --- Comment #3 from Marek Polacek --- The following seems to work and regtests cleanly. But I have to say I'm somewhat dubious now about changing this at all. I suppose I should try to compile e.g. the Linux kernel with this patch and see if anything breaks. diff --git gcc/c/c-typeck.c gcc/c/c-typeck.c index ebe4c73..590e235 100644 --- gcc/c/c-typeck.c +++ gcc/c/c-typeck.c @@ -7565,7 +7565,7 @@ pop_init_level (location_t loc, int implicit, /* Silently discard empty initializations. The parser will already have pedwarned for empty brackets. */ if (integer_zerop (constructor_unfilled_index)) - constructor_type = NULL_TREE; + /* Do nothing. */; else { gcc_assert (!TYPE_SIZE (constructor_type));