<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 - Computed goto generates badrefs: block addresses, constexpr, and lambdas."
href="https://bugs.llvm.org/show_bug.cgi?id=43546">43546</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Computed goto generates badrefs: block addresses, constexpr, and lambdas.
</td>
</tr>
<tr>
<th>Product</th>
<td>clang
</td>
</tr>
<tr>
<th>Version</th>
<td>9.0
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>C++
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedclangbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>felipe.de.azevedo.piovezan@intel.com
</td>
</tr>
<tr>
<th>CC</th>
<td>blitzrakete@gmail.com, dgregor@apple.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
</td>
</tr></table>
<p>
<div>
<pre>The code below miscompiles on Clang 9 & trunk, but not on previous versions:
(Godbolt link for convenience: <a href="https://godbolt.org/z/8LG1v3">https://godbolt.org/z/8LG1v3</a>)
We generate global variables with <badrefs> and, as such, the optimizer
completely eliminates the function.
@labels = private unnamed_addr constant [3 x i8*] [i8*
blockaddress(@"label1", <badref>), i8* blockaddress(@"label2", <badref>), i8*
blockaddress(@"label3", <badref>)], align 16
Note the badrefs! Also, we generate a basic block with no predecessors:
12: ; No predecessors!
indirectbr i8* undef, [label <badref>, label <badref>, label <badref>]
```
enum bytecode : int8_t
{
add1,
add2,
halt,
};
auto run_with_computed_goto(bytecode const* instructions)
{
auto value = 0.0;
constexpr void* labels[] = {
[bytecode::add1] = &&add1_label,
[bytecode::add2] = &&add2_label,
[bytecode::halt] = &&halt_label,
};
auto const next = [&] { return labels[*instructions++]; };
goto* next();
add1_label:
value += 1.0;
goto* next();
add2_label:
value += 2.0;
goto* next();
halt_label:
return value;
}
```</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>