From 9dde31ecc1578768eeddb508ac17cebcfd71e3d6 Mon Sep 17 00:00:00 2001 From: Rafael Auler Date: Wed, 20 Mar 2019 19:22:24 +0000 Subject: Recommit "Support attribute used in member funcs of class templates" This diff previously exposed a bug in LLVM's IRLinker, breaking buildbots that tried to self-host LLVM with monolithic LTO. The bug is now in LLVM by D59552 Original commit message: As PR17480 describes, clang does not support the used attribute for member functions of class templates. This means that if the member function is not used, its definition is never instantiated. This patch changes clang to emit the definition if it has the used attribute. Test Plan: Added a testcase Reviewed By: aaron.ballman Differential Revision: https://reviews.llvm.org/D56928 llvm-svn: 356598 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'clang/lib/Sema/SemaTemplateInstantiateDecl.cpp') diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index c71fa7ac57b..4615fbc9749 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -2232,6 +2232,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Owner->addDecl(Method); } + // PR17480: Honor the used attribute to instantiate member function + // definitions + if (Method->hasAttr()) { + if (const auto *A = dyn_cast(Owner)) { + SourceLocation Loc; + if (const MemberSpecializationInfo *MSInfo = + A->getMemberSpecializationInfo()) + Loc = MSInfo->getPointOfInstantiation(); + else if (const auto *Spec = dyn_cast(A)) + Loc = Spec->getPointOfInstantiation(); + SemaRef.MarkFunctionReferenced(Loc, Method); + } + } + return Method; } -- cgit v1.2.3