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

            Bug ID: 38753
           Summary: Stale variable value in optimised code
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: new bugs
          Assignee: [email protected]
          Reporter: [email protected]
                CC: [email protected],
                    [email protected],
                    [email protected],
                    [email protected]

With the (contrived) test below, the "cheese" variable has a stale value
reported inside the "if" block. Using an up-to-date toolchain (r340912), and
compiling with "clang++ test.cpp -g -O2 -o a.out" for x86_64, on the marked
line gdb and lldb report the value of "cheese" to be four, wheras if compiled
-O0 the correct value of eight is seen.

The likely cause is SimplifyCFG's tryCSEWithPredecessor replacing the duplicate
"read1 + read2" expression, however the debug value for "cheese" is either lost
or not updated, causing debuggers to report a state the program isn't in.

It should be possible to get this right or mark "cheese" optimised out, the
true-if-block isn't merged with anything else.

Found using DExTer ( https://github.com/SNSystems/dexter ).

-------->8--------
int
main()
{
  volatile int foo = 4;
  int read1 = foo;
  int read2 = foo;

  int cheese = foo;
  int a = read1 + read2;
  a += cheese;

  if (foo == 4) {
    cheese = read1 + read2;
    a -= cheese - 12;
    a *= 20;   // <------ stale value seen
    a /= 3;
  } else {
    a = 0;
  }

  return a;
}
--------8<--------

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
[email protected]
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to