Bug 51995 - layout for long long bitfield wrong
Summary: layout for long long bitfield wrong
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: i386
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: David Lawrence
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2001-08-17 21:37 UTC by Arch D. Robison
Modified: 2007-04-18 16:36 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2002-12-15 17:34:00 UTC
Embargoed:


Attachments (Terms of Use)

Description Arch D. Robison 2001-08-17 21:37:42 UTC
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)

Description of problem:
The gcc with Linux 7.1 lays out long long bitfields in a way that is both 
incompatible with Linux 6.2, and just plain irrational.  Surely, changing 
a field of type T to a bitfield of type T should not make a structure 
larger.  A struct containing a char and a long long bitfield should occupy 
12 bytes: 1 for the char, 3 for padding, and 8 for the long long.

Version-Release number of selected component (if applicable):


How reproducible:
Always

Steps to Reproduce:
1. Compile program as shown in "Additional Information".
2. Run program.


Actual Results:  sizeof(PlainField)=12
sizeof(BitField  )=16


Expected Results:  sizeof(PlainField)=12
sizeof(BitField  )=12


Additional info:

$ cat b.C
#include <stdio.h>

typedef long long T;

struct PlainField {
    char c;
    T field;
};

struct BitField {
    char c;
    T field: 61;
};

int main() {
    printf("sizeof(PlainField)=%d\n", sizeof(PlainField));
    printf("sizeof(BitField  )=%d\n", sizeof(BitField));
    return 0;
}
$ gcc -v b.C
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.1 2.96-81)
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cpp0 -lang-c++ -D__GNUG__=2 -
D__EXCEPTIONS -v -D__GNUC__=2 -D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -
D__EL
F__ -Dunix -Dlinux -D__ELF__ -D__unix__ -D__linux__ -D__unix -D__linux -
Asystem(posix) -Acpu(i386) -Amachine(i386) -Di386 -D__i386 -D__i386__ -
D__tune
_i386__ b.C /usr/tmp/ccbx3Oxo.ii
GNU CPP version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (cpplib) (i386 
Linux/ELF)
ignoring nonexistent directory "/usr/local/include"
ignoring nonexistent directory "/usr/i386-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/g++-3
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/include
 /usr/include
End of search list.
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/cc1plus /usr/tmp/ccbx3Oxo.ii -
quiet -dumpbase b.C -version -o /usr/tmp/cckafkTF.s
GNU C++ version 2.96 20000731 (Red Hat Linux 7.1 2.96-81) (i386-redhat-
linux) compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.1 2.96-81).
 as -V -Qy -o /usr/tmp/cc9K0tF0.o /usr/tmp/cckafkTF.s
GNU assembler version 2.10.91 (i386-redhat-linux) using BFD version 
2.10.91.0.2
 /usr/lib/gcc-lib/i386-redhat-linux/2.96/collect2 -m elf_i386 -dynamic-
linker /lib/ld-linux.so.2 /usr/lib/gcc-lib/i386-redhat-
linux/2.96/../../../crt1
.o /usr/lib/gcc-lib/i386-redhat-linux/2.96/../../../crti.o /usr/lib/gcc-
lib/i386-redhat-linux/2.96/crtbegin.o -L/usr/lib/gcc-lib/i386-redhat-
linux/2.9
6 -L/usr/lib/gcc-lib/i386-redhat-linux/2.96/../../.. /usr/tmp/cc9K0tF0.o -
lgcc -lc -lgcc /usr/lib/gcc-lib/i386-redhat-
linux/2.96/crtend.o /usr/lib/gcc
-lib/i386-redhat-linux/2.96/../../../crtn.o
$ a.out
sizeof(PlainField)=12
sizeof(BitField  )=16
$

Comment 1 Alan Cox 2002-12-15 17:34:00 UTC
gcc 3.2 sorted all this out



Note You need to log in before you can comment on or make changes to this bug.