Author: Yonghong Song Date: 2021-08-20T12:52:51-07:00 New Revision: 5ca7131eb369949ee3adf2d3a562bf7e56ca7422
URL: https://github.com/llvm/llvm-project/commit/5ca7131eb369949ee3adf2d3a562bf7e56ca7422 DIFF: https://github.com/llvm/llvm-project/commit/5ca7131eb369949ee3adf2d3a562bf7e56ca7422.diff LOG: [DebugInfo] convert btf_tag attrs to DI annotations for record fields Generate btf_tag annotations for record fields. The annotations are represented as an DINodeArray in DebugInfo. Differential Revision: https://reviews.llvm.org/D106616 Added: clang/test/CodeGen/attr-btf_tag-field.c Modified: clang/lib/CodeGen/CGDebugInfo.cpp clang/lib/CodeGen/CGDebugInfo.h Removed: ################################################################################ diff --git a/clang/lib/CodeGen/CGDebugInfo.cpp b/clang/lib/CodeGen/CGDebugInfo.cpp index 967fa7f1493a..989945a1b4ff 100644 --- a/clang/lib/CodeGen/CGDebugInfo.cpp +++ b/clang/lib/CodeGen/CGDebugInfo.cpp @@ -1377,16 +1377,16 @@ llvm::DIType *CGDebugInfo::createBitFieldType(const FieldDecl *BitFieldDecl, Offset = BitFieldInfo.StorageSize - BitFieldInfo.Size - Offset; uint64_t OffsetInBits = StorageOffsetInBits + Offset; llvm::DINode::DIFlags Flags = getAccessFlag(BitFieldDecl->getAccess(), RD); + llvm::DINodeArray Annotations = CollectBTFTagAnnotations(BitFieldDecl); return DBuilder.createBitFieldMemberType( RecordTy, Name, File, Line, SizeInBits, OffsetInBits, StorageOffsetInBits, - Flags, DebugType); + Flags, DebugType, Annotations); } -llvm::DIType * -CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc, - AccessSpecifier AS, uint64_t offsetInBits, - uint32_t AlignInBits, llvm::DIFile *tunit, - llvm::DIScope *scope, const RecordDecl *RD) { +llvm::DIType *CGDebugInfo::createFieldType( + StringRef name, QualType type, SourceLocation loc, AccessSpecifier AS, + uint64_t offsetInBits, uint32_t AlignInBits, llvm::DIFile *tunit, + llvm::DIScope *scope, const RecordDecl *RD, llvm::DINodeArray Annotations) { llvm::DIType *debugType = getOrCreateType(type, tunit); // Get the location for the field. @@ -1404,7 +1404,7 @@ CGDebugInfo::createFieldType(StringRef name, QualType type, SourceLocation loc, llvm::DINode::DIFlags flags = getAccessFlag(AS, RD); return DBuilder.createMemberType(scope, name, file, line, SizeInBits, Align, - offsetInBits, flags, debugType); + offsetInBits, flags, debugType, Annotations); } void CGDebugInfo::CollectRecordLambdaFields( @@ -1494,9 +1494,10 @@ void CGDebugInfo::CollectRecordNormalField( FieldType = createBitFieldType(field, RecordTy, RD); } else { auto Align = getDeclAlignIfRequired(field, CGM.getContext()); + llvm::DINodeArray Annotations = CollectBTFTagAnnotations(field); FieldType = createFieldType(name, type, field->getLocation(), field->getAccess(), - OffsetInBits, Align, tunit, RecordTy, RD); + OffsetInBits, Align, tunit, RecordTy, RD, Annotations); } elements.push_back(FieldType); @@ -2064,6 +2065,9 @@ llvm::DINodeArray CGDebugInfo::CollectCXXTemplateParams( } llvm::DINodeArray CGDebugInfo::CollectBTFTagAnnotations(const Decl *D) { + if (!D->hasAttr<BTFTagAttr>()) + return nullptr; + SmallVector<llvm::Metadata *, 4> Annotations; for (const auto *I : D->specific_attrs<BTFTagAttr>()) { llvm::Metadata *Ops[2] = { @@ -3446,10 +3450,7 @@ llvm::DICompositeType *CGDebugInfo::CreateLimitedType(const RecordType *Ty) { Flags |= llvm::DINode::FlagExportSymbols; } - llvm::DINodeArray Annotations = nullptr; - if (D->hasAttr<BTFTagAttr>()) - Annotations = CollectBTFTagAnnotations(D); - + llvm::DINodeArray Annotations = CollectBTFTagAnnotations(D); llvm::DICompositeType *RealDecl = DBuilder.createReplaceableCompositeType( getTagForRecord(RD), RDName, RDContext, DefUnit, Line, 0, Size, Align, Flags, Identifier, Annotations); diff --git a/clang/lib/CodeGen/CGDebugInfo.h b/clang/lib/CodeGen/CGDebugInfo.h index c0674b4511c7..0d22accb93b6 100644 --- a/clang/lib/CodeGen/CGDebugInfo.h +++ b/clang/lib/CodeGen/CGDebugInfo.h @@ -299,7 +299,8 @@ class CGDebugInfo { SourceLocation loc, AccessSpecifier AS, uint64_t offsetInBits, uint32_t AlignInBits, llvm::DIFile *tunit, llvm::DIScope *scope, - const RecordDecl *RD = nullptr); + const RecordDecl *RD = nullptr, + llvm::DINodeArray Annotations = nullptr); llvm::DIType *createFieldType(StringRef name, QualType type, SourceLocation loc, AccessSpecifier AS, diff --git a/clang/test/CodeGen/attr-btf_tag-field.c b/clang/test/CodeGen/attr-btf_tag-field.c new file mode 100644 index 000000000000..93ba6419b12e --- /dev/null +++ b/clang/test/CodeGen/attr-btf_tag-field.c @@ -0,0 +1,27 @@ +// REQUIRES: x86-registered-target +// RUN: %clang -target x86_64 -g -S -emit-llvm -o - %s | FileCheck %s + +#define __tag1 __attribute__((btf_tag("tag1"))) +#define __tag2 __attribute__((btf_tag("tag2"))) + +struct t1 { + int a __tag1 __tag2; +}; + +int foo(struct t1 *arg) { + return arg->a; +} + +struct t2 { + int b:1 __tag1 __tag2; +}; + +int foo2(struct t2 *arg) { + return arg->b; +} +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "a", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[#]], size: 32, annotations: ![[ANNOT:[0-9]+]]) +// CHECK: ![[ANNOT]] = !{![[TAG1:[0-9]+]], ![[TAG2:[0-9]+]]} +// CHECK: ![[TAG1]] = !{!"btf_tag", !"tag1"} +// CHECK: ![[TAG2]] = !{!"btf_tag", !"tag2"} + +// CHECK: !DIDerivedType(tag: DW_TAG_member, name: "b", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[#]], size: 1, flags: DIFlagBitField, extraData: i64 0, annotations: ![[ANNOT]]) _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits