LLVM Bugzilla is read-only and represents the historical archive of all LLVM issues filled before November 26, 2021. Use github to submit LLVM bugs

Bug 1420 - llvm-gcc asserts on address of field in bit field structure
Summary: llvm-gcc asserts on address of field in bit field structure
Status: RESOLVED FIXED
Alias: None
Product: tools
Classification: Unclassified
Component: llvm-gcc (show other bugs)
Version: trunk
Hardware: PC Linux
: P normal
Assignee: Unassigned LLVM Bugs
URL:
Keywords: compile-fail
Depends on:
Blocks:
 
Reported: 2007-05-15 01:48 PDT by Reid Spencer
Modified: 2007-11-19 11:01 PST (History)
3 users (show)

See Also:
Fixed By Commit(s):


Attachments
Test case for this problem. (815 bytes, text/plain)
2007-05-15 10:45 PDT, Reid Spencer
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Reid Spencer 2007-05-15 01:48:30 PDT
The following transcript shows llvm-gcc failing on input that gcc 4.0.4 compiles
correctly.

[reid@bashful C++Frontend]$ cat 2007-05-15-FieldAccess.cpp
#include <stdio.h>

class bitFieldStruct {
  public:
    int i;
    unsigned char c:7;
    int s:17;
    char c2;
};

int main()
{
  printf("sizeof(bitFieldStruct) == %d\n", sizeof(bitFieldStruct));

  if (sizeof(bitFieldStruct) != 2 * sizeof(int))
    printf("bitFieldStruct should be %d but is %d \n",
            2 * sizeof(int), sizeof(bitFieldStruct));

  bitFieldStruct x;

  char* xip = (char*) &x.i;
  char* xc2p = (char*) &x.c2;
  printf("Offset bitFieldStruct.i = %d\n", xip - xip);
  printf("Offset bitFieldStruct.c2 = %d\n", xc2p - xip);

  return 0;
}
[reid@bashful C++Frontend]$ /proj/llvm/cfe/install-2/bin/llvm-gcc -o doit
2007-05-15-FieldAccess.cpp -lstdc++
cc1plus: ../../src-2/gcc/llvm-convert.cpp:5583: LValue
TreeToLLVM::EmitLV_COMPONENT_REF(tree_node*): Assertion `BitStart == 0 && "It's
a bitfield reference or we didn't get to the field!"' failed.
2007-05-15-FieldAccess.cpp: In function 'int main()':
2007-05-15-FieldAccess.cpp:18: internal compiler error: Aborted

[reid@bashful C++Frontend]$ gcc -o doit 2007-05-15-FieldAccess.cpp -lstdc++
[reid@bashful C++Frontend]$ ./doit
sizeof(bitFieldStruct) == 8
Offset bitFieldStruct.i = 0
Offset bitFieldStruct.c2 = 7
Comment 1 Reid Spencer 2007-05-15 01:53:44 PDT
Test case is in test/C++Frontend/2007-05-15-FieldAcces.cpp

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20070514/049620.html
Comment 2 Reid Spencer 2007-05-15 02:02:02 PDT
From Duncan Sands:
IMHO both assertions are symptoms of ConvertRECORD breakage.

Duncan also reported this assertion:
   LLVM type size doesn't match GCC type size!
on a similar test case.
Comment 3 Reid Spencer 2007-05-15 10:45:57 PDT
Created attachment 844 [details]
Test case for this problem.

This is a deja-gnu ready test case, the same as in the initial comment on this
PR.
Comment 4 Chris Lattner 2007-05-15 13:01:40 PDT
Also, when fixed, the testcase should go in llvm-test, not dejagnu.
Comment 5 Reid Spencer 2007-05-15 17:35:09 PDT
I can make the test case deja-gnu compatible (doesn't execute). I'll do this
sometime soonish.
Comment 6 Chris Lattner 2007-05-23 01:19:21 PDT
maybe Duncan has an idea about this one
Comment 7 Devang Patel 2007-05-23 01:36:28 PDT
Here, the 32bit int field is used for 'c' and 's'. However it has enough bits (8) available for 'c2', so there is 
not any need to allocate another field.
Comment 8 Duncan Sands 2007-11-19 11:01:51 PST
This compiles to something sensible looking with llvm-gcc-4.2.