public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "jakub at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/58192] G++ emits incorrect code when passing enum classes as function parameters
Date: Fri, 19 Sep 2014 14:10:00 -0000	[thread overview]
Message-ID: <bug-58192-4-aPHAhjmIvA@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-58192-4@http.gcc.gnu.org/bugzilla/>

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=58192

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
When I compile:
#ifdef CHAR
typedef unsigned char Foo;
#else
enum class Foo : unsigned char { FOO };
#endif
unsigned int v1, v2;

__attribute__((noinline, noclone)) static void
foo (Foo a)
{
  v1 = (unsigned int) a;
}

__attribute__((noinline, noclone)) void
bar (Foo a)
{
  v2 = (unsigned int) a;
}

void
baz (unsigned int a)
{
  foo ((Foo) a);
  bar ((Foo) a);
}

with -DCHAR vs. -UCHAR, there is a difference visible already in *.original
dump:
 <<cleanup_point <<< Unknown tree: expr_stmt
-  foo ((int) (Foo) a) >>>>>;
+  foo ((Foo) a) >>>>>;
 <<cleanup_point <<< Unknown tree: expr_stmt
-  bar ((int) (Foo) a) >>>>>;
+  bar ((Foo) a) >>>>>;
i.e. there is explicit zero-extension for integral types smaller than int in
the IL (i.e. for the -DCHAR) case, but nothing like that for the enum class
with underlying type smaller than int.  And presumably the middle-end and
backends rely on this.


  parent reply	other threads:[~2014-09-19 14:10 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-08-19  6:27 [Bug c++/58192] New: " temporal at gmail dot com
2013-08-19  6:29 ` [Bug c++/58192] " temporal at gmail dot com
2013-08-19  6:38 ` temporal at gmail dot com
2013-08-19 16:49 ` temporal at gmail dot com
2013-08-19 16:59 ` paolo.carlini at oracle dot com
2013-08-19 18:09 ` jakub at gcc dot gnu.org
2014-09-18  9:20 ` paolo.carlini at oracle dot com
2014-09-18 10:01 ` jakub at gcc dot gnu.org
2014-09-19 12:10 ` ubizjak at gmail dot com
2014-09-19 13:07 ` ubizjak at gmail dot com
2014-09-19 14:10 ` jakub at gcc dot gnu.org [this message]
2014-12-15 14:30 ` ubizjak at gmail dot com
2014-12-15 14:55 ` hjl.tools at gmail dot com
2014-12-15 16:01 ` hjl.tools 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-58192-4-aPHAhjmIvA@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).