[llvm-bugs] [Bug 38753] New: Stale variable value in optimised code
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Aug 29 04:40:07 PDT 2018
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: 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 (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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20180829/55279f61/attachment.html>
More information about the llvm-bugs
mailing list