summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael Auler <rafaelauler@fb.com>2019-03-20 19:22:24 +0000
committerRafael Auler <rafaelauler@fb.com>2019-03-20 19:22:24 +0000
commit9dde31ecc1578768eeddb508ac17cebcfd71e3d6 (patch)
tree550537b4f640c6910719e386df704bab87c6601b
parent6dc53ccb0b0900a09d4a49a5af75e307ced5fc17 (diff)
downloadbcm5719-llvm-9dde31ecc1578768eeddb508ac17cebcfd71e3d6.tar.gz
bcm5719-llvm-9dde31ecc1578768eeddb508ac17cebcfd71e3d6.zip
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
-rw-r--r--clang/lib/Sema/SemaTemplateInstantiateDecl.cpp14
-rw-r--r--clang/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp19
2 files changed, 33 insertions, 0 deletions
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<UsedAttr>()) {
+ if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {
+ SourceLocation Loc;
+ if (const MemberSpecializationInfo *MSInfo =
+ A->getMemberSpecializationInfo())
+ Loc = MSInfo->getPointOfInstantiation();
+ else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A))
+ Loc = Spec->getPointOfInstantiation();
+ SemaRef.MarkFunctionReferenced(Loc, Method);
+ }
+ }
+
return Method;
}
diff --git a/clang/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp b/clang/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
new file mode 100644
index 00000000000..7d2062f989d
--- /dev/null
+++ b/clang/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp
@@ -0,0 +1,19 @@
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s
+
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated
+// classes
+namespace InstantiateUsedMemberDefinition {
+template <typename T>
+struct S {
+ int __attribute__((used)) f() {
+ return 0;
+ }
+};
+
+void test() {
+ // Check that InstantiateUsedMemberDefinition::S<int>::f() is defined
+ // as a result of the S class template implicit instantiation
+ // CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv
+ S<int> inst;
+}
+} // namespace InstantiateUsedMemberDefinition
OpenPOWER on IntegriCloud