<html>
<head>
<base href="http://llvm.org/bugs/" />
</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 --- - Global initializers for selectany objects are not comdat associative"
href="http://llvm.org/bugs/show_bug.cgi?id=20889">20889</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Global initializers for selectany objects are not comdat associative
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>unspecified
</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>hans@chromium.org
</td>
</tr>
<tr>
<th>CC</th>
<td>david.majnemer@gmail.com, llvmbugs@cs.uiuc.edu, rnk@google.com
</td>
</tr>
<tr>
<th>Blocks</th>
<td>18887
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider the following code:
a.cc:
#include <stdio.h>
struct S {
S() { printf("Hello!\n"); x = 42; }
int x;
};
__declspec(selectany) S s;
int main() {
return s.x;
}
b.cc:
#include <stdio.h>
struct S {
S() { printf("Hello!\n"); x = 42; }
int x;
};
__declspec(selectany) S s;
When compiled with clang-cl, this will run the global initializer for s twice.
With MSVC, it runs once.
This is because MSVC emits the initializer in a section that's associative with
s, but Clang uses a different approach.
We already have the code to do this in Clang, when using #pragma init_seg with
a non-default segment name. E.g., adding #pragma init_seg(".CRT$XCV") before
the declarations of s in the code above makes it work.
Maybe we should switch to always emit global initializers like this for win32.
Or mabye we should put InitSegAttr on selectany globals?</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>