builtins.c (expand_builtin_va_arg): Give warnings not errors for promoted argument...
authorRichard Henderson <rth@redhat.com>
Sun, 31 Mar 2002 09:52:42 +0000 (01:52 -0800)
committerRichard Henderson <rth@gcc.gnu.org>
Sun, 31 Mar 2002 09:52:42 +0000 (01:52 -0800)
        * builtins.c (expand_builtin_va_arg): Give warnings not errors for
        promoted argument types; build trap.
        (expand_builtin_trap): New.
        (expand_builtin): Use it.
        * stmt.c (expand_nl_goto_receivers): Likewise.
        * expr.h (expand_builtin_trap): Declare.
        * libfuncs.h (LTI_abort, abort_libfunc): New.
        * optabs.c (init_optabs): Init abort_libfunc.

        * gcc.dg/va-arg-1.c: Expect warnings, not errors.

From-SVN: r51643

gcc/ChangeLog
gcc/builtins.c
gcc/expr.h
gcc/libfuncs.h
gcc/optabs.c
gcc/stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/va-arg-1.c

index eae2a27d6f016caf761cf1e0a66253c1163cfd7b..d71c621fb0af3f0301f4ffca86e1880ae834affc 100644 (file)
@@ -1,3 +1,14 @@
+2002-03-31  Richard Henderson  <rth@redhat.com>
+
+       * builtins.c (expand_builtin_va_arg): Give warnings not errors for
+       promoted argument types; build trap.
+       (expand_builtin_trap): New.
+       (expand_builtin): Use it.
+       * stmt.c (expand_nl_goto_receivers): Likewise.
+       * expr.h (expand_builtin_trap): Declare.
+       * libfuncs.h (LTI_abort, abort_libfunc): New.
+       * optabs.c (init_optabs): Init abort_libfunc.
+
 2002-03-31  Alexandre Oliva  <aoliva@redhat.com>
 
        * gcc.c (LIBGCC_SPEC): Folded %L and duplicate %G here...
 2002-03-31  Alexandre Oliva  <aoliva@redhat.com>
 
        * gcc.c (LIBGCC_SPEC): Folded %L and duplicate %G here...
index eb117ceecfe9abc84937b50856c241eb5ce0c536..effd70d43ed30ae9c2fbc592d68d56d199d49f6d 100644 (file)
@@ -3079,7 +3079,7 @@ expand_builtin_va_arg (valist, type)
   else if ((promoted_type = (*lang_type_promotes_to) (type)) != NULL_TREE)
     {
       const char *name = "<anonymous type>", *pname = 0;
   else if ((promoted_type = (*lang_type_promotes_to) (type)) != NULL_TREE)
     {
       const char *name = "<anonymous type>", *pname = 0;
-      static int gave_help;
+      static bool gave_help;
 
       if (TYPE_NAME (type))
        {
 
       if (TYPE_NAME (type))
        {
@@ -3098,13 +3098,24 @@ expand_builtin_va_arg (valist, type)
            pname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (promoted_type)));
        }
 
            pname = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (promoted_type)));
        }
 
-      error ("`%s' is promoted to `%s' when passed through `...'", name, pname);
+      /* Unfortunately, this is merely undefined, rather than a constraint
+        violation, so we cannot make this an error.  If this call is never
+        executed, the program is still strictly conforming.  */
+      warning ("`%s' is promoted to `%s' when passed through `...'",
+              name, pname);
       if (! gave_help)
        {
       if (! gave_help)
        {
-         gave_help = 1;
-         error ("(so you should pass `%s' not `%s' to `va_arg')", pname, name);
+         gave_help = true;
+         warning ("(so you should pass `%s' not `%s' to `va_arg')",
+                  pname, name);
        }
 
        }
 
+      /* We can, however, treat "undefined" any way we please.
+        Call abort to encourage the user to fix the program.  */
+      expand_builtin_trap ();
+
+      /* This is dead code, but go ahead and finish so that the
+        mode of the result comes out right.  */
       addr = const0_rtx;
     }
   else
       addr = const0_rtx;
     }
   else
@@ -3556,6 +3567,18 @@ expand_builtin_expect_jump (exp, if_false_label, if_true_label)
 
   return ret;
 }
 
   return ret;
 }
+
+void
+expand_builtin_trap ()
+{
+#ifdef HAVE_trap
+  if (HAVE_trap)
+    emit_insn (gen_trap ());
+  else
+#endif
+    emit_library_call (abort_libfunc, LCT_NORETURN, VOIDmode, 0);
+  emit_barrier ();
+}
 \f
 /* Expand an expression EXP that calls a built-in function,
    with result going to TARGET if that's convenient
 \f
 /* Expand an expression EXP that calls a built-in function,
    with result going to TARGET if that's convenient
@@ -3890,13 +3913,7 @@ expand_builtin (exp, target, subtarget, mode, ignore)
        }
 
     case BUILT_IN_TRAP:
        }
 
     case BUILT_IN_TRAP:
-#ifdef HAVE_trap
-      if (HAVE_trap)
-       emit_insn (gen_trap ());
-      else
-#endif
-       error ("__builtin_trap not supported by this target");
-      emit_barrier ();
+      expand_builtin_trap ();
       return const0_rtx;
 
     case BUILT_IN_PUTCHAR:
       return const0_rtx;
 
     case BUILT_IN_PUTCHAR:
index 9ffc61fd9a8637ea8dd0cb5d94d782443ecd876a..91ffa3f0507dde0d1f932cb0adcf1c398a6093e4 100644 (file)
@@ -340,7 +340,6 @@ extern rtx get_condition PARAMS ((rtx, rtx *));
 extern rtx gen_cond_trap PARAMS ((enum rtx_code, rtx, rtx, rtx));
 \f
 /* Functions from builtins.c:  */
 extern rtx gen_cond_trap PARAMS ((enum rtx_code, rtx, rtx, rtx));
 \f
 /* Functions from builtins.c:  */
-#ifdef TREE_CODE
 extern rtx expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
 extern void std_expand_builtin_va_start PARAMS ((int, tree, rtx));
 extern rtx std_expand_builtin_va_arg PARAMS ((tree, tree));
 extern rtx expand_builtin PARAMS ((tree, rtx, rtx, enum machine_mode, int));
 extern void std_expand_builtin_va_start PARAMS ((int, tree, rtx));
 extern rtx std_expand_builtin_va_arg PARAMS ((tree, tree));
@@ -348,12 +347,11 @@ extern rtx expand_builtin_va_arg PARAMS ((tree, tree));
 extern void default_init_builtins PARAMS ((void));
 extern rtx default_expand_builtin PARAMS ((tree, rtx, rtx,
                                           enum machine_mode, int));
 extern void default_init_builtins PARAMS ((void));
 extern rtx default_expand_builtin PARAMS ((tree, rtx, rtx,
                                           enum machine_mode, int));
-#endif
-
 extern void expand_builtin_setjmp_setup PARAMS ((rtx, rtx));
 extern void expand_builtin_setjmp_receiver PARAMS ((rtx));
 extern void expand_builtin_longjmp PARAMS ((rtx, rtx));
 extern rtx expand_builtin_saveregs PARAMS ((void));
 extern void expand_builtin_setjmp_setup PARAMS ((rtx, rtx));
 extern void expand_builtin_setjmp_receiver PARAMS ((rtx));
 extern void expand_builtin_longjmp PARAMS ((rtx, rtx));
 extern rtx expand_builtin_saveregs PARAMS ((void));
+extern void expand_builtin_trap PARAMS ((void));
 extern HOST_WIDE_INT get_varargs_alias_set PARAMS ((void));
 extern HOST_WIDE_INT get_frame_alias_set PARAMS ((void));
 extern void record_base_value          PARAMS ((unsigned int, rtx, int));
 extern HOST_WIDE_INT get_varargs_alias_set PARAMS ((void));
 extern HOST_WIDE_INT get_frame_alias_set PARAMS ((void));
 extern void record_base_value          PARAMS ((unsigned int, rtx, int));
index 59e594e801e2529be4d4218e6cbb3432d1e76372..c3fa09e760c37bb42691ca39da42a80b0aa9bd2d 100644 (file)
@@ -36,6 +36,7 @@ enum libfunc_index
   LTI_truncxfdf2,
   LTI_trunctfdf2,
 
   LTI_truncxfdf2,
   LTI_trunctfdf2,
 
+  LTI_abort,
   LTI_memcpy,
   LTI_memmove,
   LTI_bcopy,
   LTI_memcpy,
   LTI_memmove,
   LTI_bcopy,
@@ -162,6 +163,7 @@ extern rtx libfunc_table[LTI_MAX];
 #define truncxfdf2_libfunc     (libfunc_table[LTI_truncxfdf2])
 #define trunctfdf2_libfunc     (libfunc_table[LTI_trunctfdf2])
 
 #define truncxfdf2_libfunc     (libfunc_table[LTI_truncxfdf2])
 #define trunctfdf2_libfunc     (libfunc_table[LTI_trunctfdf2])
 
+#define abort_libfunc  (libfunc_table[LTI_abort])
 #define memcpy_libfunc (libfunc_table[LTI_memcpy])
 #define memmove_libfunc        (libfunc_table[LTI_memmove])
 #define bcopy_libfunc  (libfunc_table[LTI_bcopy])
 #define memcpy_libfunc (libfunc_table[LTI_memcpy])
 #define memmove_libfunc        (libfunc_table[LTI_memmove])
 #define bcopy_libfunc  (libfunc_table[LTI_bcopy])
index 86c20b08d817473108d650aa5ce1e9185171a845..4d1ebda77f67a6423e5460fc639509042ad76a7e 100644 (file)
@@ -5076,6 +5076,7 @@ init_optabs ()
   truncxfdf2_libfunc = init_one_libfunc ("__truncxfdf2");
   trunctfdf2_libfunc = init_one_libfunc ("__trunctfdf2");
 
   truncxfdf2_libfunc = init_one_libfunc ("__truncxfdf2");
   trunctfdf2_libfunc = init_one_libfunc ("__trunctfdf2");
 
+  abort_libfunc = init_one_libfunc ("abort");
   memcpy_libfunc = init_one_libfunc ("memcpy");
   memmove_libfunc = init_one_libfunc ("memmove");
   bcopy_libfunc = init_one_libfunc ("bcopy");
   memcpy_libfunc = init_one_libfunc ("memcpy");
   memmove_libfunc = init_one_libfunc ("memmove");
   bcopy_libfunc = init_one_libfunc ("bcopy");
index d732047aaf87dfda074c93d61b1cdf1940c0a635..2db32e870606fff51b023a66c99e7dd3ff2e7019 100644 (file)
@@ -3667,9 +3667,7 @@ expand_nl_goto_receivers (thisblock)
   if (any_invalid)
     {
       expand_nl_goto_receiver ();
   if (any_invalid)
     {
       expand_nl_goto_receiver ();
-      emit_library_call (gen_rtx_SYMBOL_REF (Pmode, "abort"), LCT_NORETURN,
-                        VOIDmode, 0);
-      emit_barrier ();
+      expand_builtin_trap ();
     }
 
   nonlocal_goto_handler_labels = label_list;
     }
 
   nonlocal_goto_handler_labels = label_list;
index f4430292e9347dc76c0e25004ef93398be754b54..abf2c2072d08dca6300f740523f33bfc4b0f1e8e 100644 (file)
@@ -1,3 +1,7 @@
+2002-03-31  Richard Henderson  <rth@redhat.com>
+
+       * gcc.dg/va-arg-1.c: Expect warnings, not errors.
+
 2002-03-31  Kazu Hirata  <kazu@hxi.com>
 
        * gcc.dg/weak-1.c: Disable on h8300 port.
 2002-03-31  Kazu Hirata  <kazu@hxi.com>
 
        * gcc.dg/weak-1.c: Disable on h8300 port.
index b29d7eb7f2976a8740503859e95a0cc90de68399..a14823725daa5db792ad93735b0cd4eeb07b30e2 100644 (file)
@@ -7,7 +7,7 @@ volatile int i;
 
 void foo()
 {
 
 void foo()
 {
-  i = va_arg(v, char); /* { dg-error "is promoted to|so you should" "char" } */
-  i = va_arg(v, short); /* { dg-error "is promoted to" "short" } */
-  i = va_arg(v, float); /* { dg-error "is promoted to" "float" } */
+  i = va_arg(v, char); /* { dg-warning "is promoted to|so you should" "char" } */
+  i = va_arg(v, short); /* { dg-warning "is promoted to" "short" } */
+  i = va_arg(v, float); /* { dg-warning "is promoted to" "float" } */
 }
 }