Debian Codegraph @

gcc/testsuite/g++.dg/ipa/devirt-6.C

raw
1 /* Verify that we either do not do any devirtualization or correctly
2 spot that foo changes the dynamic type of the passed object. */
3
4 /* { dg-do run } */
5 /* { dg-options "-O3" } */
6
7 extern "C" void abort (void);
8 extern "C" void *malloc(__SIZE_TYPE__);
9
10 inline void* operator new(__SIZE_TYPE__, void* __p) throw() { return __p;}
11
12 int x;
13
14 class A {
15 public:
16 virtual ~A() { }
17 };
18
19 class B : public A {
20 public:
21 virtual ~B() { if (x == 1) abort (); x = 1; }
22 };
23
24 void __attribute__((noinline,noclone)) foo (void *p)
25 {
26 B *b = reinterpret_cast<B *>(p);
27 b->~B();
28 new (p) A;
29 }
30
31 int main()
32 {
33 void *p = __builtin_malloc (sizeof (B));
34 new (p) B;
35 foo(p);
36 reinterpret_cast<A *>(p)->~A();
37 return 0;
38 }