OSDN Git Service

./:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 May 2009 22:45:54 +0000 (22:45 +0000)
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 29 May 2009 22:45:54 +0000 (22:45 +0000)
* builtins.c (validate_gimple_arglist): Don't use va_arg with
enum type.
* calls.c (emit_library_call_value_1): Likewise.

* c-typeck.c (c_build_va_arg): New function.
* c-tree.h (c_build_va_arg): Declare.
* c-parser.c (c_parser_postfix_expression): Call c_build_va_arg
instead of build_va_arg.
cp/:
* error.c (cp_printer): Don't use va_arg with enum type.
testsuite/:
* gcc.dg/Wcxx-compat-11.c: New testcase.

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

gcc/ChangeLog
gcc/builtins.c
gcc/c-parser.c
gcc/c-tree.h
gcc/c-typeck.c
gcc/calls.c
gcc/cp/ChangeLog
gcc/cp/error.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/Wcxx-compat-11.c [new file with mode: 0644]

index 8315dac..f101cbf 100644 (file)
@@ -1,3 +1,14 @@
+2009-05-29  Ian Lance Taylor  <iant@google.com>
+
+       * builtins.c (validate_gimple_arglist): Don't use va_arg with
+       enum type.
+       * calls.c (emit_library_call_value_1): Likewise.
+
+       * c-typeck.c (c_build_va_arg): New function.
+       * c-tree.h (c_build_va_arg): Declare.
+       * c-parser.c (c_parser_postfix_expression): Call c_build_va_arg
+       instead of build_va_arg.
+
 2009-05-29  Eric Botcazou  <ebotcazou@adacore.com>
 
        * tree-ssa-loop-ivopts.c (strip_offset_1) <MULT_EXPR>: New case.
index 6d9f282..80ff09d 100644 (file)
@@ -11231,7 +11231,7 @@ validate_gimple_arglist (const_gimple call, ...)
 
   do
     {
-      code = va_arg (ap, enum tree_code);
+      code = (enum tree_code) va_arg (ap, int);
       switch (code)
        {
        case 0:
@@ -11282,7 +11282,7 @@ validate_arglist (const_tree callexpr, ...)
 
   do
     {
-      code = va_arg (ap, enum tree_code);
+      code = (enum tree_code) va_arg (ap, int);
       switch (code)
        {
        case 0:
index 0320fee..244c238 100644 (file)
@@ -5338,6 +5338,7 @@ c_parser_postfix_expression (c_parser *parser)
              expr.value = error_mark_node;
              break;
            }
+         loc = c_parser_peek_token (parser)->location;
          t1 = c_parser_type_name (parser);
          c_parser_skip_until_found (parser, CPP_CLOSE_PAREN,
                                     "expected %<)%>");
@@ -5348,9 +5349,9 @@ c_parser_postfix_expression (c_parser *parser)
          else
            {
              tree type_expr = NULL_TREE;
-             expr.value = build_va_arg (e1.value, groktypename (t1,
-                                                                &type_expr,
-                                                                NULL));
+             expr.value = c_build_va_arg (e1.value,
+                                          groktypename (t1, &type_expr, NULL),
+                                          loc);
              if (type_expr)
                {
                  expr.value = build2 (C_MAYBE_CONST_EXPR,
index 6062d59..05b52d8 100644 (file)
@@ -650,6 +650,7 @@ extern tree c_finish_omp_parallel (tree, tree);
 extern tree c_begin_omp_task (void);
 extern tree c_finish_omp_task (tree, tree);
 extern tree c_finish_omp_clauses (tree);
+extern tree c_build_va_arg (tree, tree, location_t);
 
 /* Set to 0 at beginning of a function definition, set to 1 if
    a return statement that specifies a return value is seen.  */
index 1a1b009..43cb6f3 100644 (file)
@@ -9976,3 +9976,14 @@ c_build_qualified_type (tree type, int type_quals)
 
   return build_qualified_type (type, type_quals);
 }
+
+/* Build a VA_ARG_EXPR for the C parser.  */
+
+tree
+c_build_va_arg (tree expr, tree type, location_t loc)
+{
+  if (warn_cxx_compat && TREE_CODE (type) == ENUMERAL_TYPE)
+    warning_at (loc, OPT_Wc___compat,
+               "C++ requires promoted type, not enum type, in %<va_arg%>");
+  return build_va_arg (expr, type);
+}
index 219b1d3..c10b0cd 100644 (file)
@@ -3445,7 +3445,7 @@ emit_library_call_value_1 (int retval, rtx orgfun, rtx value,
   for (; count < nargs; count++)
     {
       rtx val = va_arg (p, rtx);
-      enum machine_mode mode = va_arg (p, enum machine_mode);
+      enum machine_mode mode = (enum machine_mode) va_arg (p, int);
 
       /* We cannot convert the arg value to the mode the library wants here;
         must do it earlier where we know the signedness of the arg.  */
index 11be689..e7e223e 100644 (file)
@@ -1,3 +1,7 @@
+2009-05-29  Ian Lance Taylor  <iant@google.com>
+
+       * error.c (cp_printer): Don't use va_arg with enum type.
+
 2009-05-28  Dodji Seketeli  <dodji@redhat.com>
 
        PR c++/39754
index 0bfb28e..004543d 100644 (file)
@@ -2761,8 +2761,8 @@ cp_printer (pretty_printer *pp, text_info *text, const char *spec,
   const char *result;
   tree t = NULL;
 #define next_tree    (t = va_arg (*text->args_ptr, tree))
-#define next_tcode   va_arg (*text->args_ptr, enum tree_code)
-#define next_lang    va_arg (*text->args_ptr, enum languages)
+#define next_tcode   ((enum tree_code) va_arg (*text->args_ptr, int))
+#define next_lang    ((enum languages) va_arg (*text->args_ptr, int))
 #define next_int     va_arg (*text->args_ptr, int)
 
   if (precision != 0 || wide)
index 214cf74..a78c416 100644 (file)
@@ -1,3 +1,7 @@
+2009-05-29  Ian Lance Taylor  <iant@google.com>
+
+       * gcc.dg/Wcxx-compat-11.c: New testcase.
+
 2009-05-29  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
 
        PR fortran/40019
diff --git a/gcc/testsuite/gcc.dg/Wcxx-compat-11.c b/gcc/testsuite/gcc.dg/Wcxx-compat-11.c
new file mode 100644 (file)
index 0000000..8818338
--- /dev/null
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-Wc++-compat" } */
+
+#include <stdarg.h>
+
+enum E { A };
+
+extern void f2 (int);
+void
+f1 (int n, ...)
+{
+  va_list ap;
+
+  va_start (ap, n);
+  f2 (va_arg (ap, int));
+  f2 (va_arg (ap, _Bool));     /* { dg-warning "promoted" } */
+  f2 (va_arg (ap, enum E));    /* { dg-warning "promoted" } */
+}
+
+/* Match extra informative notes.  */
+/* { dg-message "note:" "expected" { target *-*-* } 0 } */