https://bugs.llvm.org/show_bug.cgi?id=34581
Bug ID: 34581
Summary: LLVM miscompiles calls to "operator delete" under -Oz
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedb...@nondot.org
Reporter: richard-l...@metafoo.co.uk
CC: llvm-bugs@lists.llvm.org
Test case:
void f(char *c) {
delete c;
}
void g(char *c) {
if (c)
::operator delete(c);
}
void h(char *c) {
if (c)
delete c;
}
At -Oz, LLVM optimizes away the implied "if (c)" in f. It's highly questionable
for LLVM to be doing this, but a C++ implementation is permitted to elide the
null check in this case.
LLVM also optimizes away the explicit "if (c)" in g, which is a miscompile. A
user replacement operator delete may have observable effects (for instance,
logging) even when called on a null pointer, so LLVM is not allowed to invent
calls to it. Note that in this case the "operator delete" invocation is
"nobuiltin", making it doubly-clear that this is a miscompile.
Finally, it optimizes away both null checks in h, which again is a miscompile.
Despite being a builtin call, this is still an incorrect transformation, again
because operator delete can have observable side-effects.
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs