Debian Codegraph @

gcc/testsuite/g++.dg/ipa/pr89693.C

raw
1 // Copyright (C) 2005 Free Software Foundation, Inc.
2 // Contributed by Nathan Sidwell 4 Apr 2005 <[email protected]>
3 // Re-purposed to check for re-rurgesnce of PR 89693 in 2019.
4
5 // { dg-do compile }
6 // { dg-options "-O3 -fno-ipa-icf-functions" }
7
8 // Origin: [email protected]
9 // [email protected]
10
11 struct A {
12 virtual void One ();
13 };
14 struct B {
15 virtual B *Two ();
16 virtual B &Three ();
17 };
18
19 struct C : A, B
20 {
21 virtual C *Two ();
22 virtual C &Three ();
23 };
24 void A::One () {}
25 B *B::Two() {return this;}
26 B &B::Three() {return *this;}
27 C *C::Two () {return 0;}
28 C &C::Three () {return *(C *)0;}
29
30 B *Foo (B *b)
31 {
32 return b->Two ();
33 }
34
35 B &Bar (B *b)
36 {
37 return b->Three ();
38 }
39
40 int main ()
41 {
42 C c;
43
44 /* We should not adjust a null pointer. */
45 if (Foo (&c))
46 return 1;
47 /* But we should adjust a (bogus) null reference. */
48 if (!&Bar (&c))
49 return 2;
50
51 return 0;
52 }