public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32132]  New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
@ 2007-05-28 20:08 pluto at agmk dot net
  2007-05-28 20:09 ` [Bug c++/32132] " pluto at agmk dot net
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-28 20:08 UTC (permalink / raw)
  To: gcc-bugs

attached testcase produces unexpected warning at -O3:

$ g++ -Wall -Woverloaded-virtual  -Werror -O3 -gdwarf-2 -g1 -fPIE \
  -Wno-error -c auHexCastTest.ii

../../au/h/auHexCast.hpp: In function ‘R au::hex_cast(const
stlp_std::string&) [with R = int]’:
../../au/h/auHexCast.hpp:50: warning: ‘r’ may be used uninitialized
in this function


-- 
           Summary: bogus warning at -O3 ( 'r' may be used uninitialized in
                    this function ).
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: pluto at agmk dot net
GCC target triplet: x86_64-linux


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
@ 2007-05-28 20:09 ` pluto at agmk dot net
  2007-05-28 20:13 ` pinskia at gcc dot gnu dot org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-28 20:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from pluto at agmk dot net  2007-05-28 20:08 -------
Created an attachment (id=13623)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13623&action=view)
testcase


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
  2007-05-28 20:09 ` [Bug c++/32132] " pluto at agmk dot net
@ 2007-05-28 20:13 ` pinskia at gcc dot gnu dot org
  2007-05-28 20:16 ` pluto at agmk dot net
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-28 20:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from pinskia at gcc dot gnu dot org  2007-05-28 20:13 -------
This might not be a bug ....


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
  2007-05-28 20:09 ` [Bug c++/32132] " pluto at agmk dot net
  2007-05-28 20:13 ` pinskia at gcc dot gnu dot org
@ 2007-05-28 20:16 ` pluto at agmk dot net
  2007-05-28 20:26 ` pinskia at gcc dot gnu dot org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-28 20:16 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from pluto at agmk dot net  2007-05-28 20:16 -------
(In reply to comment #2)
> This might not be a bug ....
> 

so, how 'r' can be used uninitialized in this case?

        template <typename R>
        R hex_cast ( const std::string & s )
        {
                if ( s.empty () )
                        throw bad_hex_cast ();
                R r;
                std::istringstream str ( s );
                str >> std::hex >> r;
                return r;
        }


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (2 preceding siblings ...)
  2007-05-28 20:16 ` pluto at agmk dot net
@ 2007-05-28 20:26 ` pinskia at gcc dot gnu dot org
  2007-05-28 21:48 ` pinskia at gcc dot gnu dot org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-28 20:26 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-05-28 20:26 -------
so, how 'r' can be used uninitialized in this case?
Because istringstream >> r could have caused an error.  so you need to check if
there is an error.


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (3 preceding siblings ...)
  2007-05-28 20:26 ` pinskia at gcc dot gnu dot org
@ 2007-05-28 21:48 ` pinskia at gcc dot gnu dot org
  2007-05-29  8:51 ` pluto at agmk dot net
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-05-28 21:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from pinskia at gcc dot gnu dot org  2007-05-28 21:48 -------
The warning is correct you need to check if str had an error after reading the
integer.  This is not a GCC bug.

The IR looks like:
<bb 7>:
  __comp_ctor  (&str, s, 8);
  this.104 = (struct ios_base *) &str.D.25711;
  __s = this.104 + *(int *) (str.D.25711._vptr.basic_istream + -12);
  D.40158 = __s->_M_fmtflags;
  __s->_M_fmtflags = D.40158 & -57 | 16;
  _M_get_num (&str.D.25711, &__lval);

<bb 8>:
  if (((this.104 + *(int *) (str.D.25711._vptr.basic_istream +
-12))->_M_iostate & 5) != 0)
    goto <bb 10>;
  else
    goto <bb 9>;

<bb 9>:
  __lval.107 = __lval;
  r = __lval.107;

<bb 10>:
  __comp_dtor  (&str);
  return r;

Which shows for sure r may be used unitialized.   

Note using libstdc++ does not warn about this because we made >> out of line
only which means you will not see the warning (even though the warning is
correct).


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (4 preceding siblings ...)
  2007-05-28 21:48 ` pinskia at gcc dot gnu dot org
@ 2007-05-29  8:51 ` pluto at agmk dot net
  2007-05-29 10:18 ` pluto at agmk dot net
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-29  8:51 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from pluto at agmk dot net  2007-05-29 08:50 -------
(In reply to comment #5)
> Which shows for sure r may be used unitialized.   

yes, but even if i catch possible i/o failure, gcc still produces warning.

--- auHexCastTest.ii.orig
+++ auHexCastTest.ii
@@ -18958,7 +18958,12 @@

   R r;
   stlp_std::istringstream str ( s );
-  str >> stlp_std::hex >> r;
+  str.exceptions ( stlp_std::istringstream::eofbit ||
stlp_std::istringstream::badbit || stlp_std::istringstream::failbit );
+  try {
+    str >> stlp_std::hex >> r;
+  } catch ( stlp_std::istringstream::failure ) {
+    throw;
+  }
   return r;
  }

so, is it still an invalid testcase?


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (5 preceding siblings ...)
  2007-05-29  8:51 ` pluto at agmk dot net
@ 2007-05-29 10:18 ` pluto at agmk dot net
  2007-05-29 12:31 ` manu at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-29 10:18 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from pluto at agmk dot net  2007-05-29 10:17 -------
(In reply to comment #6)
> +  str.exceptions ( stlp_std::istringstream::eofbit ||
> stlp_std::istringstream::badbit || stlp_std::istringstream::failbit );

^^^^^^^^^^^^ of course it should be '|' instead of '||' (shame on me)
but the warning is still presents. it is also presents when i use
the fail() method instead of exceptions machinery.


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (6 preceding siblings ...)
  2007-05-29 10:18 ` pluto at agmk dot net
@ 2007-05-29 12:31 ` manu at gcc dot gnu dot org
  2007-05-29 12:35 ` pluto at agmk dot net
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-05-29 12:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from manu at gcc dot gnu dot org  2007-05-29 12:31 -------
(In reply to comment #6)
> 
> so, is it still an invalid testcase?

Does the warning show up with -O1 and -O2 ?


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu dot org


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (7 preceding siblings ...)
  2007-05-29 12:31 ` manu at gcc dot gnu dot org
@ 2007-05-29 12:35 ` pluto at agmk dot net
  2007-05-29 12:42 ` pluto at agmk dot net
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-29 12:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #9 from pluto at agmk dot net  2007-05-29 12:35 -------
(In reply to comment #8)
> (In reply to comment #6)
> > 
> > so, is it still an invalid testcase?
> 
> Does the warning show up with -O1 and -O2 ?
> 

only with -O3.


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (8 preceding siblings ...)
  2007-05-29 12:35 ` pluto at agmk dot net
@ 2007-05-29 12:42 ` pluto at agmk dot net
  2007-05-29 12:57 ` manu at gcc dot gnu dot org
  2007-06-10  3:19 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pluto at agmk dot net @ 2007-05-29 12:42 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #10 from pluto at agmk dot net  2007-05-29 12:42 -------
Created an attachment (id=13627)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13627&action=view)
update for the testcase.


-- 


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (9 preceding siblings ...)
  2007-05-29 12:42 ` pluto at agmk dot net
@ 2007-05-29 12:57 ` manu at gcc dot gnu dot org
  2007-06-10  3:19 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: manu at gcc dot gnu dot org @ 2007-05-29 12:57 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #11 from manu at gcc dot gnu dot org  2007-05-29 12:57 -------
(In reply to comment #9)
> (In reply to comment #8)
> > (In reply to comment #6)
> > > 
> > > so, is it still an invalid testcase?
> > 
> > Does the warning show up with -O1 and -O2 ?
> > 
> 
> only with -O3.
> 

That is a bug by itself. Using more optimisations could result in some cases
clearing out (and thus, less warnings). It should never result in more
warnings.


-- 

manu at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |UNCONFIRMED
         Resolution|INVALID                     |


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


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

* [Bug c++/32132] bogus warning at -O3 ( 'r' may be used uninitialized in this function ).
  2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
                   ` (10 preceding siblings ...)
  2007-05-29 12:57 ` manu at gcc dot gnu dot org
@ 2007-06-10  3:19 ` pinskia at gcc dot gnu dot org
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-06-10  3:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #12 from pinskia at gcc dot gnu dot org  2007-06-10 03:18 -------
> It should never result in more warnings.

More inlining :)

Anyways the use is still uninitialized if you look at the IR, GCC itself cannot
tell if r is initialized by looking at the IR.


-- 

pinskia at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


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


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

end of thread, other threads:[~2007-06-10  3:19 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-28 20:08 [Bug c++/32132] New: bogus warning at -O3 ( 'r' may be used uninitialized in this function ) pluto at agmk dot net
2007-05-28 20:09 ` [Bug c++/32132] " pluto at agmk dot net
2007-05-28 20:13 ` pinskia at gcc dot gnu dot org
2007-05-28 20:16 ` pluto at agmk dot net
2007-05-28 20:26 ` pinskia at gcc dot gnu dot org
2007-05-28 21:48 ` pinskia at gcc dot gnu dot org
2007-05-29  8:51 ` pluto at agmk dot net
2007-05-29 10:18 ` pluto at agmk dot net
2007-05-29 12:31 ` manu at gcc dot gnu dot org
2007-05-29 12:35 ` pluto at agmk dot net
2007-05-29 12:42 ` pluto at agmk dot net
2007-05-29 12:57 ` manu at gcc dot gnu dot org
2007-06-10  3:19 ` pinskia at gcc dot gnu dot org

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).