Re: [PATCH] D21783: [CodeView] Implement support for bitfields in Clang
This revision was automatically updated to reflect the committed changes. Closed by commit rL274201: [CodeView] Implement support for bitfields in Clang (authored by majnemer). Changed prior to commit: http://reviews.llvm.org/D21783?vs=62095=62333#toc Repository: rL LLVM http://reviews.llvm.org/D21783 Files: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp cfe/trunk/lib/CodeGen/CGDebugInfo.h cfe/trunk/test/CodeGen/debug-info-packed-struct.c cfe/trunk/test/CodeGenCXX/debug-info-ms-bitfields.cpp Index: cfe/trunk/test/CodeGen/debug-info-packed-struct.c === --- cfe/trunk/test/CodeGen/debug-info-packed-struct.c +++ cfe/trunk/test/CodeGen/debug-info-packed-struct.c @@ -21,7 +21,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8", // CHECK-SAME: {{.*}}size: 64, align: 64, offset: 64) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128, flags: DIFlagBitField, extraData: i64 128) // - @@ -40,7 +40,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) // - @@ -61,7 +61,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) @@ -83,7 +83,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4", // CHECK-SAME: {{.*}}size: 64, align: 32, offset: 32) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96, flags: DIFlagBitField, extraData: i64 96) struct layout0 l0; struct layout1 l1; Index: cfe/trunk/test/CodeGenCXX/debug-info-ms-bitfields.cpp === --- cfe/trunk/test/CodeGenCXX/debug-info-ms-bitfields.cpp +++ cfe/trunk/test/CodeGenCXX/debug-info-ms-bitfields.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-pc-win32 -debug-info-kind=limited -gcodeview %s -emit-llvm -o - | FileCheck %s + +#pragma pack(1) +struct S { + char : 8; + short : 8; + short x : 8; +} s; + +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x", {{.*}}, size: 8, align: 16, offset: 16, flags: DIFlagBitField, extraData: i64 8) Index: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp === --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp @@ -13,6 +13,7 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" +#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" #include "CodeGenFunction.h" @@ -905,10 +906,38 @@ llvm_unreachable("unexpected access enumerator"); } -llvm::DIType *CGDebugInfo::createFieldType( -StringRef name, QualType type, uint64_t sizeInBitsOverride, -SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, -llvm::DIFile *tunit, llvm::DIScope *scope, const RecordDecl *RD) { +llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, + llvm::DIScope *RecordTy, + const RecordDecl *RD) { + StringRef Name = BitFieldDecl->getName(); + QualType Ty = BitFieldDecl->getType(); + SourceLocation Loc = BitFieldDecl->getLocation(); + llvm::DIFile *VUnit = getOrCreateFile(Loc); + llvm::DIType *DebugType = getOrCreateType(Ty, VUnit); + + // Get the location for the field. + llvm::DIFile *File = getOrCreateFile(Loc); + unsigned Line = getLineNumber(Loc); + + const CGBitFieldInfo = + CGM.getTypes().getCGRecordLayout(RD).getBitFieldInfo(BitFieldDecl); + uint64_t SizeInBits = BitFieldInfo.Size; + assert(SizeInBits > 0 && "found named 0-width bitfield"); + unsigned AlignInBits = CGM.getContext().getTypeAlign(Ty); + uint64_t StorageOffsetInBits = + CGM.getContext().toBits(BitFieldInfo.StorageOffset); + uint64_t OffsetInBits = StorageOffsetInBits + BitFieldInfo.Offset; + unsigned Flags = getAccessFlag(BitFieldDecl->getAccess(), RD); + return DBuilder.createBitFieldMemberType( + RecordTy, Name, File, Line, SizeInBits, AlignInBits, OffsetInBits, + StorageOffsetInBits, Flags, DebugType); +} + +llvm::DIType *
Re: [PATCH] D21783: [CodeView] Implement support for bitfields in Clang
rnk accepted this revision. rnk added a comment. lgtm Cute, preserves debug info compatibility at the cost of some complexity. http://reviews.llvm.org/D21783 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21783: [CodeView] Implement support for bitfields in Clang
aaboud accepted this revision. aaboud added a comment. This revision is now accepted and ready to land. LGTM. Please update PR28162. http://reviews.llvm.org/D21783 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
Re: [PATCH] D21783: [CodeView] Implement support for bitfields in Clang
majnemer updated this revision to Diff 62095. majnemer added a comment. - Address review comments http://reviews.llvm.org/D21783 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGen/debug-info-packed-struct.c test/CodeGenCXX/debug-info-ms-bitfields.cpp Index: test/CodeGenCXX/debug-info-ms-bitfields.cpp === --- /dev/null +++ test/CodeGenCXX/debug-info-ms-bitfields.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-pc-win32 -debug-info-kind=limited -gcodeview %s -emit-llvm -o - | FileCheck %s + +#pragma pack(1) +struct S { + char : 8; + short : 8; + short x : 8; +} s; + +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x", {{.*}}, size: 8, align: 16, offset: 16, flags: DIFlagBitField, extraData: i64 8) Index: test/CodeGen/debug-info-packed-struct.c === --- test/CodeGen/debug-info-packed-struct.c +++ test/CodeGen/debug-info-packed-struct.c @@ -21,7 +21,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8", // CHECK-SAME: {{.*}}size: 64, align: 64, offset: 64) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128, flags: DIFlagBitField, extraData: i64 128) // - @@ -40,7 +40,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) // - @@ -61,7 +61,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) @@ -83,7 +83,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4", // CHECK-SAME: {{.*}}size: 64, align: 32, offset: 32) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96, flags: DIFlagBitField, extraData: i64 96) struct layout0 l0; struct layout1 l1; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -232,11 +232,16 @@ llvm::DIFile *F); llvm::DIType *createFieldType(StringRef name, QualType type, -uint64_t sizeInBitsOverride, SourceLocation loc, -AccessSpecifier AS, uint64_t offsetInBits, -llvm::DIFile *tunit, llvm::DIScope *scope, +SourceLocation loc, AccessSpecifier AS, +uint64_t offsetInBits, llvm::DIFile *tunit, +llvm::DIScope *scope, const RecordDecl *RD = nullptr); + /// Create new bit field member. + llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl, + llvm::DIScope *RecordTy, + const RecordDecl *RD); + /// Helpers for collecting fields of a record. /// @{ void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,6 +13,7 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" +#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" #include "CodeGenFunction.h" @@ -905,10 +906,38 @@ llvm_unreachable("unexpected access enumerator"); } -llvm::DIType *CGDebugInfo::createFieldType( -StringRef name, QualType type, uint64_t sizeInBitsOverride, -SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, -llvm::DIFile *tunit, llvm::DIScope *scope, const RecordDecl *RD) { +llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, + llvm::DIScope *RecordTy, + const RecordDecl *RD) { + StringRef Name = BitFieldDecl->getName(); + QualType Ty = BitFieldDecl->getType(); + SourceLocation Loc = BitFieldDecl->getLocation(); + llvm::DIFile *VUnit = getOrCreateFile(Loc); + llvm::DIType *DebugType = getOrCreateType(Ty, VUnit); + + // Get the location for the
Re: [PATCH] D21783: [CodeView] Implement support for bitfields in Clang
aaboud added a comment. Looks good, one minor comments below. Comment at: lib/CodeGen/CGDebugInfo.h:243 @@ +242,3 @@ + llvm::DIScope *RecordTy, + const RecordDecl *RD, SourceLocation Loc); + You have a mismatch between definition and this declaration, definition does not take SourceLocation parameter! http://reviews.llvm.org/D21783 ___ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[PATCH] D21783: [CodeView] Implement support for bitfields in Clang
majnemer created this revision. majnemer added reviewers: rnk, aaboud. majnemer added a subscriber: cfe-commits. Emit the underlying storage offset in addition to the starting bit position of the field. http://reviews.llvm.org/D21783 Files: lib/CodeGen/CGDebugInfo.cpp lib/CodeGen/CGDebugInfo.h test/CodeGen/debug-info-packed-struct.c test/CodeGenCXX/debug-info-ms-bitfields.cpp Index: test/CodeGenCXX/debug-info-ms-bitfields.cpp === --- /dev/null +++ test/CodeGenCXX/debug-info-ms-bitfields.cpp @@ -0,0 +1,10 @@ +// RUN: %clang_cc1 -triple x86_64-pc-win32 -debug-info-kind=limited -gcodeview %s -emit-llvm -o - | FileCheck %s + +#pragma pack(1) +struct S { + char : 8; + short : 8; + short x : 8; +} s; + +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "x", {{.*}}, size: 8, align: 16, offset: 16, flags: DIFlagBitField, extraData: i64 8) Index: test/CodeGen/debug-info-packed-struct.c === --- test/CodeGen/debug-info-packed-struct.c +++ test/CodeGen/debug-info-packed-struct.c @@ -21,7 +21,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs8", // CHECK-SAME: {{.*}}size: 64, align: 64, offset: 64) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l0_ofs16", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 128, flags: DIFlagBitField, extraData: i64 128) // - @@ -40,7 +40,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l1_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) // - @@ -61,7 +61,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs1", // CHECK-SAME: {{.*}}size: 64, align: 8, offset: 8) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l2_ofs9", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 72, flags: DIFlagBitField, extraData: i64 72) @@ -83,7 +83,7 @@ // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs4", // CHECK-SAME: {{.*}}size: 64, align: 32, offset: 32) // CHECK: !DIDerivedType(tag: DW_TAG_member, name: "l3_ofs12", -// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96) +// CHECK-SAME: {{.*}}size: 1, align: 32, offset: 96, flags: DIFlagBitField, extraData: i64 96) struct layout0 l0; struct layout1 l1; Index: lib/CodeGen/CGDebugInfo.h === --- lib/CodeGen/CGDebugInfo.h +++ lib/CodeGen/CGDebugInfo.h @@ -232,11 +232,16 @@ llvm::DIFile *F); llvm::DIType *createFieldType(StringRef name, QualType type, -uint64_t sizeInBitsOverride, SourceLocation loc, -AccessSpecifier AS, uint64_t offsetInBits, -llvm::DIFile *tunit, llvm::DIScope *scope, +SourceLocation loc, AccessSpecifier AS, +uint64_t offsetInBits, llvm::DIFile *tunit, +llvm::DIScope *scope, const RecordDecl *RD = nullptr); + /// Create new bit field member. + llvm::DIType *createBitFieldType(const FieldDecl *BitFieldDecl, + llvm::DIScope *RecordTy, + const RecordDecl *RD, SourceLocation Loc); + /// Helpers for collecting fields of a record. /// @{ void CollectRecordLambdaFields(const CXXRecordDecl *CXXDecl, Index: lib/CodeGen/CGDebugInfo.cpp === --- lib/CodeGen/CGDebugInfo.cpp +++ lib/CodeGen/CGDebugInfo.cpp @@ -13,6 +13,7 @@ #include "CGDebugInfo.h" #include "CGBlocks.h" +#include "CGRecordLayout.h" #include "CGCXXABI.h" #include "CGObjCRuntime.h" #include "CodeGenFunction.h" @@ -905,10 +906,38 @@ llvm_unreachable("unexpected access enumerator"); } -llvm::DIType *CGDebugInfo::createFieldType( -StringRef name, QualType type, uint64_t sizeInBitsOverride, -SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, -llvm::DIFile *tunit, llvm::DIScope *scope, const RecordDecl *RD) { +llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, + llvm::DIScope *RecordTy, + const RecordDecl *RD) { + StringRef Name = BitFieldDecl->getName(); + QualType Ty = BitFieldDecl->getType(); + SourceLocation Loc = BitFieldDecl->getLocation(); +