public inbox for gcc-bugs@sourceware.org help / color / mirror / Atom feed
From: "eugene at hutorny dot in.ua" <gcc-bugzilla@gcc.gnu.org> To: gcc-bugs@gcc.gnu.org Subject: [Bug c/51568] New: Enum value is not extracted properly via a union Date: Thu, 15 Dec 2011 15:57:00 -0000 [thread overview] Message-ID: <bug-51568-4@http.gcc.gnu.org/bugzilla/> (raw) http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51568 Bug #: 51568 Summary: Enum value is not extracted properly via a union Classification: Unclassified Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: eugene@hutorny.in.ua Target: ARM Created attachment 26103 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=26103 Test example A wrong value is received when a value is assigned via union and read its member. Consider the following data structures: enum en { v0, v1, v2, v3, v4, v5, v6, v7 }; struct rec { unsigned short w; unsigned char c; enum en e; } __attribute__((__packed__)); union un { struct rec r; unsigned v; } __attribute__((__packed__)); void pass(unsigned v) { union un u; u.v = v; printf("r.w=%X r.c=%d r.e=%d\n", u.r.w, u.r.c, u.r.e ); } int main(int argc, char** argv) { union un u; u.r.c = '8'; u.r.e = v2; u.r.w = 0xC5FF; printf("r.w=%X r.c=%d r.e=%d\n", u.r.w, u.r.c, u.r.e ); pass(u.v); return 0; } Sample above compiled with gcc (Debian 4.3.2-1.1) 4.3.2 prints the following: r.w=C5FF r.c=56 r.e=2 r.w=C5FF r.c=56 r.e=34050 When compiled with arm-linux-gnueabi-gcc (Debian 4.3.2-1.1) 4.3.2 prints: r.w=C5FF r.c=56 r.e=2 r.w=C5FF r.c=56 r.e=50434
next reply other threads:[~2011-12-15 15:56 UTC|newest] Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top 2011-12-15 15:57 eugene at hutorny dot in.ua [this message] 2011-12-15 17:28 ` [Bug c/51568] " rearnsha at gcc dot gnu.org 2011-12-15 17:31 ` rearnsha at gcc dot gnu.org 2011-12-15 20:07 ` eugene at hutorny dot in.ua 2011-12-16 11:09 ` eugene at hutorny dot in.ua
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-51568-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: linkBe 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).