public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "pkoning at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c/51147] New: attribute((mode(byte))) on an enum generates wrong code
Date: Tue, 15 Nov 2011 22:50:00 -0000	[thread overview]
Message-ID: <bug-51147-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 51147
           Summary: attribute((mode(byte))) on an enum generates wrong
                    code
    Classification: Unclassified
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: pkoning@gcc.gnu.org


Created attachment 25830
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=25830
Test case file

In an attempt to work around bug 49459, I tried putting attribute(mode_byte))
on the enum declaration (instead of on the typedef as in that bug).

While that fixes the wrong debug output, it instead gives me seriously invalid
code.  The attached testcase shows the issue.  The compiler appears to handle
the functions foo and bar as if they return 1 unconditionally, so foo is
called, bar is not, and test returns 1 unconditionally.

Looking at the tree dump files, I see in the 001t.tu file something odd about
the return type of foo() -- it is showing up as an enum (unsigned) whose min
value is 0 and max value is -1.  I'm not sure how that causes the specific
failure but it makes me wonder.  The mishandling of the function return values
shows up right away (in the 003t.original dump file).

The bug has been seen in 4.5.1 and 4.6.1.  I also tried 3.3.3 because I happen
to have it handy, but there the compiler crashes).

A 4.1.2 compiler (stock gcc on my Linux) gets it wrong also, with the addition
that it warns "Comparison is always true due to limited range of data type". 
4.5.1 does not say so (not even with -Wall).

All this is with -O2.


             reply	other threads:[~2011-11-15 22:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-11-15 22:50 pkoning at gcc dot gnu.org [this message]
2011-11-15 23:06 ` [Bug c/51147] " pkoning at gcc dot gnu.org
2011-11-15 23:07 ` pinskia at gcc dot gnu.org
2011-11-15 23:28 ` pinskia at gcc dot gnu.org
2011-11-16  3:44 ` pkoning at gcc dot gnu.org
2011-11-18 13:12 ` pkoning 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-51147-4@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).