diff --git a/clang/include/clang/AST/ASTContext.h b/clang/include/clang/AST/ASTContext.h --- a/clang/include/clang/AST/ASTContext.h +++ b/clang/include/clang/AST/ASTContext.h @@ -1590,7 +1590,8 @@ QualType getAttributedType(attr::Kind attrKind, QualType modifiedType, - QualType equivalentType); + QualType equivalentType, + StringRef extraInfo = StringRef()); QualType getSubstTemplateTypeParmType(const TemplateTypeParmType *Replaced, QualType Replacement) const; diff --git a/clang/include/clang/AST/Type.h b/clang/include/clang/AST/Type.h --- a/clang/include/clang/AST/Type.h +++ b/clang/include/clang/AST/Type.h @@ -4775,10 +4775,12 @@ } static void Profile(llvm::FoldingSetNodeID &ID, Kind attrKind, - QualType modified, QualType equivalent) { + QualType modified, QualType equivalent, + StringRef extraInfo = StringRef()) { ID.AddInteger(attrKind); ID.AddPointer(modified.getAsOpaquePtr()); ID.AddPointer(equivalent.getAsOpaquePtr()); + ID.AddString(extraInfo); } static bool classof(const Type *T) { diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -4665,9 +4665,11 @@ QualType ASTContext::getAttributedType(attr::Kind attrKind, QualType modifiedType, - QualType equivalentType) { + QualType equivalentType, + StringRef extraInfo) { llvm::FoldingSetNodeID id; - AttributedType::Profile(id, attrKind, modifiedType, equivalentType); + AttributedType::Profile(id, attrKind, modifiedType, equivalentType, + extraInfo); void *insertPos = nullptr; AttributedType *type = AttributedTypes.FindNodeOrInsertPos(id, insertPos); diff --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp --- a/clang/lib/Sema/SemaType.cpp +++ b/clang/lib/Sema/SemaType.cpp @@ -258,9 +258,11 @@ /// Get an attributed type for the given attribute, and remember the Attr /// object so that we can attach it to the AttributedTypeLoc. QualType getAttributedType(Attr *A, QualType ModifiedType, - QualType EquivType) { + QualType EquivType, + StringRef ExtraInfo = StringRef()) { QualType T = - sema.Context.getAttributedType(A->getKind(), ModifiedType, EquivType); + sema.Context.getAttributedType(A->getKind(), ModifiedType, EquivType, + ExtraInfo); AttrsForTypes.push_back({cast(T.getTypePtr()), A}); AttrsForTypesSorted = false; return T; @@ -6553,8 +6555,9 @@ ASTContext &Ctx = S.Context; StringRef BTFTypeTag = StrLiteral->getString(); - Type = State.getAttributedType( - ::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), Type, Type); + Type = + State.getAttributedType(::new (Ctx) BTFTypeTagAttr(Ctx, Attr, BTFTypeTag), + Type, Type, BTFTypeTag); } /// HandleAddressSpaceTypeAttribute - Process an address_space attribute on the diff --git a/clang/test/CodeGen/attr-btf_type_tag-similar-type.c b/clang/test/CodeGen/attr-btf_type_tag-similar-type.c new file mode 100644 --- /dev/null +++ b/clang/test/CodeGen/attr-btf_type_tag-similar-type.c @@ -0,0 +1,26 @@ +// RUN: %clang_cc1 -triple %itanium_abi_triple -debug-info-kind=limited -S -emit-llvm -o - %s | FileCheck %s + +struct map_value { + int __attribute__((btf_type_tag("tag1"))) __attribute__((btf_type_tag("tag3"))) *a; + int __attribute__((btf_type_tag("tag2"))) __attribute__((btf_type_tag("tag4"))) *b; +}; + +struct map_value *func(void); + +int test(struct map_value *arg) +{ + return *arg->a; +} + +// CHECK: distinct !DICompositeType(tag: DW_TAG_structure_type, name: "map_value", file: ![[#]], line: [[#]], size: [[#]], elements: ![[L14:[0-9]+]] +// CHECK: ![[L14]] = !{![[L15:[0-9]+]], ![[L20:[0-9]+]]} +// CHECK: ![[L15]] = !DIDerivedType(tag: DW_TAG_member, name: "a", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[L16:[0-9]+]] +// CHECK: ![[L16]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[#]], size: [[#]], annotations: ![[L17:[0-9]+]] +// CHECK: ![[L17]] = !{![[L18:[0-9]+]], ![[L19:[0-9]+]]} +// CHECK: ![[L18]] = !{!"btf_type_tag", !"tag1"} +// CHECK: ![[L19]] = !{!"btf_type_tag", !"tag3"} +// CHECK: ![[L20]] = !DIDerivedType(tag: DW_TAG_member, name: "b", scope: ![[#]], file: ![[#]], line: [[#]], baseType: ![[L21:[0-9]+]] +// CHECK: ![[L21:[0-9]+]] = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: ![[#]], size: [[#]], annotations: ![[L22:[0-9]+]] +// CHECK: ![[L22]] = !{![[L23:[0-9]+]], ![[L24:[0-9]+]]} +// CHECK: ![[L23]] = !{!"btf_type_tag", !"tag2"} +// CHECK: ![[L24]] = !{!"btf_type_tag", !"tag4"}