Bug 33810 - [4.1 Regression] gcc 4.1.2 mangles results on x86_64 in bitfield operations
Summary: [4.1 Regression] gcc 4.1.2 mangles results on x86_64 in bitfield operations
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.1.2
: P1 normal
Target Milestone: 4.2.0
Assignee: Not yet assigned to anyone
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2007-10-18 10:33 UTC by satyakaam Goswami
Modified: 2008-07-04 16:15 UTC (History)
6 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.6 4.2.3 4.3.0
Known to fail: 4.1.3
Last reconfirmed: 2008-01-13 03:10:24


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description satyakaam Goswami 2007-10-18 10:33:11 UTC
Run the test case on a x86_64 bit machine to see how gcc 4.1.2 mangles results in under Linux

We have tested the test case using 3.2.3 Compiler on RHEL 3 on both 32 as well as 64 bit OS it works well.

Compile the test case provided with the following steps

$gcc -g -I. -Wall -m64 -c bar.c
$g++ -g -I. -Wall -m64 -o foo foo.c bar.o

Actual results: once you run the program foo you will see the following result

foo: i is 3.
bar: i is 3221205968.

Expected results:

foo: i is 3.
bar: i is 3.

Additional info: Test Case follows


----- bar.h -----

typedef struct {

 unsigned b1:16;

 unsigned b2:16;

} foo;



#ifdef   __cplusplus

extern "C"

{

#endif



foo bar(unsigned);



#ifdef   __cplusplus

}

#endif




----- bar.c -----

#include <stdio.h>

#include <bar.h>



foo bar(unsigned i)

{

 foo myfoo;

 myfoo.b1=myfoo.b2=0;

 printf("bar: i is %u.\n",i);

 return(myfoo);

}





----- foo.c -----

#include <stdio.h>
#include <bar.h>

int main(void)

{

 foo myfoo;

 unsigned i = 3;

 printf("foo: i is %u.\n",i);

 myfoo = bar(i);

 return 0;

}
Comment 1 Wolfgang Bangerth 2008-01-13 03:10:24 UTC
Confirmed. Here's a slightly simplified testcase:
-----------bar.h------------
typedef struct {
    unsigned : 16;
    unsigned : 16;
} foo;
-----------bar.c------------
#include <stdio.h>
#include <bar.h>

foo bar(unsigned i)
{
  printf("bar: i is %u.\n",i);
  foo myfoo;
  return myfoo;
}
-------------foo.cc------------
#include <stdio.h>
#include <bar.h>

extern "C" foo bar(unsigned int);

int main(void)
{
  foo myfoo;
  unsigned i = 3;
  printf("foo: i is %u.\n",i);
  myfoo = bar(i);
  return 0;
}
-------------------
tmp/g> gcc -I. -c bar.c
tmp/g> g++ -I. -o foo foo.c bar.o
tmp/g> ./foo 
foo: i is 3.
bar: i is 1289971520.

Something appears to go wrong when calling the extern "C" function...

This is a wrong-code regression on valid code.

W.
Comment 2 Joseph S. Myers 2008-07-04 16:15:32 UTC
Closing 4.1 branch.