[llvm-bugs] [Bug 43546] New: Computed goto generates badrefs: block addresses, constexpr, and lambdas.
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Oct 3 08:14:50 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=43546
Bug ID: 43546
Summary: Computed goto generates badrefs: block addresses,
constexpr, and lambdas.
Product: clang
Version: 9.0
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: C++
Assignee: unassignedclangbugs at nondot.org
Reporter: felipe.de.azevedo.piovezan at intel.com
CC: blitzrakete at gmail.com, dgregor at apple.com,
erik.pilkington at gmail.com, llvm-bugs at lists.llvm.org,
richard-llvm at metafoo.co.uk
The code below miscompiles on Clang 9 & trunk, but not on previous versions:
(Godbolt link for convenience: https://godbolt.org/z/8LG1v3)
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;
}
```
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20191003/915db046/attachment.html>
More information about the llvm-bugs
mailing list