public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above
@ 2013-05-20 23:28 dhazeghi at yahoo dot com
  2013-05-21  6:32 ` [Bug rtl-optimization/57347] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: dhazeghi at yahoo dot com @ 2013-05-20 23:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 57347
           Summary: wrong code for bitfield on x86_64-linux at -Os and
                    above
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: dhazeghi at yahoo dot com

The following code is miscompiled on x86_64-linux with gcc trunk and 4.8 at -Os
and above optimization level.  It works correctly with gcc 4.7 (outputs 1).

$ gcc-trunk -v
gcc version 4.9.0 20130520 (experimental) [trunk revision 199099] (GCC) 
$ gcc-trunk -O1 wrong.c 
$ ./a.out 
1
$ gcc-4.7 -Os wrong.c 
$ ./a.out 
1
$ gcc-trunk -Os wrong.c 
$ ./a.out 
0
$

-----------------
int printf(const char *, ...);

struct S1 {
  int f0;
  int f1 : 10;
  int f2 : 13;
};

int i;
int *j = &i;

static void foo(struct S1 s) {
  int *p;
  int l[88];
  int **pp = &p;
  *pp = &l[1];
  l[0] = 1;
  *j = 1 && s.f2;
}

int main(void) {
  struct S1 s = { 0, 0, 1 };
  foo(s);
  printf("%d\n", i);
  return 0;
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/57347] [4.8/4.9 Regression] wrong code for bitfield on x86_64-linux at -Os and above
  2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
@ 2013-05-21  6:32 ` jakub at gcc dot gnu.org
  2013-05-21 12:26 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-21  6:32 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-05-21
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.8.1
            Summary|wrong code for bitfield on  |[4.8/4.9 Regression] wrong
                   |x86_64-linux at -Os and     |code for bitfield on
                   |above                       |x86_64-linux at -Os and
                   |                            |above
     Ever confirmed|0                           |1

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Started with r193298 .

struct S1 { int f0; int f1 : 10; int f2 : 13; };
int i;
int *j = &i;

static void
foo (struct S1 s)
{
  int *p;
  int l[88];
  int **pp = &p;
  *pp = &l[1];
  l[0] = 1;
  *j = 1 && s.f2;
}

int
main ()
{
  struct S1 s = { 0, 0, 1 };
  foo (s);
  if (i != 1)
    __builtin_abort ();
  return 0;
}


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/57347] [4.8/4.9 Regression] wrong code for bitfield on x86_64-linux at -Os and above
  2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
  2013-05-21  6:32 ` [Bug rtl-optimization/57347] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
@ 2013-05-21 12:26 ` jakub at gcc dot gnu.org
  2013-05-21 13:47 ` jamborm at gcc dot gnu.org
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-05-21 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jamborm at gcc dot gnu.org

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
I don't find code in http://gcc.gnu.org/ml/gcc-patches/2012-11/msg00460.html to
handle bitfields, the comment talks about punting on them, but I couldn't find
anything that would try to punt.
ipa_load_from_parm_agg_1 seems to return just the bit offset (which is then
compared to the offsets in aggval chain), but not the access bitsize (if aggval
is guaranteed to contain values for all fields, then perhaps with bitsize it
would be enough to look for all v where v->offset is in [offset,
offset+bitsize)
and combine all those values together - is v->value always constant?).


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug rtl-optimization/57347] [4.8/4.9 Regression] wrong code for bitfield on x86_64-linux at -Os and above
  2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
  2013-05-21  6:32 ` [Bug rtl-optimization/57347] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
  2013-05-21 12:26 ` jakub at gcc dot gnu.org
@ 2013-05-21 13:47 ` jamborm at gcc dot gnu.org
  2013-05-23 13:47 ` [Bug middle-end/57347] " jamborm at gcc dot gnu.org
  2013-05-23 13:47 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-05-21 13:47 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |jamborm at gcc dot gnu.org

--- Comment #3 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Right, even though IPA-CP was intended to ignore bit-fields, this
testcase shows there are quite good reasons to do so, but apparently I
somehow lost or forgot to add the code to actually check for this.

For 4.8 we do want to ignore bit-fields for sure.  And I'd argue that
we should do it on trunk too.  Once we implement the plan to lower
bit-fields early, jump functions will automatically start working on
bit-fields too.  Let me prepare a patch that adds the punting.


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/57347] [4.8/4.9 Regression] wrong code for bitfield on x86_64-linux at -Os and above
  2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
                   ` (3 preceding siblings ...)
  2013-05-23 13:47 ` [Bug middle-end/57347] " jamborm at gcc dot gnu.org
@ 2013-05-23 13:47 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-05-23 13:47 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Jambor <jamborm at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #6 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Author: jamborm
Date: Thu May 23 13:25:23 2013
New Revision: 199253

URL: http://gcc.gnu.org/viewcvs?rev=199253&root=gcc&view=rev
Log:
2013-05-23  Martin Jambor  <mjambor@suse.cz>

    PR middle-end/57347
    * tree.h (contains_bitfld_component_ref_p): Declare.
    * tree-sra.c (contains_bitfld_comp_ref_p): Move...
    * tree.c (contains_bitfld_component_ref_p): ...here.  Adjust its caller.
    * ipa-prop.c (determine_known_aggregate_parts): Check that LHS does
    not access a bit-field.  Assert all final offsets are byte-aligned.

testsuite/
    * gcc.dg/ipa/pr57347.c: New test.


Added:
    branches/gcc-4_8-branch/gcc/testsuite/gcc.dg/ipa/pr57347.c
Modified:
    branches/gcc-4_8-branch/gcc/ChangeLog
    branches/gcc-4_8-branch/gcc/ipa-prop.c
    branches/gcc-4_8-branch/gcc/testsuite/ChangeLog
    branches/gcc-4_8-branch/gcc/tree-sra.c
    branches/gcc-4_8-branch/gcc/tree.c
    branches/gcc-4_8-branch/gcc/tree.h


^ permalink raw reply	[flat|nested] 6+ messages in thread

* [Bug middle-end/57347] [4.8/4.9 Regression] wrong code for bitfield on x86_64-linux at -Os and above
  2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
                   ` (2 preceding siblings ...)
  2013-05-21 13:47 ` jamborm at gcc dot gnu.org
@ 2013-05-23 13:47 ` jamborm at gcc dot gnu.org
  2013-05-23 13:47 ` jamborm at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: jamborm at gcc dot gnu.org @ 2013-05-23 13:47 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Martin Jambor <jamborm at gcc dot gnu.org> ---
Author: jamborm
Date: Thu May 23 13:20:41 2013
New Revision: 199252

URL: http://gcc.gnu.org/viewcvs?rev=199252&root=gcc&view=rev
Log:
2013-05-22  Martin Jambor  <mjambor@suse.cz>

    PR middle-end/57347
    * tree.h (contains_bitfld_component_ref_p): Declare.
    * tree-sra.c (contains_bitfld_comp_ref_p): Move...
    * tree.c (contains_bitfld_component_ref_p): ...here.  Adjust its caller.
    * ipa-prop.c (determine_known_aggregate_parts): Check that LHS does
    not access a bit-field.  Assert all final offsets are byte-aligned.

testsuite/
    * gcc.dg/ipa/pr57347.c: New test.


Added:
    trunk/gcc/testsuite/gcc.dg/ipa/pr57347.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/ipa-prop.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/tree-sra.c
    trunk/gcc/tree.c
    trunk/gcc/tree.h


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2013-05-23 13:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-20 23:28 [Bug rtl-optimization/57347] New: wrong code for bitfield on x86_64-linux at -Os and above dhazeghi at yahoo dot com
2013-05-21  6:32 ` [Bug rtl-optimization/57347] [4.8/4.9 Regression] " jakub at gcc dot gnu.org
2013-05-21 12:26 ` jakub at gcc dot gnu.org
2013-05-21 13:47 ` jamborm at gcc dot gnu.org
2013-05-23 13:47 ` [Bug middle-end/57347] " jamborm at gcc dot gnu.org
2013-05-23 13:47 ` jamborm at gcc dot gnu.org

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).