This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/71885] Incorrect code generated with -01, memset() function call is missing
- From: "trippels at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 16 Aug 2016 11:24:26 +0000
- Subject: [Bug c++/71885] Incorrect code generated with -01, memset() function call is missing
- Authentication-results: sourceware.org; auth=none
- Auto-submitted: auto-generated
- References: <bug-71885-4@http.gcc.gnu.org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71885
--- Comment #26 from Markus Trippelsdorf <trippels at gcc dot gnu.org> ---
For future reference here is a nice, short example from Bernd Edlinger:
markus@x4 tmp % cat lifetime-dse.cpp
#include <assert.h>
#include <stdlib.h>
#include <string.h>
struct A {
A() {}
void *operator new(size_t s) {
void *ptr = malloc(s);
memset(ptr, 0xFF, s);
return ptr;
}
int value;
};
int main() {
A *a = new A;
assert(a->value == -1); /* Use of uninitialized value */
}
markus@x4 tmp % g++ -O2 -flifetime-dse=1 lifetime-dse.cpp
markus@x4 tmp % ./a.out
markus@x4 tmp % g++ -O2 -flifetime-dse=2 lifetime-dse.cpp
markus@x4 tmp % ./a.out
a.out: lifetime-dse.cpp:17: int main(): Assertion `a->value == -1' failed.
[1] 21394 abort ./a.out