This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/71885] Incorrect code generated with -01, memset() function call is missing


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]