[llvm-bugs] [Bug 38754] New: Debug: illegal value appears in variable when conditional blocks folded

via llvm-bugs llvm-bugs at lists.llvm.org
Wed Aug 29 05:57:00 PDT 2018


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

            Bug ID: 38754
           Summary: Debug: illegal value appears in variable when
                    conditional blocks folded
           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

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 ( https://github.com/SNSystems/dexter ).

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

-- 
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/d2e79e92/attachment.html>


More information about the llvm-bugs mailing list