This commit is contained in:
Jakub Jelinek 2007-09-07 07:12:55 +00:00
parent 2d7fb2fe4b
commit 062e14b258
2 changed files with 224 additions and 1 deletions

View File

@ -1,3 +1,11 @@
2007-09-07 Jakub Jelinek <jakub@redhat.com>
* tree.c (cp_cannot_inline_tree_fn): Don't mark varargs_function_p
as uninlinable.
* g++.dg/ext/va-arg-pack-1.C: New test.
* g++.dg/ext/va-arg-pack-2.C: New test.
2007-09-05 Jakub Jelinek <jakub@redhat.com>
* builtins.def (BUILT_IN_VA_ARG_PACK): New built-in.
@ -291,6 +299,21 @@
pp_character (buffer, ')');
op1 = TREE_OPERAND (node, 2);
--- gcc/cp/tree.c.jj 2007-03-12 08:28:01.000000000 +0100
+++ gcc/cp/tree.c 2007-09-07 09:03:07.000000000 +0200
@@ -2078,12 +2078,6 @@ cp_cannot_inline_tree_fn (tree* fnp)
return 1;
}
- if (varargs_function_p (fn))
- {
- DECL_UNINLINABLE (fn) = 1;
- return 1;
- }
-
if (! function_attribute_inlinable_p (fn))
{
DECL_UNINLINABLE (fn) = 1;
--- gcc/testsuite/gcc.c-torture/execute/va-arg-pack-1.c.jj 2007-09-06 10:19:25.000000000 +0200
+++ gcc/testsuite/gcc.c-torture/execute/va-arg-pack-1.c 2007-09-06 10:19:25.000000000 +0200
@@ -0,0 +1,143 @@
@ -500,3 +523,200 @@
+{
+ return bar (5, "", 6, __builtin_va_arg_pack ()); /* { dg-error "invalid use of" } */
+}
--- gcc/testsuite/g++.dg/ext/va-arg-pack-1.C.jj 2007-09-07 08:52:55.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/va-arg-pack-1.C 2007-09-07 08:53:45.000000000 +0200
@@ -0,0 +1,145 @@
+// __builtin_va_arg_pack () builtin tests.
+// { dg-do run }
+// { dg-options "-O2" }
+
+#include <stdarg.h>
+
+extern "C" void abort (void);
+
+int v1 = 8;
+long int v2 = 3;
+void *v3 = (void *) &v2;
+struct A { char c[16]; } v4 = { "foo" };
+long double v5 = 40;
+char seen[20];
+int cnt;
+
+__attribute__ ((noinline)) int
+foo1 (int x, int y, ...)
+{
+ int i;
+ long int l;
+ void *v;
+ struct A a;
+ long double ld;
+ va_list ap;
+
+ va_start (ap, y);
+ if (x < 0 || x >= 20 || seen[x])
+ abort ();
+ seen[x] = ++cnt;
+ if (y != 6)
+ abort ();
+ i = va_arg (ap, int);
+ if (i != 5)
+ abort ();
+ switch (x)
+ {
+ case 0:
+ i = va_arg (ap, int);
+ if (i != 9 || v1 != 9)
+ abort ();
+ a = va_arg (ap, struct A);
+ if (__builtin_memcmp (a.c, v4.c, sizeof (a.c)) != 0)
+ abort ();
+ v = (void *) va_arg (ap, struct A *);
+ if (v != (void *) &v4)
+ abort ();
+ l = va_arg (ap, long int);
+ if (l != 3 || v2 != 4)
+ abort ();
+ break;
+ case 1:
+ ld = va_arg (ap, long double);
+ if (ld != 41 || v5 != ld)
+ abort ();
+ i = va_arg (ap, int);
+ if (i != 8)
+ abort ();
+ v = va_arg (ap, void *);
+ if (v != &v2)
+ abort ();
+ break;
+ case 2:
+ break;
+ default:
+ abort ();
+ }
+ va_end (ap);
+ return x;
+}
+
+__attribute__ ((noinline)) int
+foo2 (int x, int y, ...)
+{
+ long long int ll;
+ void *v;
+ struct A a, b;
+ long double ld;
+ va_list ap;
+
+ va_start (ap, y);
+ if (x < 0 || x >= 20 || seen[x])
+ abort ();
+ seen[x] = ++cnt | 64;
+ if (y != 10)
+ abort ();
+ switch (x)
+ {
+ case 11:
+ break;
+ case 12:
+ ld = va_arg (ap, long double);
+ if (ld != 41 || v5 != 40)
+ abort ();
+ a = va_arg (ap, struct A);
+ if (__builtin_memcmp (a.c, v4.c, sizeof (a.c)) != 0)
+ abort ();
+ b = va_arg (ap, struct A);
+ if (__builtin_memcmp (b.c, v4.c, sizeof (b.c)) != 0)
+ abort ();
+ v = va_arg (ap, void *);
+ if (v != &v2)
+ abort ();
+ ll = va_arg (ap, long long int);
+ if (ll != 16LL)
+ abort ();
+ break;
+ case 2:
+ break;
+ default:
+ abort ();
+ }
+ va_end (ap);
+ return x + 8;
+}
+
+__attribute__ ((noinline)) int
+foo3 (void)
+{
+ return 6;
+}
+
+extern inline __attribute__ ((always_inline, gnu_inline)) int
+bar (int x, ...)
+{
+ if (x < 10)
+ return foo1 (x, foo3 (), 5, __builtin_va_arg_pack ());
+ return foo2 (x, foo3 () + 4, __builtin_va_arg_pack ());
+}
+
+int
+main (void)
+{
+ if (bar (0, ++v1, v4, &v4, v2++) != 0)
+ abort ();
+ if (bar (1, ++v5, 8, v3) != 1)
+ abort ();
+ if (bar (2) != 2)
+ abort ();
+ if (bar (v1 + 2) != 19)
+ abort ();
+ if (bar (v1 + 3, v5--, v4, v4, v3, 16LL) != 20)
+ abort ();
+ return 0;
+}
--- gcc/testsuite/g++.dg/ext/va-arg-pack-2.C.jj 2007-09-07 08:53:23.000000000 +0200
+++ gcc/testsuite/g++.dg/ext/va-arg-pack-2.C 2007-09-07 08:54:25.000000000 +0200
@@ -0,0 +1,46 @@
+// { dg-do compile }
+// { dg-options "-O2" }
+
+int bar (int, const char *, int, ...);
+int baz (int, const char *, long int);
+
+extern inline __attribute__((always_inline)) int
+f2 (int y, ...)
+{
+ return bar (y, "", __builtin_va_arg_pack ()); /* { dg-error "invalid use of" } */
+}
+
+extern inline __attribute__((always_inline)) int
+f3 (int y, ...)
+{
+ return bar (y, "", 5, __builtin_va_arg_pack ());
+}
+
+extern inline __attribute__((always_inline)) int
+f4 (int y, ...)
+{
+ return bar (y, "", 4, __builtin_va_arg_pack (), 6); /* { dg-error "invalid use of" } */
+}
+
+extern inline __attribute__((always_inline)) int
+f5 (int y, ...)
+{
+ return baz (y, "", __builtin_va_arg_pack ()); /* { dg-error "invalid use of" } */
+}
+
+extern inline __attribute__((always_inline)) int
+f6 (int y, ...)
+{
+ return __builtin_va_arg_pack (); /* { dg-error "invalid use of" } */
+}
+
+int
+test (void)
+{
+ int a = f2 (5, "a", 6);
+ a += f3 (6, "ab", 17LL);
+ a += f4 (7, 1, 2, 3);
+ a += f5 (8, 7L);
+ a += f6 (9);
+ return a;
+}

View File

@ -1,6 +1,6 @@
%define DATE 20070821
%define gcc_version 4.1.2
%define gcc_release 22
%define gcc_release 23
%define _unpackaged_files_terminate_build 0
%define multilib_64_archs sparc64 ppc64 s390x x86_64
%define include_gappletviewer 1
@ -1623,6 +1623,9 @@ fi
%doc rpm.doc/changelogs/libmudflap/ChangeLog*
%changelog
* Fri Sep 7 2007 Jakub Jelinek <jakub@redhat.com> 4.1.2-23
- fix __builtin_va_arg_pack () support for C++
* Thu Sep 6 2007 Jakub Jelinek <jakub@redhat.com> 4.1.2-22
- backport __builtin_va_arg_pack () support
- make sure __builtin_{,v}{,f}{print,scan}f, __builtin_{,f}printf_unlocked