<html xmlns:v="urn:schemas-microsoft-com:vml" 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:SimSun;
panose-1:2 1 6 0 3 1 1 1 1 1;}
@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:"\@SimSun";
panose-1:2 1 6 0 3 1 1 1 1 1;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman",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;}
span.EmailStyle17
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-family:"Calibri",sans-serif;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-US" link="blue" vlink="purple">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thank you so much. Jennifer<o:p></o:p></span></p>
<p class="MsoNormal"><a name="_MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"><o:p> </o:p></span></a></p>
<p class="MsoNormal"><a name="_____replyseparator"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif"> Nico Weber [mailto:thakis@chromium.org]
<br>
<b>Sent:</b> Thursday, April 11, 2019 2:25 PM<br>
<b>To:</b> Yu, Jennifer <jennifer.yu@intel.com><br>
<b>Cc:</b> cfe-commits <cfe-commits@lists.llvm.org><br>
<b>Subject:</b> Re: r357610 - Bug-40323: MS ABI adding template static member in the linker directive section to make sure init function can be called before main.<o:p></o:p></span></p>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">Done in 358232. Thanks!<o:p></o:p></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<div>
<div>
<p class="MsoNormal">On Thu, Apr 11, 2019 at 5:19 PM Yu, Jennifer <<a href="mailto:jennifer.yu@intel.com">jennifer.yu@intel.com</a>> wrote:<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"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Hi Nico,</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Iet’s revert it now. I will try to re-submit latter.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Thanks.</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D">Jennifer</span><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a name="m_-3378690069479697153__MailEndCompose"><span style="font-size:11.0pt;font-family:"Calibri",sans-serif;color:#1F497D"> </span></a><o:p></o:p></p>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><a name="m_-3378690069479697153______replyseparat"></a><b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">From:</span></b><span style="font-size:11.0pt;font-family:"Calibri",sans-serif">
Nico Weber [mailto:<a href="mailto:thakis@chromium.org" target="_blank">thakis@chromium.org</a>]
<br>
<b>Sent:</b> Thursday, April 11, 2019 2:04 PM<br>
<b>To:</b> Yu, Jennifer <<a href="mailto:jennifer.yu@intel.com" target="_blank">jennifer.yu@intel.com</a>><br>
<b>Cc:</b> cfe-commits <<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>><br>
<b>Subject:</b> Re: r357610 - Bug-40323: MS ABI adding template static member in the linker directive section to make sure init function can be called before main.</span><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>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Hi Jennifer,<o:p></o:p></p>
<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">this caused <a href="https://bugs.llvm.org/show_bug.cgi?id=41471" target="_blank">https://bugs.llvm.org/show_bug.cgi?id=41471</a><o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto"><br>
Do you think this is easy to fix, or should we revert for now?<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>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Thanks,<o:p></o:p></p>
</div>
<div>
<p class="MsoNormal" style="mso-margin-top-alt:auto;mso-margin-bottom-alt:auto">Nico<o:p></o:p></p>
</div>
</div>
</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">On Wed, Apr 3, 2019 at 1:20 PM Jennifer Yu 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>
<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;mso-margin-bottom-alt:auto">Author: jyu2<br>
Date: Wed Apr 3 10:21:40 2019<br>
New Revision: 357610<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=357610&view=rev" target="_blank">
http://llvm.org/viewvc/llvm-project?rev=357610&view=rev</a><br>
Log:<br>
Bug-40323: MS ABI adding template static member in the linker directive section to make sure init function can be called before main.<br>
<br>
Added:<br>
cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp<br>
Modified:<br>
cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
<br>
Modified: cfe/trunk/lib/CodeGen/CGDeclCXX.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=357610&r1=357609&r2=357610&view=diff" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDeclCXX.cpp?rev=357610&r1=357609&r2=357610&view=diff</a><br>
==============================================================================<br>
--- cfe/trunk/lib/CodeGen/CGDeclCXX.cpp (original)<br>
+++ cfe/trunk/lib/CodeGen/CGDeclCXX.cpp Wed Apr 3 10:21:40 2019<br>
@@ -481,6 +481,12 @@ CodeGenModule::EmitCXXGlobalVarDeclInitF<br>
// minor startup time optimization. In the MS C++ ABI, there are no guard<br>
// variables, so this COMDAT key is required for correctness.<br>
AddGlobalCtor(Fn, 65535, COMDATKey);<br>
+ if (getTarget().getCXXABI().isMicrosoft()) {<br>
+ // In The MS C++, MS add template static data member in the linker<br>
+ // drective.<br>
+ assert(COMDATKey);<br>
+ addUsedGlobal(COMDATKey);<br>
+ }<br>
} else if (D->hasAttr<SelectAnyAttr>()) {<br>
// SelectAny globals will be comdat-folded. Put the initializer into a<br>
// COMDAT group associated with the global, so the initializers get folded<br>
<br>
Added: cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp?rev=357610&view=auto" target="_blank">
http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp?rev=357610&view=auto</a><br>
==============================================================================<br>
--- cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp (added)<br>
+++ cfe/trunk/test/CodeGenCXX/microsoft-abi-template-static-init.cpp Wed Apr 3 10:21:40 2019<br>
@@ -0,0 +1,57 @@<br>
+// RUN: %clang_cc1 %s -triple=i686-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s<br>
+// RUN: %clang_cc1 %s -triple=x86_64-pc-win32 -fms-extensions -emit-llvm -o - | FileCheck %s<br>
+// RUN: %clang_cc1 %s -triple=i686-pc-windows-msvc -fms-extensions -emit-llvm -o - | FileCheck %s<br>
+// RUN: %clang_cc1 %s -triple=x86_64-pc-windows-msvc -fms-extensions -emit-llvm -o - | FileCheck %s<br>
+<br>
+struct S {<br>
+ S();<br>
+ ~S();<br>
+};<br>
+<br>
+template <typename T> struct __declspec(dllexport) ExportedTemplate {<br>
+ static S s;<br>
+};<br>
+template <typename T> S ExportedTemplate<T>::s;<br>
+void useExportedTemplate(ExportedTemplate<int> x) {<br>
+ (void)x.s;<br>
+}<br>
+int f();<br>
+namespace selectany_init {<br>
+// MS don't put selectany static var in the linker directive, init routine<br>
+// f() is not getting called if x is not referenced.<br>
+int __declspec(selectany) x = f();<br>
+}<br>
+<br>
+namespace explicit_template_instantiation {<br>
+template <typename T> struct A { static int x; };<br>
+template <typename T> int A<T>::x = f();<br>
+template struct A<int>;<br>
+}<br>
+<br>
+namespace implicit_template_instantiation {<br>
+template <typename T> struct A { static int x; };<br>
+template <typename T> int A<T>::x = f();<br>
+int g() { return A<int>::x; }<br>
+}<br>
+<br>
+<br>
+template <class T><br>
+struct X_ {<br>
+ static T ioo;<br>
+ static T init();<br>
+};<br>
+template <class T> T X_<T>::ioo = X_<T>::init();<br>
+template struct X_<int>;<br>
+<br>
+template <class T><br>
+struct X {<br>
+ static T ioo;<br>
+ static T init();<br>
+};<br>
+// template specialized static data don't need in llvm.used,<br>
+// the static init routine get call from _GLOBAL__sub_I_ routines.<br>
+template <> int X<int>::ioo = X<int>::init();<br>
+template struct X<int>;<br>
+// CHECK: @llvm.global_ctors = appending global [6 x { i32, void ()*, i8* }] [{ i32, void ()*, i8* } { i32 65535, void ()* @"??__Ex@selectany_init@@YAXXZ", i8* bitcast (i32* @"?x@selectany_init@@3HA" to i8*) }, { i32, void ()*, i8* } { i32 65535, void ()*
@"??__E?x@?$A@H@explicit_template_instantiation@@2HA@@YAXXZ", i8* bitcast (i32* @"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*) }, { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?ioo@?$X_@H@@2HA@@YAXXZ", i8* bitcast (i32* @"?ioo@?$X_@H@@2HA"
to i8*) }, { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?s@?$ExportedTemplate@H@@2US@@A@@YAXXZ", i8* getelementptr inbounds (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A", i32 0, i32 0) }, { i32, void ()*, i8* } { i32 65535, void ()* @"??__E?x@?$A@H@implicit_template_instantiation@@2HA@@YAXXZ",
i8* bitcast (i32* @"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*) }, { i32, void ()*, i8* } { i32 65535, void ()* @_GLOBAL__sub_I_microsoft_abi_template_static_init.cpp, i8* null }]<br>
+// CHECK: @llvm.used = appending global [4 x i8*] [i8* bitcast (i32* @"?x@?$A@H@explicit_template_instantiation@@2HA" to i8*), i8* bitcast (i32* @"?ioo@?$X_@H@@2HA" to i8*), i8* getelementptr inbounds (%struct.S, %struct.S* @"?s@?$ExportedTemplate@H@@2US@@A",
i32 0, i32 0), i8* bitcast (i32* @"?x@?$A@H@implicit_template_instantiation@@2HA" to i8*)], section "llvm.metadata"<br>
+<br>
<br>
<br>
_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits</a><o:p></o:p></p>
</blockquote>
</div>
</div>
</div>
</blockquote>
</div>
</div>
</body>
</html>