public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "siarhei dot siamashka at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug regression/32687]  New: Invalid code generation for reading signed negative bitfield value (g++ optimization)
Date: Mon, 09 Jul 2007 06:18:00 -0000	[thread overview]
Message-ID: <bug-32687-14457@http.gcc.gnu.org/bugzilla/> (raw)

Reading signed bitfield value when it needs to be extended to larger type (for
example assigning 24-bit value to int) results in zero extending instead of
sign extending when compiled with g++ using optimizations (-O1 or higher).
Compiling the same code with gcc or disabling optimizations makes the problem
disappear.

The following code reproduces the problem:

#include <stdio.h>

struct TEST_STRUCT
{
    int f_8  : 8;
    int f_24 : 24;
};

int main ()
{
    struct TEST_STRUCT x;
    int a = -123;
    x.f_24 = a;

    printf("a=%d (%08X)\n", (int)a, (int)a);
    printf("x.f_24=%d (%08X)\n", (int)x.f_24, (int)x.f_24);

    if ((int)x.f_24 != (int)a)
        printf("test failed\n");
    else
        printf("test ok\n");
    return 0;
}

////////////////////////////////

Expected correct result:
a=-123 (FFFFFF85)
x.f_24=-123 (FFFFFF85)
test ok

Faulty result:
a=-123 (FFFFFF85)
x.f_24=16777093 (00FFFF85)
test failed

It is a regression as gcc 3.4.6 did not have this bug. Also this problem may be
related to http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32346 and
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30332


-- 
           Summary: Invalid code generation for reading signed negative
                    bitfield value (g++ optimization)
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: regression
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: siarhei dot siamashka at gmail dot com
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


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


             reply	other threads:[~2007-07-09  6:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-07-09  6:18 siarhei dot siamashka at gmail dot com [this message]
2007-07-09  7:18 ` [Bug c++/32687] " pinskia at gcc dot gnu dot org
2007-07-11  7:06 ` siarhei dot siamashka at gmail dot com
2008-11-14  0:22 ` jason at gcc dot gnu dot 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-32687-14457@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).