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.
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(
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);
}
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] = {
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);
--- /dev/null
+// 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]])