<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 - Clang/LLVM Produces a constant description of a global constant, even when that constant has storage"
href="https://bugs.llvm.org/show_bug.cgi?id=39899">39899</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Clang/LLVM Produces a constant description of a global constant, even when that constant has storage
</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>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</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>dblaikie@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>aprantl@apple.com, echristo@gmail.com, jdevlieghere@apple.com, llvm-bugs@lists.llvm.org, neeilans@live.com, paul.robinson@am.sony.com, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>Given this:
static const int x = 3;
const int *y() {
return &x;
}
int z() {
return 1;
}
Clang produces IR with a variable description like this:
@_ZL1x = internal constant i32 3, align 4, !dbg !0
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
Which seems all right and good.
but if you change the "return 1" to "return x", you get IR like this:
@_ZL1x = internal constant i32 3, align 4, !dbg !0
!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression(DW_OP_constu,
3, DW_OP_stack_value))
It's weird that the !dbg is even attached to the global anymore, since it
doesn't use its address in the location expression at all.
But also, it's a regression to describe something with a constant when it does
have storage - it means you can't, say evaluate "&i" in a debugger, or pass the
address of the global to a function that wants an address, etc.
According to some rough debugging with godbolt, this regression first appeared
in the 4.0 release.</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>