This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Suppress tree inlining of variadic functions


GCC can't inline functions that use varargs.  The immediate problem
(shown by the testcase) is that expand_builtin_next_arg, called from
expand_builtin_va_start, looks at current_function_decl and expects it
to be meaningful; on the testcase this leads it to complain about
being used in a function (file_name_as_prefix) which has fixed
arguments.  There are no doubt other problems.

Bootstrapped & tested on powerpc-darwin.

-- 
- Geoffrey Keating <geoffk@apple.com>

===File ~/patches/gcc-novararginline.patch==================
2003-04-29  Geoffrey Keating  <geoffk@apple.com>

	* tree-inline.c (inlinable_function_p): Don't support inlining
	functions using varargs.

Index: testsuite/ChangeLog
2003-04-29  Geoffrey Keating  <geoffk@apple.com>

	* gcc.c-torture/compile/inline-1.c: New file.

Index: tree-inline.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-inline.c,v
retrieving revision 1.54
diff -u -p -u -p -r1.54 tree-inline.c
--- tree-inline.c	29 Apr 2003 03:24:27 -0000	1.54
+++ tree-inline.c	29 Apr 2003 23:25:24 -0000
@@ -1008,6 +1008,13 @@ inlinable_function_p (fn, id, nolimit)
   else if (lookup_attribute ("always_inline", DECL_ATTRIBUTES (fn)) == NULL
 	   && find_alloca_call (DECL_SAVED_TREE (fn)))
     ;
+  /* Can't inline functions which use varargs.  It's not theoretically
+     impossible, we just don't do it yet; at least one problem is that
+     expand_builtin_next_arg needs to handle the situation.  */
+  else if (TYPE_ARG_TYPES (TREE_TYPE (fn)) != 0
+	   && (TREE_VALUE (tree_last (TYPE_ARG_TYPES (TREE_TYPE (fn))))
+	       != void_type_node))
+    ;
   /* All is well.  We can inline this function.  Traditionally, GCC
      has refused to inline functions using alloca, or functions whose
      values are returned in a PARALLEL, and a few other such obscure
Index: testsuite/gcc.c-torture/compile/inline-1.c
===================================================================
RCS file: testsuite/gcc.c-torture/compile/inline-1.c
diff -N testsuite/gcc.c-torture/compile/inline-1.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ testsuite/gcc.c-torture/compile/inline-1.c	29 Apr 2003 23:25:28 -0000
@@ -0,0 +1,21 @@
+typedef __builtin_va_list va_list;
+
+extern void foo (va_list);
+
+static void
+build_message_string (const char *msg, ...)
+{
+  va_list ap;
+
+  __builtin_va_start (ap, msg);
+  foo (ap);
+  __builtin_va_end (ap);
+}
+
+void
+file_name_as_prefix (f)
+     const char *f;
+{
+  build_message_string ("%s: ", f);
+}
+
============================================================


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]