public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rockeet at gmail dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/53505] New: bitfield with bool type generated broken object code
Date: Mon, 28 May 2012 08:00:00 -0000	[thread overview]
Message-ID: <bug-53505-4@http.gcc.gnu.org/bugzilla/> (raw)

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

             Bug #: 53505
           Summary: bitfield with bool type generated broken object code
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: rockeet@gmail.com


compiler flag: -Wall -Wextra -O[0|1|2|3|fast]

All optimization levels: 1,2,3,fast  reproduce the bug
-O0 is OK.

The expected output is 0

//================================================
$g++ -v
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/opt/libexec/gcc/x86_64-unknown-linux-gnu/4.7.0/lto-wrapper
Target: x86_64-unknown-linux-gnu
Configured with: ../gcc-4.7.0-RC-20120314/configure --prefix=/opt
--with-gmp=/opt --with-mpfr=/opt --with-mpc=/opt --with-ppl=/opt
--with-cloog=/opt --with-local-prefix=/opt --enable-languages=c,c++ :
(reconfigured) ../gcc-4.7.0-RC-20120314/configure --prefix=/opt --with-gmp=/opt
--with-mpfr=/opt --with-mpc=/opt --with-ppl=/opt --with-cloog=/opt
--with-local-prefix=/opt --enable-languages=c,c++,fortran
Thread model: posix
gcc version 4.7.0 20120314 (prerelease) (GCC)

//================================================
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <vector>

#if 1
    #define BIT bool // reproduce the bug
#else
    #define BIT unsigned // bug vanished
#endif

struct A {
    unsigned int  a;
    unsigned char c1, c2;
    BIT  b1 : 1;
    BIT  b2 : 1;
    BIT  b3 : 1;

    A() {
        memset(this, -1, sizeof(A));
        a = 0;
        c1 = c2 = 0;
        b1 = 0;
        b2 = 0;
        b3 = 0;
    }
};

void f(const std::vector<A>& v) {
    int s = 0;
    for (int i = 0, n = v.size(); i < n; ++i) {
        const A a = v[i]; // produce the bug
//    const A&a = v[i]; // bug vanished if 'a' is a const reference
        s += a.b1 ? 1 : 0;
    }
    printf("%d\n", s);
}

int main(int argc, char* argv[]) {
    size_t size = argc < 2 ? 100 : atoi(argv[1]);
    std::vector<A> v(size);
    f(v);
    return 0;
}


             reply	other threads:[~2012-05-28  7:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-28  8:00 rockeet at gmail dot com [this message]
2012-05-28 13:26 ` [Bug c++/53505] [4.7/4.8 Regression] bitfield with bool type generated broken object file jakub at gcc dot gnu.org
2012-05-28 13:39 ` jakub at gcc dot gnu.org
2012-05-28 14:00 ` jakub at gcc dot gnu.org
2012-05-28 14:11 ` jakub at gcc dot gnu.org
2012-05-28 14:29 ` jakub at gcc dot gnu.org
2012-05-28 14:36 ` jakub 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-53505-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).