public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58455] New: spurious "may be used uninitialized" warning with -Og
@ 2013-09-18  6:29 rbd at debian dot org
  2013-09-18  7:00 ` [Bug c++/58455] " rbd at debian dot org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: rbd at debian dot org @ 2013-09-18  6:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58455
           Summary: spurious "may be used uninitialized" warning with -Og
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rbd at debian dot org

(My gcc 4.8 is new enough that it has the fix for PR middle-end/58377)

I have a case of C++ code that spuriously warns about a "may be used
uninitialized" variable.  I haven't been able to turn this into similar C code
that still warns.  Also the "|| false" in the if statement seems to do
something -- without it I don't get the warning!

$ cat y.cpp
struct B
{
    int offset;
    bool is_loaded(unsigned char *p1)
    {
        if (offset) {
            *p1 = offset;
            return true;
        }
        return false;
    }
};

unsigned char match(struct B ref)
{
        unsigned char ref_offset;
        if (!ref.is_loaded(&ref_offset) || false)
                return ref_offset;
        else
                return 0;
}


$ gcc -v -Wall -Og -Werror -c ~/y.cpp
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.1-10ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu3) 
COLLECT_GCC_OPTIONS='-v' '-Wall' '-Og' '-Werror' '-c' '-E' '-mtune=generic'
'-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -E -quiet -v -imultiarch
x86_64-linux-gnu -D_GNU_SOURCE /home/roland/y.cpp -mtune=generic -march=x86-64
-Wall -Werror -Og -fstack-protector -Wformat -Wformat-security
ignoring duplicate directory "/usr/include/x86_64-linux-gnu/c++/4.8"
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../x86_64-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.8
 /usr/include/x86_64-linux-gnu/c++/4.8
 /usr/include/c++/4.8/backward
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed
 /usr/include/x86_64-linux-gnu
 /usr/include
End of search list.
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.8/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib/:/lib/x86_64-linux-gnu/:/lib/../lib/:/usr/lib/x86_64-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-Wall' '-Og' '-Werror' '-c' '-E' '-mtune=generic'
'-march=x86-64'
Using built-in specs.
COLLECT_GCC=/usr/bin/gcc
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.8.1-10ubuntu3' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs
--enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.8 --enable-shared --enable-linker-build-id
--libexecdir=/usr/lib --without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin
--with-system-zlib --disable-browser-plugin --enable-java-awt=gtk
--enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre
--enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64
--with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64
--with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar
--enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686
--with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic
--enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu3) 
COLLECT_GCC_OPTIONS='-v' '-Wall' '-Og' '-Werror' '-c' '-o'
'/home/roland/.ccache/a/4/3eaed08e6d4177435e048912941826-3578.o.tmp.roland-t410s.22760'
'-mtune=generic' '-march=x86-64'
 /usr/lib/gcc/x86_64-linux-gnu/4.8/cc1plus -fpreprocessed
/home/roland/.ccache/tmp/y.tmp.roland-t410s.22760.ii -quiet -dumpbase
y.tmp.roland-t410s.22760.ii -mtune=generic -march=x86-64 -auxbase-strip
/home/roland/.ccache/a/4/3eaed08e6d4177435e048912941826-3578.o.tmp.roland-t410s.22760
-Og -Wall -Werror -version -fstack-protector -Wformat -Wformat-security -o
/tmp/cc6olJBS.s
GNU C++ (Ubuntu/Linaro 4.8.1-10ubuntu3) version 4.8.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.1-p2,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu/Linaro 4.8.1-10ubuntu3) version 4.8.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.8.1, GMP version 5.1.2, MPFR version 3.1.1-p2,
MPC version 1.0.1
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 9d410e3e527a5e0f1d5bb684c93d46d6
/home/roland/y.cpp: In function ‘unsigned char match(B)’:
/home/roland/y.cpp:16:23: error: ‘ref_offset’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
         unsigned char ref_offset;
                       ^
cc1plus: all warnings being treated as errors


$ for o in Og O0 O1 O2 O3; do echo == $o ==;  gcc -Wall -$o -Werror -c ~/y.cpp;
done
== Og ==
/home/roland/y.cpp: In function ‘unsigned char match(B)’:
/home/roland/y.cpp:16:23: error: ‘ref_offset’ may be used uninitialized in this
function [-Werror=maybe-uninitialized]
         unsigned char ref_offset;
                       ^
cc1plus: all warnings being treated as errors
== O0 ==
== O1 ==
== O2 ==
== O3 ==
>From gcc-bugs-return-430054-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Sep 18 06:45:40 2013
Return-Path: <gcc-bugs-return-430054-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 10542 invoked by alias); 18 Sep 2013 06:45:40 -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 10490 invoked by uid 48); 18 Sep 2013 06:45:36 -0000
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58455] spurious "may be used uninitialized" warning with -Og
Date: Wed, 18 Sep 2013 06:45: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: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: jakub 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: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cc
Message-ID: <bug-58455-4-81pKxKb5Zi@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-58455-4@http.gcc.gnu.org/bugzilla/>
References: <bug-58455-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/msg01294.txt.bz2
Content-length: 529

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Why do you think this is spurious?  You are returning ref_offset if is_loaded
method returns false, i.e. exactly when ref_offset hasn't been initialized.


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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-09-18  6:29 [Bug c++/58455] New: spurious "may be used uninitialized" warning with -Og rbd at debian dot org
2013-09-18  7:00 ` [Bug c++/58455] " rbd at debian dot org
2013-09-18  8:12 ` rguenth at gcc dot gnu.org
2013-09-18  8:39 ` rguenth at gcc dot gnu.org
2013-09-18  8:40 ` rguenth at gcc dot gnu.org
2013-09-18  8:54 ` rguenth at gcc dot gnu.org
2013-10-30 21:00 ` 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).