public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug middle-end/50189] [4.5/4.6 Regression] Wrong code error in -O2 [-fstrict-enums] compile, target independent
Date: Wed, 12 Oct 2011 11:43:00 -0000	[thread overview]
Message-ID: <bug-50189-4-IZZzvFEOIN@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-50189-4@http.gcc.gnu.org/bugzilla/>

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

Richard Guenther <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |rguenth at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #11 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-10-12 11:42:45 UTC ---
(In reply to comment #10)
> Created attachment 25467 [details]
> Tentative patch against 4.6.1
> 
> I chased the issue for a while, using 4.6.1 as the test version.
> 
> The problem is in extract_range_from_assert.  When processing < <= > >=
> assertions, it sets the min (for < <=) or max (for > >=) of the calculated
> range to be the type min or max of the right hand side.
> 
> In the testcase, we have "m_timestamp > AT_END" where m_timestamp is unsigned
> int and AT_END is enum with value 2.  The highest enum value of that enum type
> is 3, so if fstrict-enums is in effect, the type max is 3.
> 
> Result: while the dump file shows the resulting range as [3,+INF] what that
> actually means is [3,3] because the upper bound of the enum is applied, *not*
> the upper bound of the variable being compared.
> 
> The solution is for extract_range_from_assert to pick up type min or type max
> from the type of the left hand side (here m_timestamp, i.e., unsigned int).  So
> the range still shows as [3,+INF] but now that represents [3,4294967295] and
> the resulting code is correct.
> 
> The patch is just one line.  The question I have is whether changing the way
> variable "type" is set is right, because it is also used in the != case and I
> don't fully understand that one.

While I don't necessarily agree with your conclusion that this is the bug
(GCC expects both operands of the comparisons to be of "compatible types",
and GCC treats types compatible when they have the same precision and
disregards TYPE_{MIN,MAX}_VALUE - which it can't when at the same time
VRP (and _only_ VRP) uses those values for optimization), your patch
makes sense - the type of var is the more natural one to chose (also
when looking at other uses of 'type').  If it mitigates the issue in
more cases that's even better!

I'm going to give it proper testing.

Thanks for spotting this simple solution for your problem.


  parent reply	other threads:[~2011-10-12 11:43 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-08-25 17:19 [Bug c++/50189] New: Wrong code error in -O2 " pkoning at gcc dot gnu.org
2011-08-25 17:21 ` [Bug c++/50189] " pkoning at gcc dot gnu.org
2011-08-25 17:43 ` pkoning at gcc dot gnu.org
2011-08-25 18:34 ` [Bug c++/50189] [4.5 Regression] " pinskia at gcc dot gnu.org
2011-08-26  8:01 ` [Bug middle-end/50189] " rguenth at gcc dot gnu.org
2011-08-26  8:27 ` jakub at gcc dot gnu.org
2011-08-26  8:32 ` [Bug middle-end/50189] [4.5/4.6 Regression] Wrong code error in -O2 [-fstrict-enums] " rguenth at gcc dot gnu.org
2011-09-09 19:35 ` pkoning at gcc dot gnu.org
2011-10-10 20:42 ` pkoning at gcc dot gnu.org
2011-10-11  9:06 ` rguenth at gcc dot gnu.org
2011-10-11  9:09 ` rguenth at gcc dot gnu.org
2011-10-11 19:03 ` pkoning at gcc dot gnu.org
2011-10-12 11:43 ` rguenth at gcc dot gnu.org [this message]
2011-10-12 14:05 ` pkoning at gcc dot gnu.org
2011-10-12 14:17 ` rguenther at suse dot de
2011-10-12 14:23 ` rguenther at suse dot de
2011-10-12 15:14 ` rguenth at gcc dot gnu.org
2011-10-12 15:17 ` [Bug middle-end/50189] [4.5 " rguenth at gcc dot gnu.org
2011-10-12 15:18 ` [Bug middle-end/50189] [4.5/4.6 " rguenth at gcc dot gnu.org
2012-01-03 15:29 ` [Bug middle-end/50189] [4.5 " rguenth at gcc dot gnu.org
2012-01-03 15:29 ` rguenth at gcc dot gnu.org

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-50189-4-IZZzvFEOIN@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).