[llvm-bugs] [Bug 38756] New: Debug: illegal value and unreachable lines seen when conditional stores merged

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 29 06:20:33 PDT 2018


https://bugs.llvm.org/show_bug.cgi?id=38756

            Bug ID: 38756
           Summary: Debug: illegal value and unreachable lines seen when
                    conditional stores merged
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: jeremy.morse.llvm at gmail.com
                CC: greg.bedwell at sony.com,
                    international.phantom at gmail.com,
                    llvm-bugs at lists.llvm.org,
                    paul_robinson at playstation.sony.com

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<--------

-- 
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/20180829/134dee07/attachment.html>


More information about the llvm-bugs mailing list