<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
pre
        {mso-style-priority:99;
        mso-style-link:"HTML Preformatted Char";
        margin:0in;
        margin-bottom:.0001pt;
        font-size:10.0pt;
        font-family:"Courier New";}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.HTMLPreformattedChar
        {mso-style-name:"HTML Preformatted Char";
        mso-style-priority:99;
        mso-style-link:"HTML Preformatted";
        font-family:"Consolas",serif;}
span.EmailStyle20
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal">Full LTO. Oh, so your build bot is using thinLTO. I’ll keep an eye in thinLTO builds.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style="font-size:12.0pt;color:black">From: </span></b><span style="font-size:12.0pt;color:black">Michael Spencer <bigcheesegs@gmail.com><br>
<b>Date: </b>Thursday, March 28, 2019 at 1:27 PM<br>
<b>To: </b>Rafael Auler <rafaelauler@fb.com><br>
<b>Cc: </b>"cfe-commits@lists.llvm.org" <cfe-commits@lists.llvm.org><br>
<b>Subject: </b>Re: r356598 - Recommit "Support attribute used in member funcs of class templates"<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<div>
<div>
<div>
<p class="MsoNormal">On Tue, Mar 26, 2019 at 7:40 PM Rafael Auler <<a href="mailto:rafaelauler@fb.com">rafaelauler@fb.com</a>> wrote:<o:p></o:p></p>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I’m familiar with this issue as I had to fix a memory bug in LLVM IRLinker that was exposed by this commit. That’s why I initially reverted it. However, after fixing it, I was able
 to do the full clang LTO self-hosting with lld on Linux. Is there any way I can repro this issue? It’s probably a bad interaction of attribute used and an optimization. See
<a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D59552&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=zyfJGH3SN_mqqkedhHgxTKMJD-SKkgBThplLcE0c4bc&s=ZbiPDYSvM_vb8esCc6n0mu7cKL-P4cWlCzbwo7j6Eqo&e=" target="_blank">
https://reviews.llvm.org/D59552</a><o:p></o:p></p>
</div>
</div>
</blockquote>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">Was this with full LTO or thin LTO?  I'm still working on getting a reproducer.  This may be related to this issue: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__bugs.llvm.org_show-5Fbug.cgi-3Fid-3D41236&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=zyfJGH3SN_mqqkedhHgxTKMJD-SKkgBThplLcE0c4bc&s=XJ3Li7xxtXeJejLu56BM69HTR1NeZpvM2ibUasdBxVA&e=">https://bugs.llvm.org/show_bug.cgi?id=41236</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<div>
<p class="MsoNormal">- Michael Spencer<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal"> <o:p></o:p></p>
</div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in">
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">Michael Spencer <<a href="mailto:bigcheesegs@gmail.com" target="_blank">bigcheesegs@gmail.com</a>><br>
<b>Date: </b>Tuesday, March 26, 2019 at 6:59 PM<br>
<b>To: </b>Rafael Auler <<a href="mailto:rafaelauler@fb.com" target="_blank">rafaelauler@fb.com</a>><br>
<b>Cc: </b>"<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>" <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject: </b>Re: r356598 - Recommit "Support attribute used in member funcs of class templates"</span><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<div>
<div>
<div>
<div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">On Wed, Mar 20, 2019 at 12:21 PM Rafael Auler via cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>> wrote:<o:p></o:p></p>
</div>
</div>
</div>
<div>
<blockquote style="border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-top:5.0pt;margin-right:0in;margin-bottom:5.0pt">
<p class="MsoNormal" style="mso-margin-top-alt:auto;margin-bottom:12.0pt">Author: rafauler<br>
Date: Wed Mar 20 12:22:24 2019<br>
New Revision: 356598<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D356598-26view-3Drev&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=Tp8AU6vZlFhDRTWeUHWkXzTHsspDHfWnErBtktRStLc&s=z5t_fduYusJn1DP4wsOLj9KYsPpKMyUkVXk2JAPRNM8&e=" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=356598&view=rev</a><br>
Log:<br>
Recommit "Support attribute used in member funcs of class templates"<br>
<br>
This diff previously exposed a bug in LLVM's IRLinker, breaking<br>
buildbots that tried to self-host LLVM with monolithic LTO.<br>
The bug is now in LLVM by D59552<br>
<br>
Original commit message:<br>
As PR17480 describes, clang does not support the used attribute<br>
for member functions of class templates. This means that if the member<br>
function is not used, its definition is never instantiated. This patch<br>
changes clang to emit the definition if it has the used attribute.<br>
<br>
Test Plan: Added a testcase<br>
<br>
Reviewed By: aaron.ballman<br>
<br>
Differential Revision: <a href="https://urldefense.proofpoint.com/v2/url?u=https-3A__reviews.llvm.org_D56928&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=Tp8AU6vZlFhDRTWeUHWkXzTHsspDHfWnErBtktRStLc&s=Y54Z_weCYOa7tU_wNo9M6yMwDeLwDQKoNdrnZu_PllE&e=" target="_blank">
https://reviews.llvm.org/D56928</a><br>
<br>
Added:<br>
    cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp<br>
Modified:<br>
    cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
<br>
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_lib_Sema_SemaTemplateInstantiateDecl.cpp-3Frev-3D356598-26r1-3D356597-26r2-3D356598-26view-3Ddiff&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=Tp8AU6vZlFhDRTWeUHWkXzTHsspDHfWnErBtktRStLc&s=Zh4mt8nrN7qZNDUMeoVkSQtZ2ebQTgXi_MOQa87S5fY&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=356598&r1=356597&r2=356598&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)<br>
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Wed Mar 20 12:22:24 2019<br>
@@ -2232,6 +2232,20 @@ TemplateDeclInstantiator::VisitCXXMethod<br>
     Owner->addDecl(Method);<br>
   }<br>
<br>
+  // PR17480: Honor the used attribute to instantiate member function<br>
+  // definitions<br>
+  if (Method->hasAttr<UsedAttr>()) {<br>
+    if (const auto *A = dyn_cast<CXXRecordDecl>(Owner)) {<br>
+      SourceLocation Loc;<br>
+      if (const MemberSpecializationInfo *MSInfo =<br>
+              A->getMemberSpecializationInfo())<br>
+        Loc = MSInfo->getPointOfInstantiation();<br>
+      else if (const auto *Spec = dyn_cast<ClassTemplateSpecializationDecl>(A))<br>
+        Loc = Spec->getPointOfInstantiation();<br>
+      SemaRef.MarkFunctionReferenced(Loc, Method);<br>
+    }<br>
+  }<br>
+<br>
   return Method;<br>
 }<br>
<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_cfe_trunk_test_CodeGenCXX_attr-2Dused-2Dmember-2Dfunction-2Dimplicit-2Dinstantiation.cpp-3Frev-3D356598-26view-3Dauto&d=DwMFaQ&c=5VD0RTtNlTh3ycd41b3MUw&r=kx31RNFp5lAJejEYwuEQ4Zc5A6GakBit07EY08bIAvc&m=Tp8AU6vZlFhDRTWeUHWkXzTHsspDHfWnErBtktRStLc&s=CMIrOdMDTKRq5dy52CT5B9v2iMMA2dPslSvyhjaCb2o&e=" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp?rev=356598&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/attr-used-member-function-implicit-instantiation.cpp Wed Mar 20 12:22:24 2019<br>
@@ -0,0 +1,19 @@<br>
+// RUN: %clang_cc1 -triple x86_64-unknown-unknown -emit-llvm -o - %s | FileCheck %s<br>
+<br>
+// Check that PR17480 is fixed: __attribute__((used)) ignored in templated<br>
+// classes<br>
+namespace InstantiateUsedMemberDefinition {<br>
+template <typename T><br>
+struct S {<br>
+  int __attribute__((used)) f() {<br>
+    return 0;<br>
+  }<br>
+};<br>
+<br>
+void test() {<br>
+  // Check that InstantiateUsedMemberDefinition::S<int>::f() is defined<br>
+  // as a result of the S class template implicit instantiation<br>
+  // CHECK: define linkonce_odr i32 @_ZN31InstantiateUsedMemberDefinition1SIiE1fEv<br>
+  S<int> inst;<br>
+}<br>
+} // namespace InstantiateUsedMemberDefinition<o:p></o:p></p>
</blockquote>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"> <o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">I believe this commit broke our (Apple) internal LTO bots.  I'm working on getting more information and narrowing it down.  The symptom is:<o:p></o:p></p>
</div>
<div>
<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="color:black"> </span><o:p></o:p></pre>
<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="color:black">Undefined symbols for architecture x86_64:</span><o:p></o:p></pre>
<pre><span style="color:black">  "llvm::cfg::Update<llvm::BasicBlock*>::dump() const", referenced from:</span><o:p></o:p></pre>
<pre><span style="color:black">      DominatorTreeBatchUpdates_LegalizeDomUpdates_Test::TestBody() in DominatorTreeBatchUpdatesTest.cpp.o</span><o:p></o:p></pre>
<pre><span style="color:black">      DominatorTreeBatchUpdates_LegalizePostDomUpdates_Test::TestBody() in DominatorTreeBatchUpdatesTest.cpp.o</span><o:p></o:p></pre>
<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="color:black"> </span><o:p></o:p></pre>
<pre style="word-wrap:break-word;white-space:pre-wrap"><span style="color:black">Has anyone else seen a similar issue with this commit?</span><o:p></o:p></pre>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">- Michael Spencer<o:p></o:p></p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</div>
</div>
</div>
</body>
</html>