[c++] fix pr opt/6793

Richard Henderson rth@redhat.com
Sun Jun 16 17:34:00 GMT 2002


A regression from before the tree-inliner, so the test passed
in e.g. 2.95.  Applied mainline and branch.

I also note that the C cannot_inline function checks for other
things like calling setjmp, or using computed gotos.  I don't
see these checks in the C++ version, which is almost certainly
a mistake.  Probably the C++ version should do template 
instantiation, then defer to the C version.  That's probably
only appropriate for mainline though, and not addressed here.


r~


        * tree.c (cp_cannot_inline_tree_fn): Don't short-circuit test
        after template instantiation.

Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/tree.c,v
retrieving revision 1.285
diff -c -p -d -r1.285 tree.c
*** tree.c	4 Jun 2002 07:10:24 -0000	1.285
--- tree.c	17 Jun 2002 00:05:15 -0000
*************** cp_cannot_inline_tree_fn (fnp)
*** 2162,2168 ****
        && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
      {
        fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
!       return TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn));
      }
  
    if (varargs_function_p (fn))
--- 2162,2169 ----
        && TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
      {
        fn = *fnp = instantiate_decl (fn, /*defer_ok=*/0);
!       if (TI_PENDING_TEMPLATE_FLAG (DECL_TEMPLATE_INFO (fn)))
! 	return 1;
      }
  
    if (varargs_function_p (fn))
Index: testsuite/g++.dg/opt/inline3.C
===================================================================
RCS file: testsuite/g++.dg/opt/inline3.C
diff -N testsuite/g++.dg/opt/inline3.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/opt/inline3.C	17 Jun 2002 00:24:33 -0000
***************
*** 0 ****
--- 1,40 ----
+ // PR opt/6793
+ // We failed to supress inlining of a varargs function when it's a template.
+ // { dg-do compile }
+ // { dg-options "-O3" }
+ 
+ #include <stdarg.h>
+ 
+ typedef __SIZE_TYPE__ size_t;
+ 
+ template < class Type > class VectorNd
+ {
+   size_t size;
+   Type *data;
+  public:
+ 
+   VectorNd (size_t _size, size_t count, ...)
+ 	: size (_size)
+   {
+     data = new Type[size];
+ 
+     va_list ap;
+ 
+     va_start (ap, count);
+ 
+     for (size_t i = 0; i < count; i++)
+       data[i] = va_arg (ap, Type);
+ 
+     va_end (ap);
+   }
+ 
+   ~VectorNd ()
+   {
+     delete [] data;
+   }
+ };
+ 
+ int main ()
+ {
+   VectorNd <double> vector (3, 3, 1.0, 2.0, 3.0);
+ }



More information about the Gcc-patches mailing list