OSDN Git Service

* function.c (assign_parms): Set last_named only for last named
authorjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2001 09:29:54 +0000 (09:29 +0000)
committerjakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4>
Tue, 4 Dec 2001 09:29:54 +0000 (09:29 +0000)
argument.

* g++.dg/other/stdarg1.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@47601 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/ChangeLog
gcc/function.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/other/stdarg1.C [new file with mode: 0644]

index a3a4cd4..dff736e 100644 (file)
@@ -1,3 +1,8 @@
+2001-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * function.c (assign_parms): Set last_named only for last named
+       argument.
+
 2001-12-04  Joseph S. Myers  <jsm28@cam.ac.uk>
 
        * doc/install.texi: Use the GFDL.  Include years from old install
index 04f8ca6..653e2ab 100644 (file)
@@ -4307,16 +4307,25 @@ assign_parms (fndecl)
       tree passed_type = DECL_ARG_TYPE (parm);
       tree nominal_type = TREE_TYPE (parm);
       int pretend_named;
+      int last_named = 0, named_arg;
 
-      /* Set LAST_NAMED if this is last named arg before some
+      /* Set LAST_NAMED if this is last named arg before last
         anonymous args.  */
-      int last_named = ((TREE_CHAIN (parm) == 0
-                        || DECL_NAME (TREE_CHAIN (parm)) == 0)
-                       && (stdarg || current_function_varargs));
+      if (stdarg || current_function_varargs)
+       {
+         tree tem;
+
+         for (tem = TREE_CHAIN (parm); tem; tem = TREE_CHAIN (tem))
+           if (DECL_NAME (tem))
+             break;
+
+         if (tem == 0)
+           last_named = 1;
+       }
       /* Set NAMED_ARG if this arg should be treated as a named arg.  For
         most machines, if this is a varargs/stdarg function, then we treat
         the last named arg as if it were anonymous too.  */
-      int named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
+      named_arg = STRICT_ARGUMENT_NAMING ? 1 : ! last_named;
 
       if (TREE_TYPE (parm) == error_mark_node
          /* This can happen after weird syntax errors
index 4bb0e18..4c7036f 100644 (file)
@@ -1,3 +1,7 @@
+2001-12-04  Jakub Jelinek  <jakub@redhat.com>
+
+       * g++.dg/other/stdarg1.C: New test.
+
 2001-12-03  Janis Johnson  <janis187@us.ibm.com>
 
        * gcc.c-torture/execute/builtin-prefetch-1.c: New test.
diff --git a/gcc/testsuite/g++.dg/other/stdarg1.C b/gcc/testsuite/g++.dg/other/stdarg1.C
new file mode 100644 (file)
index 0000000..3b7718b
--- /dev/null
@@ -0,0 +1,26 @@
+// Test stdarg function with anonymous argument
+// { dg-do run }
+
+#include <stdarg.h>
+
+extern "C" void abort (void);
+
+void baz (va_list list)
+{
+  if (va_arg (list, long) != 3)
+    abort ();
+}
+
+void foo (long p1, long, long p2, ...)
+{
+  va_list list;
+  va_start (list, p2);
+  baz (list);
+  va_end (list);
+}
+
+int main ()
+{
+  foo (0, 1, 2, 3);
+  return 0;
+}