<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 --- - The address of a dllimported global variable cannot be used in a constant initializer"
href="http://llvm.org/bugs/show_bug.cgi?id=19955">19955</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>The address of a dllimported global variable cannot be used in a constant initializer
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</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>Core LLVM classes
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>rnk@google.com
</td>
</tr>
<tr>
<th>CC</th>
<td>david.majnemer@gmail.com, llvmbugs@cs.uiuc.edu
</td>
</tr>
<tr>
<th>Classification</th>
<td>Unclassified
</td>
</tr></table>
<p>
<div>
<pre>Consider:
extern "C" int __declspec(dllimport) x;
extern "C" int *y = &x;
Clang creates this LLVM IR:
@x = external dllimport global i32
@y = global i32* @x, align 4
This is lowered to:
.data
.globl _y
.align 4
_y:
.long _x
Which is incorrect, because x is dllimported, and its address isn't a link time
constant. It must be loaded from __imp_x. Clang should emit something like
the following IR instead:
@y = global i32* null, align 4
@x = external dllimport global i32
@llvm.global_ctors = appending global [1 x { i32, void ()*, i8* }] [{ i32, void
()*, i8* } { i32 65535, void ()* @init, i8* null }]
define internal void @init() {
entry:
store i32* @x, i32** @y, align 4
ret void
}
This is consistent with what MSVC does, and it would be important to match them
if x was selectany or a static data member of a class template.
However, this is really a bug in LLVM, because LLVM will optimize that IR back
to Clang's original output:
$ opt t.ll -O2 -S -o -
@y = global i32* @x, align 4
@x = external dllimport global i32
@llvm.global_ctors = appending global [0 x { i32, void ()*, i8* }]
zeroinitializer
If y were a function, this would actually link correctly, because import
libraries provide thunks for functions. The only downside is that the address
of a thunk isn't really the address of the function, but few programs rely on
function identity. There's no way to create a forwarding thunk for data, so we
get a link failure with this test case.</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>