public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "manu at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/48001] inconsistent warning within loop always taken and outside the loop
Date: Sat, 05 Mar 2011 21:41:00 -0000	[thread overview]
Message-ID: <bug-48001-4-83Y1J2t9sr@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-48001-4@http.gcc.gnu.org/bugzilla/>

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

Manuel López-Ibáñez <manu at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |manu at gcc dot gnu.org
            Summary|-Wuninitialized warning     |inconsistent warning within
                   |caught a different way for  |loop always taken and
                   |printf and ++ in loop       |outside the loop

--- Comment #2 from Manuel López-Ibáñez <manu at gcc dot gnu.org> 2011-03-05 21:41:16 UTC ---
This is because printf has side-effects (printing) but x++ does not have any
side-effects (x is unused), therefore, gcc removes x completely in the third
testcase. I guess the loop is also removed completely. This is a too artificial
testcase, in the sense that we do not care that x is uninitialized because it
is never used for anything.

We warn for the first testcase because the mechanism for detecting "is" is
different from the mechanism for detecting "may be". The former happens before
we remove the unused x, but the latter happens after in order to not warn for
dead code.

There is also the problem that GCC cannot detect that loops are taken at least
once, which makes it say "maybe" when it should actually be "is".

To be consistent, I would say that GCC shouldn't warn in the first testcase, or
should warn as "is used" in the third testcase.


  parent reply	other threads:[~2011-03-05 21:41 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-05 20:43 [Bug middle-end/48001] New: -Wuninitialized warning caught a different way for printf and ++ in loop jerome.borme at gmail dot com
2011-03-05 20:46 ` [Bug middle-end/48001] " jerome.borme at gmail dot com
2011-03-05 21:41 ` manu at gcc dot gnu.org [this message]
2011-03-05 22:25 ` [Bug middle-end/48001] inconsistent warning within loop always taken and outside the loop jerome.borme at gmail dot com

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-48001-4-83Y1J2t9sr@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).