xref: /minix3/external/bsd/llvm/dist/clang/test/CodeGenCXX/debug-info-use-after-free.cpp (revision f4a2713ac843a11c696ec80c0a5e3e5d80b4d338)
1*f4a2713aSLionel Sambuc // RUN: %clang_cc1 -g -emit-llvm-only %s
2*f4a2713aSLionel Sambuc // Check that we don't crash.
3*f4a2713aSLionel Sambuc // PR12305, PR12315
4*f4a2713aSLionel Sambuc 
5*f4a2713aSLionel Sambuc # 1 "a.h"  3
6*f4a2713aSLionel Sambuc template < typename T1 > struct Types1
7*f4a2713aSLionel Sambuc {
8*f4a2713aSLionel Sambuc   typedef T1 Head;
9*f4a2713aSLionel Sambuc };
10*f4a2713aSLionel Sambuc template < typename > struct Types;
11*f4a2713aSLionel Sambuc template < template < typename > class Tmpl > struct TemplateSel
12*f4a2713aSLionel Sambuc {
13*f4a2713aSLionel Sambuc   template < typename T > struct Bind
14*f4a2713aSLionel Sambuc   {
15*f4a2713aSLionel Sambuc     typedef Tmpl < T > type;
16*f4a2713aSLionel Sambuc   };
17*f4a2713aSLionel Sambuc };
18*f4a2713aSLionel Sambuc template < typename > struct NoneT;
19*f4a2713aSLionel Sambuc template < template < typename > class T1, template < typename > class > struct Templates2
20*f4a2713aSLionel Sambuc {
21*f4a2713aSLionel Sambuc   typedef TemplateSel < T1 > Head;
22*f4a2713aSLionel Sambuc };
23*f4a2713aSLionel Sambuc template < template < typename > class, template < typename > class =
24*f4a2713aSLionel Sambuc   NoneT, template < typename > class = NoneT, template < typename > class =
25*f4a2713aSLionel Sambuc   NoneT > struct Templates;
26*f4a2713aSLionel Sambuc template < template < typename > class T1,
27*f4a2713aSLionel Sambuc   template < typename > class T2 > struct Templates <T1, T2 >
28*f4a2713aSLionel Sambuc {
29*f4a2713aSLionel Sambuc   typedef Templates2 < T1, T2 > type;
30*f4a2713aSLionel Sambuc };
31*f4a2713aSLionel Sambuc template < typename T > struct TypeList
32*f4a2713aSLionel Sambuc {
33*f4a2713aSLionel Sambuc   typedef Types1 < T > type;
34*f4a2713aSLionel Sambuc };
35*f4a2713aSLionel Sambuc template < template < typename > class, class TestSel,
36*f4a2713aSLionel Sambuc   typename Types > class TypeParameterizedTest
37*f4a2713aSLionel Sambuc {
38*f4a2713aSLionel Sambuc public:static bool Register ()
39*f4a2713aSLionel Sambuc   {
40*f4a2713aSLionel Sambuc     typedef typename Types::Head Type;
41*f4a2713aSLionel Sambuc     typename TestSel::template Bind < Type >::type TestClass;
42*f4a2713aSLionel Sambuc }};
43*f4a2713aSLionel Sambuc 
44*f4a2713aSLionel Sambuc template < template < typename > class Fixture, typename Tests,
45*f4a2713aSLionel Sambuc   typename Types > class TypeParameterizedTestCase
46*f4a2713aSLionel Sambuc {
47*f4a2713aSLionel Sambuc public:static bool Register (char *, char *, int *)
48*f4a2713aSLionel Sambuc   {
49*f4a2713aSLionel Sambuc     typedef typename Tests::Head Head;
50*f4a2713aSLionel Sambuc     TypeParameterizedTest < Fixture, Head, Types >::Register;
51*f4a2713aSLionel Sambuc }};
52*f4a2713aSLionel Sambuc 
53*f4a2713aSLionel Sambuc template < typename > class TypedTestP1
54*f4a2713aSLionel Sambuc {
55*f4a2713aSLionel Sambuc };
56*f4a2713aSLionel Sambuc 
57*f4a2713aSLionel Sambuc namespace gtest_case_TypedTestP1_
58*f4a2713aSLionel Sambuc {
59*f4a2713aSLionel Sambuc   template < typename gtest_TypeParam_ > class A:TypedTestP1 <
60*f4a2713aSLionel Sambuc     gtest_TypeParam_ >
61*f4a2713aSLionel Sambuc   {
62*f4a2713aSLionel Sambuc   };
63*f4a2713aSLionel Sambuc template < typename gtest_TypeParam_ > class B:TypedTestP1 <
64*f4a2713aSLionel Sambuc     gtest_TypeParam_ >
65*f4a2713aSLionel Sambuc   {
66*f4a2713aSLionel Sambuc   };
67*f4a2713aSLionel Sambuc   typedef Templates < A >::type gtest_AllTests_;
68*f4a2713aSLionel Sambuc }
69*f4a2713aSLionel Sambuc 
70*f4a2713aSLionel Sambuc template < typename > class TypedTestP2
71*f4a2713aSLionel Sambuc {
72*f4a2713aSLionel Sambuc };
73*f4a2713aSLionel Sambuc 
74*f4a2713aSLionel Sambuc namespace gtest_case_TypedTestP2_
75*f4a2713aSLionel Sambuc {
76*f4a2713aSLionel Sambuc   template < typename gtest_TypeParam_ > class A:TypedTestP2 <
77*f4a2713aSLionel Sambuc     gtest_TypeParam_ >
78*f4a2713aSLionel Sambuc   {
79*f4a2713aSLionel Sambuc   };
80*f4a2713aSLionel Sambuc   typedef Templates < A >::type gtest_AllTests_;
81*f4a2713aSLionel Sambuc }
82*f4a2713aSLionel Sambuc 
83*f4a2713aSLionel Sambuc bool gtest_Int_TypedTestP1 =
84*f4a2713aSLionel Sambuc   TypeParameterizedTestCase < TypedTestP1,
85*f4a2713aSLionel Sambuc   gtest_case_TypedTestP1_::gtest_AllTests_,
86*f4a2713aSLionel Sambuc   TypeList < int >::type >::Register ("Int", "TypedTestP1", 0);
87*f4a2713aSLionel Sambuc bool gtest_Int_TypedTestP2 =
88*f4a2713aSLionel Sambuc   TypeParameterizedTestCase < TypedTestP2,
89*f4a2713aSLionel Sambuc   gtest_case_TypedTestP2_::gtest_AllTests_,
90*f4a2713aSLionel Sambuc   TypeList < Types < int > >::type >::Register ("Int", "TypedTestP2", 0);
91*f4a2713aSLionel Sambuc 
92*f4a2713aSLionel Sambuc template < typename _Tp > struct new_allocator
93*f4a2713aSLionel Sambuc {
94*f4a2713aSLionel Sambuc   typedef _Tp *pointer;
95*f4a2713aSLionel Sambuc   template < typename > struct rebind {
96*f4a2713aSLionel Sambuc     typedef new_allocator other;
97*f4a2713aSLionel Sambuc   };
98*f4a2713aSLionel Sambuc };
99*f4a2713aSLionel Sambuc template < typename _Tp > struct allocator:new_allocator < _Tp > {
100*f4a2713aSLionel Sambuc };
101*f4a2713aSLionel Sambuc template < typename _Tp, typename _Alloc > struct _Vector_base {
102*f4a2713aSLionel Sambuc   typedef typename _Alloc::template rebind < _Tp >::other _Tp_alloc_type;
103*f4a2713aSLionel Sambuc   struct _Vector_impl {
104*f4a2713aSLionel Sambuc     typename _Tp_alloc_type::pointer _M_end_of_storage;
105*f4a2713aSLionel Sambuc   };
106*f4a2713aSLionel Sambuc   _Vector_base () {
107*f4a2713aSLionel Sambuc     foo((int *) this->_M_impl._M_end_of_storage);
108*f4a2713aSLionel Sambuc   }
109*f4a2713aSLionel Sambuc   void foo(int *);
110*f4a2713aSLionel Sambuc   _Vector_impl _M_impl;
111*f4a2713aSLionel Sambuc };
112*f4a2713aSLionel Sambuc template < typename _Tp, typename _Alloc =
113*f4a2713aSLionel Sambuc allocator < _Tp > >struct vector:_Vector_base < _Tp, _Alloc > { };
114*f4a2713aSLionel Sambuc 
115*f4a2713aSLionel Sambuc 
116*f4a2713aSLionel Sambuc template < class T> struct HHH {};
117*f4a2713aSLionel Sambuc struct DDD { int x_;};
118*f4a2713aSLionel Sambuc struct Data;
119*f4a2713aSLionel Sambuc struct X1;
120*f4a2713aSLionel Sambuc struct CCC:DDD {   virtual void xxx (HHH < X1 >); };
121*f4a2713aSLionel Sambuc template < class SSS > struct EEE:vector < HHH < SSS > > { };
122*f4a2713aSLionel Sambuc template < class SSS, class = EEE < SSS > >class FFF { };
123*f4a2713aSLionel Sambuc template < class SSS, class GGG = EEE < SSS > >class AAA:FFF <GGG> { };
124*f4a2713aSLionel Sambuc class BBB:virtual CCC {
125*f4a2713aSLionel Sambuc   void xxx (HHH < X1 >);
126*f4a2713aSLionel Sambuc   vector < HHH < X1 > >aaa;
127*f4a2713aSLionel Sambuc };
128*f4a2713aSLionel Sambuc class ZZZ:AAA < Data >, BBB { virtual ZZZ *ppp () ; };
129*f4a2713aSLionel Sambuc ZZZ * ZZZ::ppp () { return new ZZZ; }
130*f4a2713aSLionel Sambuc 
131*f4a2713aSLionel Sambuc namespace std
132*f4a2713aSLionel Sambuc {
133*f4a2713aSLionel Sambuc   template < class, class > struct pair;
134*f4a2713aSLionel Sambuc }
135*f4a2713aSLionel Sambuc namespace __gnu_cxx {
136*f4a2713aSLionel Sambuc template < typename > class new_allocator;
137*f4a2713aSLionel Sambuc }
138*f4a2713aSLionel Sambuc namespace std {
139*f4a2713aSLionel Sambuc template < typename _Tp > class allocator:__gnu_cxx::new_allocator < _Tp > {
140*f4a2713aSLionel Sambuc };
141*f4a2713aSLionel Sambuc template < typename, typename > struct _Vector_base {
142*f4a2713aSLionel Sambuc };
143*f4a2713aSLionel Sambuc template < typename _Tp, typename _Alloc = std::allocator < _Tp > >class vector:_Vector_base < _Tp,
144*f4a2713aSLionel Sambuc   _Alloc
145*f4a2713aSLionel Sambuc         > {
146*f4a2713aSLionel Sambuc         };
147*f4a2713aSLionel Sambuc }
148*f4a2713aSLionel Sambuc 
149*f4a2713aSLionel Sambuc namespace
150*f4a2713aSLionel Sambuc std {
151*f4a2713aSLionel Sambuc   template <
152*f4a2713aSLionel Sambuc       typename,
153*f4a2713aSLionel Sambuc       typename > struct unary_function;
154*f4a2713aSLionel Sambuc   template <
155*f4a2713aSLionel Sambuc       typename,
156*f4a2713aSLionel Sambuc       typename,
157*f4a2713aSLionel Sambuc       typename > struct binary_function;
158*f4a2713aSLionel Sambuc   template <
159*f4a2713aSLionel Sambuc       typename
160*f4a2713aSLionel Sambuc       _Tp > struct equal_to:
161*f4a2713aSLionel Sambuc         binary_function <
162*f4a2713aSLionel Sambuc         _Tp,
163*f4a2713aSLionel Sambuc         _Tp,
164*f4a2713aSLionel Sambuc         bool > {
165*f4a2713aSLionel Sambuc         };
166*f4a2713aSLionel Sambuc   template <
167*f4a2713aSLionel Sambuc       typename
168*f4a2713aSLionel Sambuc       _Pair > struct _Select1st:
169*f4a2713aSLionel Sambuc         unary_function <
170*f4a2713aSLionel Sambuc         _Pair,
171*f4a2713aSLionel Sambuc         typename
172*f4a2713aSLionel Sambuc         _Pair::first_type > {
173*f4a2713aSLionel Sambuc         };
174*f4a2713aSLionel Sambuc }
175*f4a2713aSLionel Sambuc # 1 "f.h"  3
176*f4a2713aSLionel Sambuc using
177*f4a2713aSLionel Sambuc std::pair;
178*f4a2713aSLionel Sambuc namespace
179*f4a2713aSLionel Sambuc __gnu_cxx {
180*f4a2713aSLionel Sambuc   template <
181*f4a2713aSLionel Sambuc       class > struct hash;
182*f4a2713aSLionel Sambuc   template <
183*f4a2713aSLionel Sambuc       class,
184*f4a2713aSLionel Sambuc       class,
185*f4a2713aSLionel Sambuc       class,
186*f4a2713aSLionel Sambuc       class,
187*f4a2713aSLionel Sambuc       class
188*f4a2713aSLionel Sambuc           _EqualKey,
189*f4a2713aSLionel Sambuc       class >
190*f4a2713aSLionel Sambuc           class
191*f4a2713aSLionel Sambuc           hashtable {
192*f4a2713aSLionel Sambuc            public:
193*f4a2713aSLionel Sambuc             typedef _EqualKey
194*f4a2713aSLionel Sambuc                 key_equal;
195*f4a2713aSLionel Sambuc             typedef void key_type;
196*f4a2713aSLionel Sambuc           };
197*f4a2713aSLionel Sambuc   using
198*f4a2713aSLionel Sambuc       std::equal_to;
199*f4a2713aSLionel Sambuc   using
200*f4a2713aSLionel Sambuc       std::allocator;
201*f4a2713aSLionel Sambuc   using
202*f4a2713aSLionel Sambuc       std::_Select1st;
203*f4a2713aSLionel Sambuc   template < class _Key, class _Tp, class _HashFn =
204*f4a2713aSLionel Sambuc       hash < _Key >, class _EqualKey = equal_to < _Key >, class _Alloc =
205*f4a2713aSLionel Sambuc       allocator < _Tp > >class hash_map {
206*f4a2713aSLionel Sambuc         typedef
207*f4a2713aSLionel Sambuc             hashtable <
208*f4a2713aSLionel Sambuc             pair <
209*f4a2713aSLionel Sambuc             _Key,
210*f4a2713aSLionel Sambuc         _Tp >,
211*f4a2713aSLionel Sambuc         _Key,
212*f4a2713aSLionel Sambuc         _HashFn,
213*f4a2713aSLionel Sambuc         _Select1st <
214*f4a2713aSLionel Sambuc             pair <
215*f4a2713aSLionel Sambuc             _Key,
216*f4a2713aSLionel Sambuc         _Tp > >,
217*f4a2713aSLionel Sambuc         _EqualKey,
218*f4a2713aSLionel Sambuc         _Alloc >
219*f4a2713aSLionel Sambuc             _Ht;
220*f4a2713aSLionel Sambuc        public:
221*f4a2713aSLionel Sambuc         typedef typename _Ht::key_type key_type;
222*f4a2713aSLionel Sambuc         typedef typename
223*f4a2713aSLionel Sambuc             _Ht::key_equal
224*f4a2713aSLionel Sambuc             key_equal;
225*f4a2713aSLionel Sambuc       };
226*f4a2713aSLionel Sambuc }
227*f4a2713aSLionel Sambuc using
228*f4a2713aSLionel Sambuc __gnu_cxx::hash_map;
229*f4a2713aSLionel Sambuc class
230*f4a2713aSLionel Sambuc C2;
231*f4a2713aSLionel Sambuc template < class > class scoped_ptr {
232*f4a2713aSLionel Sambuc };
233*f4a2713aSLionel Sambuc namespace {
234*f4a2713aSLionel Sambuc class
235*f4a2713aSLionel Sambuc     AAA {
236*f4a2713aSLionel Sambuc       virtual ~
237*f4a2713aSLionel Sambuc           AAA () {
238*f4a2713aSLionel Sambuc           }};
239*f4a2713aSLionel Sambuc }
240*f4a2713aSLionel Sambuc template < typename > class EEE;
241*f4a2713aSLionel Sambuc template < typename CCC, typename =
242*f4a2713aSLionel Sambuc typename CCC::key_equal, typename =
243*f4a2713aSLionel Sambuc EEE < CCC > >class III {
244*f4a2713aSLionel Sambuc };
245*f4a2713aSLionel Sambuc namespace
246*f4a2713aSLionel Sambuc util {
247*f4a2713aSLionel Sambuc   class
248*f4a2713aSLionel Sambuc       EEE {
249*f4a2713aSLionel Sambuc       };
250*f4a2713aSLionel Sambuc }
251*f4a2713aSLionel Sambuc namespace {
252*f4a2713aSLionel Sambuc class
253*f4a2713aSLionel Sambuc     C1:
254*f4a2713aSLionel Sambuc       util::EEE {
255*f4a2713aSLionel Sambuc        public:
256*f4a2713aSLionel Sambuc         class
257*f4a2713aSLionel Sambuc             C3:
258*f4a2713aSLionel Sambuc               AAA {
259*f4a2713aSLionel Sambuc                 struct FFF;
260*f4a2713aSLionel Sambuc                 typedef
261*f4a2713aSLionel Sambuc                     III <
262*f4a2713aSLionel Sambuc                     hash_map <
263*f4a2713aSLionel Sambuc                     C2,
264*f4a2713aSLionel Sambuc                     FFF > >
265*f4a2713aSLionel Sambuc                         GGG;
266*f4a2713aSLionel Sambuc                 GGG
267*f4a2713aSLionel Sambuc                     aaa;
268*f4a2713aSLionel Sambuc                 friend
269*f4a2713aSLionel Sambuc                     C1;
270*f4a2713aSLionel Sambuc               };
271*f4a2713aSLionel Sambuc         void
272*f4a2713aSLionel Sambuc             HHH (C3::GGG &);
273*f4a2713aSLionel Sambuc       };
274*f4a2713aSLionel Sambuc }
275*f4a2713aSLionel Sambuc namespace
276*f4a2713aSLionel Sambuc n1 {
277*f4a2713aSLionel Sambuc   class
278*f4a2713aSLionel Sambuc       Test {
279*f4a2713aSLionel Sambuc       };
280*f4a2713aSLionel Sambuc   template <
281*f4a2713aSLionel Sambuc       typename >
282*f4a2713aSLionel Sambuc       class
283*f4a2713aSLionel Sambuc       C7 {
284*f4a2713aSLionel Sambuc       };
285*f4a2713aSLionel Sambuc   class
286*f4a2713aSLionel Sambuc       C4:
287*f4a2713aSLionel Sambuc         n1::Test {
288*f4a2713aSLionel Sambuc           vector <
289*f4a2713aSLionel Sambuc               C1::C3 * >
290*f4a2713aSLionel Sambuc               a1;
291*f4a2713aSLionel Sambuc         };
292*f4a2713aSLionel Sambuc   enum C5 { };
293*f4a2713aSLionel Sambuc   class
294*f4a2713aSLionel Sambuc       C6:
295*f4a2713aSLionel Sambuc         C4,
296*f4a2713aSLionel Sambuc         n1::C7 <
297*f4a2713aSLionel Sambuc         C5 > {
298*f4a2713aSLionel Sambuc         };
299*f4a2713aSLionel Sambuc   class
300*f4a2713aSLionel Sambuc       C8:
301*f4a2713aSLionel Sambuc         C6 {
302*f4a2713aSLionel Sambuc         };
303*f4a2713aSLionel Sambuc   class
304*f4a2713aSLionel Sambuc       C9:
305*f4a2713aSLionel Sambuc         C8 {
306*f4a2713aSLionel Sambuc           void
307*f4a2713aSLionel Sambuc               TestBody ();
308*f4a2713aSLionel Sambuc         };
309*f4a2713aSLionel Sambuc   void
310*f4a2713aSLionel Sambuc       C9::TestBody () {
311*f4a2713aSLionel Sambuc         scoped_ptr < C1::C3 > context;
312*f4a2713aSLionel Sambuc       }
313*f4a2713aSLionel Sambuc }
314