<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 - Debug: illegal value appears in variable when conditional blocks folded"
href="https://bugs.llvm.org/show_bug.cgi?id=38754">38754</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Debug: illegal value appears in variable when conditional blocks folded
</td>
</tr>
<tr>
<th>Product</th>
<td>new-bugs
</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>normal
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>new bugs
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>jeremy.morse.llvm@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>greg.bedwell@sony.com, international.phantom@gmail.com, llvm-bugs@lists.llvm.org, paul_robinson@playstation.sony.com
</td>
</tr></table>
<p>
<div>
<pre>With the test below, debuggers report "qux" as having the value two for the
whole program when compiled -O2 -g. This is wrong, because not only does "qux"
never have the value two, no variable in the program ever does either.
Using an up-to-date toolchain (r340912), and compiling with "clang++ test.cpp
-g -O2 -o a.out" for x86_64, printing the "qux" variable with gdb and lldb
yields two on all lines past quxes initialisation, wheras if compiled -O0 the
correct value of zero then eight is seen.
I've tried to reduce this test further, but that led to the value reported for
"qux" changing (but still being a fixed value). My feeling is that whatever
calculates the DWARF expression for "qux" is interpreting the not-taken
else-blocks wrong in some way, deleting the bodies of those blocks changes
debug behaviour too. FWIW, I generated this test while trying to stimulate
SimplifyCFG's jump threader (which tries to merge the two if conditions into
one), SimplifyEqualityComparisonWithOnlyPredecessor.
Found using DExTer ( <a href="https://github.com/SNSystems/dexter">https://github.com/SNSystems/dexter</a> ).
-------->8--------
int
main()
{
volatile int foo = 4;
int read = foo;
int read1 = foo;
int read2 = foo;
int baz = 0;
int bar = 0, qux = 0;
if (read == 4) {
baz = 4;
bar = read1 * 2;
qux = read2 * 2;
} else {
baz = read;
bar = read1 / 2;
qux = read2 / 2;
}
bar &= 0xffff;
if (baz == 4) {
bar += baz + qux;
} else {
bar -= baz + qux;
}
return bar;
}
--------8<--------</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>