Fortran: Fix PR 47485.
[gcc.git] / gcc / testsuite / g++.dg / ubsan / pr83555.C
blob6574923740c6dae76c908c8f750ca4d7d99e8180
1 // PR c++/83555
2 // { dg-do run }
3 // { dg-options "-fsanitize=null" }
4 // { dg-output ":25:\[^\n\r]*reference binding to null pointer of type 'struct C'" }
6 struct A { int a; };
7 struct B { int b; };
8 struct C : A, B { int c; };
10 __attribute__((noipa)) C *
11 foo (B *b)
13   return static_cast<C *>(b);
16 __attribute__((noipa)) C *
17 bar (B *b)
19   return &static_cast<C &>(*b);
22 __attribute__((noipa)) C *
23 baz (B *b)
25   return &static_cast<C &>(*b);
28 int
29 main ()
31   C c;
32   if (foo (static_cast<B *> (&c)) != &c)
33     __builtin_abort ();
34   if (foo (0))
35     __builtin_abort ();
36   if (bar (static_cast<B *> (&c)) != &c)
37     __builtin_abort ();
38   baz (0);
39   return 0;