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

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