public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/32346]  New: long long bitfield passed to int argument incorrectly
@ 2007-06-14 16:52 greened at obbligato dot org
  2007-06-14 20:48 ` [Bug c++/32346] " greened at obbligato dot org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: greened at obbligato dot org @ 2007-06-14 16:52 UTC (permalink / raw)
  To: gcc-bugs

A long long bitfield of size 32 is passed to a function taking an int argument
using two argument slots.  Adding an explicit cast solves the problem.

Testcase:

#include <stdio.h>

typedef struct {
   long long item : 32;
} tester;

void dosomething(int i, int j)
{
   printf("i = %#x, j = %#x\n", i, j);
}

void foo(tester bar)
{
   dosomething(bar.item, 0);
}

int main(void)
{
   tester test;
   test.item = 0xabcdef01;

   foo(test);

   return(0);
}

Asm:
        .align 2
.globl _Z3foo6tester
        .type   _Z3foo6tester, @function
_Z3foo6tester:
.LFB3:
        pushl   %ebp
.LCFI3:
        movl    %esp, %ebp
.LCFI4:
        subl    $24, %esp
.LCFI5:
        movl    8(%ebp), %eax
        movl    %eax, %edx
        sarl    $31, %edx
        movl    $0, 8(%esp)
        movl    %eax, (%esp)
        movl    %edx, 4(%esp)
        call    _Z11dosomethingii
        leave
        ret
.LFE3:
        .size   _Z3foo6tester, .-_Z3foo6tester

Output:

i = 0xabcdef01, j = 0xffffffff

With explicit cast:

void foo(tester bar)
{
   dosomething((int)bar.item, 0);
}

Asm:
        .align 2
.globl _Z3foo6tester
        .type   _Z3foo6tester, @function
_Z3foo6tester:
.LFB3:
        pushl   %ebp
.LCFI3:
        movl    %esp, %ebp
.LCFI4:
        subl    $8, %esp
.LCFI5:
        movl    8(%ebp), %eax
        movl    $0, 4(%esp)
        movl    %eax, (%esp)
        call    _Z11dosomethingii
        leave
        ret
.LFE3:
        .size   _Z3foo6tester, .-_Z3foo6tester

Output:

i = 0xabcdef01, j = 0


-- 
           Summary: long long bitfield passed to int argument incorrectly
           Product: gcc
           Version: 4.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: greened at obbligato dot org
 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=32346


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

* [Bug c++/32346] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
@ 2007-06-14 20:48 ` greened at obbligato dot org
  2007-06-14 20:50 ` greened at obbligato dot org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: greened at obbligato dot org @ 2007-06-14 20:48 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from greened at obbligato dot org  2007-06-14 20:48 -------
Created an attachment (id=13705)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=13705&action=view)
Preprocessed testcase


-- 


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


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

* [Bug c++/32346] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
  2007-06-14 20:48 ` [Bug c++/32346] " greened at obbligato dot org
@ 2007-06-14 20:50 ` greened at obbligato dot org
  2007-07-24 19:59 ` greened at obbligato dot org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: greened at obbligato dot org @ 2007-06-14 20:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from greened at obbligato dot org  2007-06-14 20:50 -------
Configuration:

g++ -v
Using built-in specs.
Target: i686-pc-linux-gnu
Configured with: /tools/gcc-4.2.0/configure --prefix=/tools/i686-pc-linux-gnu
--disable-shared --with-gnu-as --with-gnu-ld
--with-build-time-tools=/tools/i686-pc-linux-gnu/bin
--with-mpfr=/tools/i686-pc-linux-gnu --with-gmp=/tools/i686-pc-linux-gnu
--enable-targets=all
Thread model: posix
gcc version 4.2.0

This only fails with g++.  gcc compiles it fine.


-- 

greened at obbligato dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |greened at obbligato dot org


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


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

* [Bug c++/32346] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
  2007-06-14 20:48 ` [Bug c++/32346] " greened at obbligato dot org
  2007-06-14 20:50 ` greened at obbligato dot org
@ 2007-07-24 19:59 ` greened at obbligato dot org
  2007-07-25 19:47 ` greened at obbligato dot org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: greened at obbligato dot org @ 2007-07-24 19:59 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from greened at obbligato dot org  2007-07-24 19:59 -------
This is also broken in 4.2.1.


-- 


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


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

* [Bug c++/32346] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (2 preceding siblings ...)
  2007-07-24 19:59 ` greened at obbligato dot org
@ 2007-07-25 19:47 ` greened at obbligato dot org
  2007-07-26  9:58 ` [Bug c++/32346] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: greened at obbligato dot org @ 2007-07-25 19:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from greened at obbligato dot org  2007-07-25 19:47 -------
It is also broken on trunk.


-- 


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


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

* [Bug c++/32346] [4.2/4.3 Regression] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (3 preceding siblings ...)
  2007-07-25 19:47 ` greened at obbligato dot org
@ 2007-07-26  9:58 ` rguenth at gcc dot gnu dot org
  2007-07-26 23:28 ` mmitchel at gcc dot gnu dot org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2007-07-26  9:58 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #5 from rguenth at gcc dot gnu dot org  2007-07-26 09:58 -------
Confirmed.  This is caused by

2007-04-17  Mark Mitchell  <mark@codesourcery.com>

        PR c++/31513
        * call.c (convert_for_arg_passing): Convert bitfields to their
        declared types.

which causes us to expand

  dosomething ((long long int) bar.item, 0)

as convert_for_arg_passing does not demote types.  The patch didn't went to
the 4.1 branch and I cannot reproduce the failure there.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |rguenth at gcc dot gnu dot
                   |                            |org, mark at codesourcery
                   |                            |dot com
OtherBugsDependingO|                            |31513
              nThis|                            |
             Status|UNCONFIRMED                 |NEW
     Ever Confirmed|0                           |1
           Keywords|                            |wrong-code
      Known to fail|                            |4.2.0 4.2.1 4.3.0
      Known to work|                            |4.1.2
   Last reconfirmed|0000-00-00 00:00:00         |2007-07-26 09:58:28
               date|                            |
            Summary|long long bitfield passed to|[4.2/4.3 Regression] long
                   |int argument incorrectly    |long bitfield passed to int
                   |                            |argument incorrectly
   Target Milestone|---                         |4.2.2


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


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

* [Bug c++/32346] [4.2/4.3 Regression] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (4 preceding siblings ...)
  2007-07-26  9:58 ` [Bug c++/32346] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2007-07-26 23:28 ` mmitchel at gcc dot gnu dot org
  2007-07-27 17:13 ` mmitchel at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-07-26 23:28 UTC (permalink / raw)
  To: gcc-bugs



-- 

mmitchel at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |mmitchel at gcc dot gnu dot
                   |dot org                     |org
             Status|NEW                         |ASSIGNED
   Last reconfirmed|2007-07-26 09:58:28         |2007-07-26 23:28:16
               date|                            |


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


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

* [Bug c++/32346] [4.2/4.3 Regression] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (5 preceding siblings ...)
  2007-07-26 23:28 ` mmitchel at gcc dot gnu dot org
@ 2007-07-27 17:13 ` mmitchel at gcc dot gnu dot org
  2007-07-27 21:46 ` mmitchel at gcc dot gnu dot org
  2007-07-27 23:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-07-27 17:13 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #6 from mmitchel at gcc dot gnu dot org  2007-07-27 17:13 -------
Subject: Bug 32346

Author: mmitchel
Date: Fri Jul 27 17:13:29 2007
New Revision: 126986

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126986
Log:
        PR c++/32346
        * call.c (convert_for_arg_passing): Only widen bitfields to their
        declared types if necessary.
        PR c++/32346
        * g++.dg/expr/bitfield9.C: New test.

Added:
    trunk/gcc/testsuite/g++.dg/expr/bitfield9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/32346] [4.2/4.3 Regression] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (6 preceding siblings ...)
  2007-07-27 17:13 ` mmitchel at gcc dot gnu dot org
@ 2007-07-27 21:46 ` mmitchel at gcc dot gnu dot org
  2007-07-27 23:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-07-27 21:46 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #7 from mmitchel at gcc dot gnu dot org  2007-07-27 21:46 -------
Subject: Bug 32346

Author: mmitchel
Date: Fri Jul 27 21:46:33 2007
New Revision: 126999

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=126999
Log:
        PR c++/32346
        * call.c (convert_for_arg_passing): Only widen bitfields to their
        declared types if necessary.
        PR c++/32346
        * g++.dg/expr/bitfield9.C: New test.

Added:
    branches/gcc-4_2-branch/gcc/testsuite/g++.dg/expr/bitfield9.C
Modified:
    branches/gcc-4_2-branch/gcc/cp/ChangeLog
    branches/gcc-4_2-branch/gcc/cp/call.c
    branches/gcc-4_2-branch/gcc/testsuite/ChangeLog


-- 


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


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

* [Bug c++/32346] [4.2/4.3 Regression] long long bitfield passed to int argument incorrectly
  2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
                   ` (7 preceding siblings ...)
  2007-07-27 21:46 ` mmitchel at gcc dot gnu dot org
@ 2007-07-27 23:25 ` mmitchel at gcc dot gnu dot org
  8 siblings, 0 replies; 10+ messages in thread
From: mmitchel at gcc dot gnu dot org @ 2007-07-27 23:25 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #8 from mmitchel at gcc dot gnu dot org  2007-07-27 23:24 -------
Fixed in 4.2.2.


-- 

mmitchel at gcc dot gnu dot org changed:

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


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


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

end of thread, other threads:[~2007-07-27 23:25 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-06-14 16:52 [Bug c++/32346] New: long long bitfield passed to int argument incorrectly greened at obbligato dot org
2007-06-14 20:48 ` [Bug c++/32346] " greened at obbligato dot org
2007-06-14 20:50 ` greened at obbligato dot org
2007-07-24 19:59 ` greened at obbligato dot org
2007-07-25 19:47 ` greened at obbligato dot org
2007-07-26  9:58 ` [Bug c++/32346] [4.2/4.3 Regression] " rguenth at gcc dot gnu dot org
2007-07-26 23:28 ` mmitchel at gcc dot gnu dot org
2007-07-27 17:13 ` mmitchel at gcc dot gnu dot org
2007-07-27 21:46 ` mmitchel at gcc dot gnu dot org
2007-07-27 23:25 ` mmitchel at gcc dot gnu dot 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).