<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - static initialization order issue with inline variables and -fno-use-init-array"
href="https://bugs.llvm.org/show_bug.cgi?id=50266">50266</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>static initialization order issue with inline variables and -fno-use-init-array
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Windows NT
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>LLVM Codegen
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>Wolfgang_Pieb@playstation.sony.com
</td>
</tr>
<tr>
<th>CC</th>
<td>llvm-bugs@lists.llvm.org, neeilans@live.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>// The following test suffers from an incorrect initialization
// order when compiled with
// > clang -fno-use-init-array -o t t.cpp
// > .t
// I want to be printed second
// I want to be printed first
extern "C" int printf(const char *, ...);
class A {
public:
A() {
printf("I want to be printed first\n");
}
};
class B {
public:
B() {
printf("I want to be printed second\n");
}
};
class StaticsClass {
private:
static inline A A_Var;
static inline B B_Var;
};
int main(void) {
return 0;
}
//****** end *********
Important: The test case needs to be linked with a pair or crtbegin/crtend
startup files that do not define stubs for .init_array, otherwise
nothing will be printed.
Examining the assembly output, after the following commit:
=================================================
commit c19f4f8069722f6804086d4438a0254104242c46
Author: Jennifer Yu <<a href="mailto:jennifer.yu@intel.com">jennifer.yu@intel.com</a>>
Date: Thu Apr 25 17:45:45 2019 +0000
Fix <a class="bz_bug_link
bz_status_RESOLVED bz_closed"
title="RESOLVED FIXED - Clang/LLVM 7.0.1 on Windows initializes inline static data member multiple times"
href="show_bug.cgi?id=37903">bug 37903</a>:MS ABI: handle inline static data member and inline variable
as template static
data member
llvm-svn: 359212
=================================================
we see 2 different .ctors section entries in different
comdat groups
.section .ctors,"aGw",@progbits,_ZN12StaticsClass5A_VarE,comdat
.p2align 3
.quad __cxx_global_var_init
.section .ctors,"aGw",@progbits,_ZN12StaticsClass5B_VarE,comdat
.p2align 3
.quad __cxx_global_var_init.1
which end up consecutively in the executable in this order. However,
the startup code travels the .ctors array in reverse, so we end up
reversing the intialization order.</pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>