<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 --- - clang produces an unneeded static initializer"
href="http://llvm.org/bugs/show_bug.cgi?id=19590">19590</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>clang produces an unneeded static initializer
</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>All
</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>nicolasweber@gmx.de
</td>
</tr>
<tr>
<th>CC</th>
<td>llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>$ cat si.cc
enum LinkerInitialized { LINKER_INITIALIZED };
struct Bar {
// Note: No definition.
static const LinkerInitialized LINKER_INITIALIZED;
};
class Foo {
public:
// Note: `x` isn't used, definition not needed.
explicit Foo(LinkerInitialized /*x*/) {}
private:
int lockword_;
};
Foo foo(Bar::LINKER_INITIALIZED);
int main() {}
$ third_party/llvm-build/Release+Asserts/bin/clang++ -O2 -o foo -fPIC si.cc
$ readelf -SW foo | grep init_arr [18] .init_array INIT_ARRAY
0000000000600dd0 000dd0 000008 00 WA 0 0 8
gcc doesn't do this:
$ g++ -O2 -o foo -fPIC si.cc
$ readelf -SW foo | grep init_arr
This is true for the .o too:
$ g++ -O2 -c -fPIC si.cc
$ nm si.o | grep GLOBAL
$ third_party/llvm-build/Release+Asserts/bin/clang++ -O2 -c -fPIC si.cc
$ nm si.o | grep GLOBAL0000000000000000 t _GLOBAL__I_si.cc
(the "-fPIC" is so that gcc adds the filename to the _GLOBAL__ symbol. clang
only adds that with the "[(questionable but useful) patch] Let codegen write
the filename for translation unit initializer functions" patch on cfe-commits.)</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>