[llvm-bugs] [Bug 39572] New: Optimizer removes unrelated test due to later static_cast
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Nov 6 15:06:43 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39572
Bug ID: 39572
Summary: Optimizer removes unrelated test due to later
static_cast
Product: clang
Version: 7.0
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: -New Bugs
Assignee: unassignedclangbugs at nondot.org
Reporter: scott.smith at purestorage.com
CC: llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk
Created attachment 21096
--> https://bugs.llvm.org/attachment.cgi?id=21096&action=edit
Complete test case
For the following code (see attachments for the full test case):
for (size_t i = 0; i < 20; i++) {
op * res = nullptr;
if (rand() % 2) { // compiler turns this into: if (rand(),
true) {
count++;
res = get_an_op();
}
static_cast<no_dispose *>(res)->execute(); // nullptr
dereference 50% of the time
}
printf("ASDF count = %d\n", count);
I expect the code to usually crash due to dereference of nullptr. However when
compiled with -O3, it prints "ASDF count = 20".
Note the static_cast - if you remove it, the code crashes as you'd expect.
This may be a case of the compiler making unrelated decisions due the
unexpected behavior of the null dereference (though the cast itself is legal,
and the change in behavior only happens with the cast). However it does seem
odd to me that the cast affects the earlier if() statement.
To repeat:
good:
$ clang++-7 -o good a.cpp
$ ./good
Segmentation fault (core dumped)
bad:
$ clang++-7 -o bad -O3 a.cpp
$ ./bad
ASDF count = 20
--
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/20181106/c11a37fd/attachment-0001.html>
More information about the llvm-bugs
mailing list