[PATCH] D21489: [codeview] Added support for bitfield type
David Majnemer via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 27 09:21:35 PDT 2016
majnemer added a comment.
In http://reviews.llvm.org/D21489#467653, @aaboud wrote:
> In http://reviews.llvm.org/D21489#467609, @majnemer wrote:
>
> > Consider this input:
> >
> > #pragma pack(1)
> > struct S {
> > char : 8;
> > short : 8;
> > short x : 8;
> > } s;
> >
> >
> > Your patch appears to give:
> >
> > BitField (0x1001) {
> > TypeLeafKind: LF_BITFIELD (0x1205)
> > Type: short (0x11)
> > BitSize: 8
> > BitOffset: 0
> > }
> > FieldList (0x1002) {
> > TypeLeafKind: LF_FIELDLIST (0x1203)
> > DataMember {
> > AccessSpecifier: Public (0x3)
> > Type: 0x1001
> > FieldOffset: 0x2
> > Name: x
> > }
> > }
> >
> >
> > MSVC gives:
> >
> > BitField (0x1001) {
> > TypeLeafKind: LF_BITFIELD (0x1205)
> > Type: short (0x11)
> > BitSize: 8
> > BitOffset: 8
> > }
> > FieldList (0x1002) {
> > TypeLeafKind: LF_FIELDLIST (0x1203)
> > DataMember {
> > AccessSpecifier: Public (0x3)
> > Type: 0x1001
> > FieldOffset: 0x1
> > Name: x
> > }
> > }
>
>
> You are right, this case is not handled correctly yet.
> However, this is because Clang (FE) does not provide the information, this is how LLVM IR looks like:
>
> !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 2, size: 24, align: 8, elements: !6, identifier: ".?AUS@@")
> !6 = !{!7}
> !7 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !5, file: !1, line: 5, baseType: !8, size: 8, align: 16, offset: 16)
> !8 = !DIBasicType(name: "short", size: 16, align: 16, encoding: DW_ATE_signed)
>
>
> and this how it should look like to fix the problem, once we make Clang emit the following the above code will work:
>
> !5 = distinct !DICompositeType(tag: DW_TAG_structure_type, name: "S", file: !1, line: 2, size: 24, align: 8, elements: !6, identifier: ".?AUS@@")
> !6 = !{!7, !9, 11}
> !7 = !DIDerivedType(tag: DW_TAG_member, scope: !5, file: !1, line: 3, baseType: !8, size: 8, align: 8, offset: 0)
> !8 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed)
> !9 = !DIDerivedType(tag: DW_TAG_member, scope: !5, file: !1, line: 4, baseType: !10, size: 8, align: 16, offset: 8)
> !10 = !DIBasicType(name: "short", size: 16, align: 16, encoding: DW_ATE_signed)
> !11 = !DIDerivedType(tag: DW_TAG_member, name: "x", scope: !5, file: !1, line: 5, baseType: !11, size: 8, align: 16, offset: 16)
>
>
> Then all we need to do, is not to emit members with no name, but to consider the size and alignment they consume.
I don't think this is a good idea. It would be far cheaper to encode the offset of the underlying allocation in the extraData.
http://reviews.llvm.org/D21489
More information about the llvm-commits
mailing list