<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 and unreachable lines seen when conditional stores merged"
   href="https://bugs.llvm.org/show_bug.cgi?id=38756">38756</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Debug: illegal value and unreachable lines seen when conditional stores merged
          </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>The test below causes debuggers to report an illegal variable value and step
onto a line that isn't executed. The test was originally intended to stimulate
SimplifyCFG's mergeConditionalStores method (merging the conditional stores to
"global") but is likely triggering bad behaviour elsewhere.

I've used an up-to-date toolchain (r340912), and compiled with "clang++
test.cpp -g -O2 -o a.out" for x86_64. To be clear, the program should pass
through both "else" blocks of the conditionals as bar == 4, and "lolret" should
accumulate the values zero, two, and six. however:
 * Single stepping, we step onto "lolret += 4", immediately followed by
   "lolret += 3". The latter is not actually executed, and stepping on both
   branches of a conditional is misleading anyway,
 * "lolret" appears with the value five at one step of the program, which
   is a value it never has (neither does anything else). This appears on
   the "if (bar & 2)" line, but,
 * Control flow really bounces around, I observe more backward steps in
   this test than forward steps.

To be completely clear, here's a trace of hitting the unreachable line and
finding the illegal value:
Starting program: /tmp/a.out
Temporary breakpoint 2, main () at test.cpp:6
6         volatile int foo = 4;
(gdb) s
7         int bar = foo;
(gdb) s
10        if (bar & 1) {
(gdb) s
23          lolret += 4;
(gdb) s
20          lolret += 3;
(gdb)
18        if (bar & 2) {
(gdb) print lolret
$10 = 5
(gdb)

-------->8--------
int global = 0;

int
main()
{
  volatile int foo = 4;
  int bar = foo;
  int lolret = 0;

  if (bar & 1) {
    bar += 1;
    lolret += 1;
  } else {
    global = 2;
    lolret += 2;
  }

  if (bar & 2) {
    bar += 2;
    lolret += 3;
  } else {
    global = 5;
    lolret += 4;
  }

  return lolret;
}
--------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>