107163879Schristos /* This testcase is part of GDB, the GNU debugger.
207163879Schristos 
3*1424dfb3Schristos    Copyright 2002-2020 Free Software Foundation, Inc.
407163879Schristos 
507163879Schristos    This program is free software; you can redistribute it and/or modify
607163879Schristos    it under the terms of the GNU General Public License as published by
707163879Schristos    the Free Software Foundation; either version 3 of the License, or
807163879Schristos    (at your option) any later version.
907163879Schristos 
1007163879Schristos    This program is distributed in the hope that it will be useful,
1107163879Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1207163879Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1307163879Schristos    GNU General Public License for more details.
1407163879Schristos 
1507163879Schristos    You should have received a copy of the GNU General Public License
1607163879Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
1707163879Schristos 
1807163879Schristos struct aggregate
1907163879Schristos {
2007163879Schristos   int i1;
2107163879Schristos   int i2;
2207163879Schristos   int i3;
2307163879Schristos };
2407163879Schristos 
keepalive_float(double * var)2507163879Schristos void keepalive_float (double *var) { }
keepalive_int(int * var)2607163879Schristos void keepalive_int (int *var) { }
keepalive_aggregate(struct aggregate * var)2707163879Schristos void keepalive_aggregate (struct aggregate *var) { }
2807163879Schristos 
2907163879Schristos #define PREFIXIFY(PREFIX, VAR)			\
3007163879Schristos   PREFIX ## _ ## VAR
3107163879Schristos 
3207163879Schristos #define DEF_STATICS(PREFIX)						\
3307163879Schristos   static int PREFIXIFY(PREFIX, s_var_int) = 4;				\
3407163879Schristos   static double PREFIXIFY(PREFIX, s_var_float) = 3.14f;			\
3507163879Schristos   static struct aggregate PREFIXIFY(PREFIX, s_var_aggregate)		\
3607163879Schristos     = { 1, 2, 3 };							\
3707163879Schristos 									\
3807163879Schristos   keepalive_int (&PREFIXIFY(PREFIX, s_var_int));			\
3907163879Schristos   keepalive_float (&PREFIXIFY(PREFIX, s_var_float));			\
4007163879Schristos   keepalive_aggregate (&PREFIXIFY(PREFIX, s_var_aggregate));
4107163879Schristos 
4207163879Schristos #ifdef __cplusplus
4307163879Schristos 
4407163879Schristos struct S
4507163879Schristos {
inline_methodS4607163879Schristos   void inline_method ()
4707163879Schristos   {
4807163879Schristos     DEF_STATICS (S_IM);
4907163879Schristos   }
static_inline_methodS5007163879Schristos   static void static_inline_method ()
5107163879Schristos   {
5207163879Schristos     DEF_STATICS (S_SIM);
5307163879Schristos   }
5407163879Schristos 
5507163879Schristos   void method ();
5607163879Schristos   void method () const;
5707163879Schristos   void method () volatile;
5807163879Schristos   void method () volatile const;
5907163879Schristos 
6007163879Schristos   static void static_method ();
6107163879Schristos };
6207163879Schristos 
6307163879Schristos S s;
6407163879Schristos const S c_s = {};
6507163879Schristos volatile S v_s = {};
6607163879Schristos const volatile S cv_s = {};
6707163879Schristos 
6807163879Schristos void
method()6907163879Schristos S::method ()
7007163879Schristos {
7107163879Schristos   DEF_STATICS (S_M);
7207163879Schristos }
7307163879Schristos 
7407163879Schristos void
method()7507163879Schristos S::method () const
7607163879Schristos {
7707163879Schristos   DEF_STATICS (S_M_C);
7807163879Schristos }
7907163879Schristos 
8007163879Schristos void
method()8107163879Schristos S::method () volatile
8207163879Schristos {
8307163879Schristos   DEF_STATICS (S_M_V);
8407163879Schristos }
8507163879Schristos 
8607163879Schristos void
method()8707163879Schristos S::method () const volatile
8807163879Schristos {
8907163879Schristos   DEF_STATICS (S_M_CV);
9007163879Schristos }
9107163879Schristos 
9207163879Schristos void
static_method()9307163879Schristos S::static_method ()
9407163879Schristos {
9507163879Schristos   DEF_STATICS (S_SM);
9607163879Schristos }
9707163879Schristos 
9807163879Schristos template <typename T>
9907163879Schristos struct S2
10007163879Schristos {
10107163879Schristos   void method ();
10207163879Schristos   static void static_method ();
10307163879Schristos 
inline_methodS210407163879Schristos   void inline_method ()
10507163879Schristos   {
10607163879Schristos     DEF_STATICS (S2_IM);
10707163879Schristos   }
10807163879Schristos 
static_inline_methodS210907163879Schristos   static void static_inline_method ()
11007163879Schristos   {
11107163879Schristos     DEF_STATICS (S2_SIM);
11207163879Schristos   }
11307163879Schristos };
11407163879Schristos 
11507163879Schristos template<typename T>
11607163879Schristos void
method()11707163879Schristos S2<T>::method ()
11807163879Schristos {
11907163879Schristos   DEF_STATICS (S2_M);
12007163879Schristos }
12107163879Schristos 
12207163879Schristos template<typename T>
12307163879Schristos void
static_method()12407163879Schristos S2<T>::static_method ()
12507163879Schristos {
12607163879Schristos   DEF_STATICS (S2_SM);
12707163879Schristos }
12807163879Schristos 
12907163879Schristos S2<int> s2;
13007163879Schristos 
13107163879Schristos #endif
13207163879Schristos 
13307163879Schristos void
free_func(void)13407163879Schristos free_func (void)
13507163879Schristos {
13607163879Schristos   DEF_STATICS (FF);
13707163879Schristos }
13807163879Schristos 
13907163879Schristos static inline void
free_inline_func(void)14007163879Schristos free_inline_func (void)
14107163879Schristos {
14207163879Schristos   DEF_STATICS (FIF);
14307163879Schristos }
14407163879Schristos 
14507163879Schristos int
main()14607163879Schristos main ()
14707163879Schristos {
148*1424dfb3Schristos   int i;
149*1424dfb3Schristos 
150*1424dfb3Schristos   for (i = 0; i < 1000; i++)
15107163879Schristos     {
15207163879Schristos       free_func ();
15307163879Schristos       free_inline_func ();
15407163879Schristos 
15507163879Schristos #ifdef __cplusplus
15607163879Schristos       s.method ();
15707163879Schristos       c_s.method ();
15807163879Schristos       v_s.method ();
15907163879Schristos       cv_s.method ();
16007163879Schristos       s.inline_method ();
16107163879Schristos       S::static_method ();
16207163879Schristos       S::static_inline_method ();
16307163879Schristos 
16407163879Schristos       s2.method ();
16507163879Schristos       s2.inline_method ();
16607163879Schristos       S2<int>::static_method ();
16707163879Schristos       S2<int>::static_inline_method ();
16807163879Schristos #endif
16907163879Schristos     }
17007163879Schristos 
17107163879Schristos   return 0;
17207163879Schristos }
173