https://github.com/egorzhdan updated https://github.com/llvm/llvm-project/pull/122516
>From 689b28a653eeed50a04a2fbd9286831ddfa1018b Mon Sep 17 00:00:00 2001 From: Egor Zhdan <e_zh...@apple.com> Date: Fri, 10 Jan 2025 19:41:02 +0000 Subject: [PATCH] [APINotes] Avoid duplicated attributes for class template instantiations If a C++ class template is annotated via API Notes, the instantiations had the attributes repeated twice. This is because Clang was adding the attribute twice while processing the same class template. This change makes sure we don't try to add attributes from API Notes twice. There is currently no way to annotate specific instantiations using API Notes. rdar://142539959 --- clang/lib/Sema/SemaTemplate.cpp | 1 - clang/test/APINotes/Inputs/Headers/Templates.h | 1 + clang/test/APINotes/templates.cpp | 3 +++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index 5e7a3c8484c88f..6c7e2a3b4214e9 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -2135,7 +2135,6 @@ DeclResult Sema::CheckClassTemplate( NewClass->startDefinition(); ProcessDeclAttributeList(S, NewClass, Attr); - ProcessAPINotes(NewClass); if (PrevClassTemplate) mergeDeclAttributes(NewClass, PrevClassTemplate->getTemplatedDecl()); diff --git a/clang/test/APINotes/Inputs/Headers/Templates.h b/clang/test/APINotes/Inputs/Headers/Templates.h index 862035fee363f7..2a86a46d4af27d 100644 --- a/clang/test/APINotes/Inputs/Headers/Templates.h +++ b/clang/test/APINotes/Inputs/Headers/Templates.h @@ -6,4 +6,5 @@ struct Box { const T* get_ptr() const { return &value; } }; +using FloatBox = Box<float>; using IntBox = Box<int>; diff --git a/clang/test/APINotes/templates.cpp b/clang/test/APINotes/templates.cpp index 0556eba925a514..48109011e73a95 100644 --- a/clang/test/APINotes/templates.cpp +++ b/clang/test/APINotes/templates.cpp @@ -7,3 +7,6 @@ // CHECK-BOX: Dumping Box: // CHECK-BOX-NEXT: ClassTemplateDecl {{.+}} imported in Templates Box // CHECK-BOX: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned" + +// Make sure the attributes aren't duplicated. +// CHECK-BOX-NOT: SwiftAttrAttr {{.+}} <<invalid sloc>> "import_owned" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits