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]

lang_type_promotes_to langhook


I changed the semantics of this function slightly; it would previously
return NULL if the original type was the promoted type; now it just
returns the original type.  This was more useful for most of the users,
and no more awkward to the remaining callers.

Bootstrapped x86 Linux.  OK?

Neil.

	* builtins.c: Include langhooks.h.
	(lang_type_promotes_to): Remove.
	(expand_builtin_va_arg): Use new hook.
	* c-common.c (c_common_nodes_and_builtins): Don't set hook.
	(simple_type_promotes_to): Move to c-typeck.c.
	* c-common.h (simple_type_promotes_to): Remove.
	* c-decl.c (duplicate_decls, grokdeclarator): Update.
	* c-format.c: Include langhooks.h.
	(check_format_types): Update.
	* c-tree.h (c_type_promotes_to): New.
	* c-typeck.c (c_type_promotes_to): Move from c-common.c.
	(type_lists_compatible_p): Update.
	* langhooks-def.h (lhd_type_promotes_to): New.
	(LANG_HOOKS_TYPE_PROMOTES_TO): New.
	(LANG_HOOKS_FOR_TYPES_INITIALIZER): Update.
	* langhooks.c (lhd_type_promotes_to): New.
	* langhooks.h (struct lang_hooks_for_types): New hook.
	* tree.h (lang_type_promotes_to): Remove.
cp:
	* call.c (convert_type_from_ellipsis): Rename, update.
	* cp-lang.c (LANG_HOOKS_TYPE_PROMOTES_TO): Redefine.
	* cp-tree.h (convert_type_from_ellipsis): Rename.
	* decl.c (cxx_init_decl_processing): Don't set hook.
objc:
	* objc-lang.c (LANG_HOOKS_TYPE_PROMOTES_TO): Redefine.

============================================================
Index: gcc/Makefile.in
--- gcc/Makefile.in	17 Apr 2002 03:15:13 -0000	1.857
+++ gcc/Makefile.in	18 Apr 2002 21:35:06 -0000
@@ -1221,7 +1221,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYST
 	toplev.h output.h c-pragma.h $(RTL_H) $(GGC_H) $(EXPR_H) $(TM_P_H) \
 	builtin-types.def $(TARGET_H) langhooks.h
 
-c-format.o : c-format.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) \
+c-format.o : c-format.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) langhooks.h \
 	$(C_COMMON_H) flags.h toplev.h intl.h diagnostic.h
 
 c-semantics.o : c-semantics.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(C_TREE_H) \
============================================================
Index: gcc/builtins.c
--- gcc/builtins.c	3 Apr 2002 02:33:07 -0000	1.147
+++ gcc/builtins.c	18 Apr 2002 21:35:16 -0000
@@ -41,6 +41,7 @@ Software Foundation, 59 Temple Place - S
 #include "predict.h"
 #include "tm_p.h"
 #include "target.h"
+#include "langhooks.h"
 
 #define CALLED_AS_BUILT_IN(NODE) \
    (!strncmp (IDENTIFIER_POINTER (DECL_NAME (NODE)), "__builtin_", 10))
@@ -72,8 +73,6 @@ const char *const built_in_names[(int) E
    initialized to NULL_TREE.  */
 tree built_in_decls[(int) END_BUILTINS];
 
-tree (*lang_type_promotes_to) PARAMS ((tree));
-
 static int get_pointer_alignment	PARAMS ((tree, unsigned int));
 static tree c_strlen			PARAMS ((tree));
 static const char *c_getstr		PARAMS ((tree));
@@ -3083,7 +3082,8 @@ expand_builtin_va_arg (valist, type)
 
   /* Generate a diagnostic for requesting data of a type that cannot
      be passed through `...' due to type promotion at the call site.  */
-  else if ((promoted_type = (*lang_type_promotes_to) (type)) != NULL_TREE)
+  else if ((promoted_type = (*lang_hooks.types.type_promotes_to) (type))
+	   != type)
     {
       const char *name = "<anonymous type>", *pname = 0;
       static bool gave_help;
============================================================
Index: gcc/c-common.c
--- gcc/c-common.c	17 Apr 2002 01:47:19 -0000	1.311
+++ gcc/c-common.c	18 Apr 2002 21:35:27 -0000
@@ -2928,10 +2928,6 @@ c_common_nodes_and_builtins ()
 		      0, NOT_BUILT_IN, 0, 0, 1);
 
   main_identifier_node = get_identifier ("main");
-
-  /* ??? Perhaps there's a better place to do this.  But it is related
-     to __builtin_va_arg, so it isn't that off-the-wall.  */
-  lang_type_promotes_to = simple_type_promotes_to;
 }
 
 tree
@@ -3073,32 +3069,6 @@ c_promoting_integer_type_p (t)
     default:
       return 0;
     }
-}
-
-/* Given a type, apply default promotions wrt unnamed function arguments
-   and return the new type.  Return NULL_TREE if no change.  */
-/* ??? There is a function of the same name in the C++ front end that
-   does something similar, but is more thorough and does not return NULL
-   if no change.  We could perhaps share code, but it would make the
-   self_promoting_type property harder to identify.  */
-
-tree
-simple_type_promotes_to (type)
-     tree type;
-{
-  if (TYPE_MAIN_VARIANT (type) == float_type_node)
-    return double_type_node;
-
-  if (c_promoting_integer_type_p (type))
-    {
-      /* Preserve unsignedness if not really getting any wider.  */
-      if (TREE_UNSIGNED (type)
-          && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
-        return unsigned_type_node;
-      return integer_type_node;
-    }
-
-  return NULL_TREE;
 }
 
 /* Return 1 if PARMS specifies a fixed number of parameters
============================================================
Index: gcc/c-common.h
--- gcc/c-common.h	17 Apr 2002 01:47:20 -0000	1.128
+++ gcc/c-common.h	18 Apr 2002 21:35:30 -0000
@@ -568,7 +568,6 @@ extern void c_common_parse_file			PARAMS
 extern HOST_WIDE_INT c_common_get_alias_set	PARAMS ((tree));
 extern bool c_promoting_integer_type_p		PARAMS ((tree));
 extern int self_promoting_args_p		PARAMS ((tree));
-extern tree simple_type_promotes_to		PARAMS ((tree));
 extern tree strip_array_types                   PARAMS ((tree));
 
 /* These macros provide convenient access to the various _STMT nodes.  */
============================================================
Index: gcc/c-decl.c
--- gcc/c-decl.c	10 Apr 2002 19:49:52 -0000	1.317
+++ gcc/c-decl.c	18 Apr 2002 21:35:49 -0000
@@ -1550,7 +1550,7 @@ duplicate_decls (newdecl, olddecl, diffe
 		  break;
 		}
 
-	      if (simple_type_promotes_to (type) != NULL_TREE)
+	      if (c_type_promotes_to (type) != type)
 		{
 		  error ("an argument type that has a default promotion can't match an empty parameter name list declaration");
 		  break;
@@ -4793,11 +4793,7 @@ grokdeclarator (declarator, declspecs, d
 	if (type == error_mark_node)
 	  promoted_type = type;
 	else
-	  {
-	    promoted_type = simple_type_promotes_to (type);
-	    if (! promoted_type)
-	      promoted_type = type;
-	  }
+	  promoted_type = c_type_promotes_to (type);
 
 	DECL_ARG_TYPE (decl) = promoted_type;
 	DECL_ARG_TYPE_AS_WRITTEN (decl) = type_as_written;
============================================================
Index: gcc/c-format.c
--- gcc/c-format.c	1 Apr 2002 08:45:41 -0000	1.18
+++ gcc/c-format.c	18 Apr 2002 21:35:54 -0000
@@ -27,7 +27,7 @@ Software Foundation, 59 Temple Place - S
 #include "c-common.h"
 #include "intl.h"
 #include "diagnostic.h"
-
+#include "langhooks.h"
 
 /* Command line options and their associated flags.  */
 
@@ -2258,7 +2258,6 @@ check_format_types (status, types)
       tree cur_type;
       tree orig_cur_type;
       tree wanted_type;
-      tree promoted_type;
       int arg_num;
       int i;
       int char_type_flag;
@@ -2277,11 +2276,7 @@ check_format_types (status, types)
 	abort ();
 
       if (types->pointer_count == 0)
-	{
-	  promoted_type = simple_type_promotes_to (wanted_type);
-	  if (promoted_type != NULL_TREE)
-	    wanted_type = promoted_type;
-	}
+	wanted_type = (*lang_hooks.types.type_promotes_to) (wanted_type);
 
       STRIP_NOPS (cur_param);
 
============================================================
Index: gcc/c-lang.c
--- gcc/c-lang.c	18 Apr 2002 17:53:19 -0000	1.88
+++ gcc/c-lang.c	18 Apr 2002 21:35:55 -0000
@@ -102,6 +102,8 @@ static void c_post_options PARAMS ((void
 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR c_incomplete_type_error
+#undef LANG_HOOKS_TYPE_PROMOTES_TO
+#define LANG_HOOKS_TYPE_PROMOTES_TO c_type_promotes_to
 
 /* ### When changing hooks, consider if ObjC needs changing too!! ### */
 
============================================================
Index: gcc/c-tree.h
--- gcc/c-tree.h	18 Apr 2002 17:53:20 -0000	1.93
+++ gcc/c-tree.h	18 Apr 2002 21:35:56 -0000
@@ -251,6 +251,7 @@ extern tree c_sizeof_nowarn			PARAMS ((t
 extern tree c_size_in_bytes                     PARAMS ((tree));
 extern bool c_mark_addressable			PARAMS ((tree));
 extern void c_incomplete_type_error		PARAMS ((tree, tree));
+extern tree c_type_promotes_to			PARAMS ((tree));
 extern tree build_component_ref                 PARAMS ((tree, tree));
 extern tree build_indirect_ref                  PARAMS ((tree, const char *));
 extern tree build_array_ref                     PARAMS ((tree, tree));
============================================================
Index: gcc/c-typeck.c
--- gcc/c-typeck.c	18 Apr 2002 17:53:21 -0000	1.191
+++ gcc/c-typeck.c	18 Apr 2002 21:36:12 -0000
@@ -173,6 +173,28 @@ c_incomplete_type_error (value, type)
     }
 }
 
+/* Given a type, apply default promotions wrt unnamed function
+   arguments and return the new type.  */
+
+tree
+c_type_promotes_to (type)
+     tree type;
+{
+  if (TYPE_MAIN_VARIANT (type) == float_type_node)
+    return double_type_node;
+
+  if (c_promoting_integer_type_p (type))
+    {
+      /* Preserve unsignedness if not really getting any wider.  */
+      if (TREE_UNSIGNED (type)
+          && (TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)))
+        return unsigned_type_node;
+      return integer_type_node;
+    }
+
+  return type;
+}
+
 /* Return a variant of TYPE which has all the type qualifiers of LIKE
    as well as those of TYPE.  */
 
@@ -658,12 +680,12 @@ type_lists_compatible_p (args1, args2)
 	 So match anything that self-promotes.  */
       if (TREE_VALUE (args1) == 0)
 	{
-	  if (simple_type_promotes_to (TREE_VALUE (args2)) != NULL_TREE)
+	  if (c_type_promotes_to (TREE_VALUE (args2)) != TREE_VALUE (args2))
 	    return 0;
 	}
       else if (TREE_VALUE (args2) == 0)
 	{
-	  if (simple_type_promotes_to (TREE_VALUE (args1)) != NULL_TREE)
+	  if (c_type_promotes_to (TREE_VALUE (args1)) != TREE_VALUE (args1))
 	    return 0;
 	}
       else if (! (newval = comptypes (TYPE_MAIN_VARIANT (TREE_VALUE (args1)), 
============================================================
Index: gcc/langhooks-def.h
--- gcc/langhooks-def.h	18 Apr 2002 17:53:21 -0000	1.28
+++ gcc/langhooks-def.h	18 Apr 2002 21:36:12 -0000
@@ -58,6 +58,7 @@ extern void lhd_print_error_function PAR
 extern void lhd_set_decl_assembler_name PARAMS ((tree));
 extern bool lhd_warn_unused_global_decl PARAMS ((tree));
 extern void lhd_incomplete_type_error PARAMS ((tree, tree));
+extern tree lhd_type_promotes_to PARAMS ((tree));
 
 /* Declarations of default tree inlining hooks.  */
 tree lhd_tree_inlining_walk_subtrees		PARAMS ((tree *, int *,
@@ -161,6 +162,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
    so we create a compile-time error instead.  */
 #define LANG_HOOKS_MAKE_TYPE make_node
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR lhd_incomplete_type_error
+#define LANG_HOOKS_TYPE_PROMOTES_TO lhd_type_promotes_to
 
 #define LANG_HOOKS_FOR_TYPES_INITIALIZER { \
   LANG_HOOKS_MAKE_TYPE, \
@@ -169,6 +171,7 @@ int lhd_tree_dump_type_quals			PARAMS ((
   LANG_HOOKS_UNSIGNED_TYPE, \
   LANG_HOOKS_SIGNED_TYPE, \
   LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE, \
+  LANG_HOOKS_TYPE_PROMOTES_TO, \
   LANG_HOOKS_INCOMPLETE_TYPE_ERROR \
 }
 
============================================================
Index: gcc/langhooks.c
--- gcc/langhooks.c	18 Apr 2002 17:53:21 -0000	1.27
+++ gcc/langhooks.c	18 Apr 2002 21:36:13 -0000
@@ -178,6 +178,14 @@ lhd_clear_binding_stack ()
     poplevel (0, 0, 0);
 }
 
+/* Type promotion for variable arguments.  */
+tree
+lhd_type_promotes_to (type)
+     tree type ATTRIBUTE_UNUSED;
+{
+  abort ();
+}
+
 /* Invalid use of an incomplete type.  */
 void
 lhd_incomplete_type_error (value, type)
============================================================
Index: gcc/langhooks.h
--- gcc/langhooks.h	18 Apr 2002 17:53:22 -0000	1.35
+++ gcc/langhooks.h	18 Apr 2002 21:36:14 -0000
@@ -97,6 +97,12 @@ struct lang_hooks_for_types
      according to UNSIGNEDP.  */
   tree (*signed_or_unsigned_type) PARAMS ((int, tree));
 
+  /* Given a type, apply default promotions to unnamed function
+     arguments and return the new type.  Return the same type if no
+     change.  Required by any language that supports variadic
+     arguments.  The default hook aborts.  */
+  tree (*type_promotes_to) PARAMS ((tree));
+
   /* This routine is called in tree.c to print an error message for
      invalid use of an incomplete type.  VALUE is the expression that
      was used (or 0 if that isn't known) and TYPE is the type that was
============================================================
Index: gcc/tree.h
--- gcc/tree.h	18 Apr 2002 17:53:22 -0000	1.329
+++ gcc/tree.h	18 Apr 2002 21:36:26 -0000
@@ -2799,11 +2799,6 @@ extern void rrotate_double	PARAMS ((unsi
 extern int operand_equal_p	PARAMS ((tree, tree, int));
 extern tree invert_truthvalue	PARAMS ((tree));
 
-/* In builtins.c.  Given a type, apply default promotions wrt unnamed
-   function arguments and return the new type.  Return NULL_TREE if no
-   change.  Required by any language that supports variadic arguments.  */
-
-extern tree (*lang_type_promotes_to)	PARAMS ((tree));
 extern tree fold_builtin		PARAMS ((tree));
 
 extern tree build_range_type PARAMS ((tree, tree, tree));
============================================================
Index: gcc/cp/call.c
--- gcc/cp/call.c	18 Apr 2002 17:53:48 -0000	1.317
+++ gcc/cp/call.c	18 Apr 2002 21:36:39 -0000
@@ -4026,24 +4026,27 @@ build_x_va_arg (expr, type)
   return build_va_arg (expr, type);
 }
 
-/* TYPE has been given to va_arg. Apply the default conversions which would
-   have happened when passed via ellipsis. Return the promoted type, or
-   NULL_TREE, if there is no change.  */
+/* TYPE has been given to va_arg.  Apply the default conversions which
+   would have happened when passed via ellipsis.  Return the promoted
+   type, or the passed type if there is no change.  */
 
 tree
-convert_type_from_ellipsis (type)
+cxx_type_promotes_to (type)
      tree type;
 {
   tree promote;
-  
+
   if (TREE_CODE (type) == ARRAY_TYPE)
-    promote = build_pointer_type (TREE_TYPE (type));
-  else if (TREE_CODE (type) == FUNCTION_TYPE)
-    promote = build_pointer_type (type);
-  else
-    promote = type_promotes_to (type);
+    return build_pointer_type (TREE_TYPE (type));
+
+  if (TREE_CODE (type) == FUNCTION_TYPE)
+    return build_pointer_type (type);
+
+  promote = type_promotes_to (type);
+  if (same_type_p (type, promote))
+    promote = type;
   
-  return same_type_p (type, promote) ? NULL_TREE : promote;
+  return promote;
 }
 
 /* ARG is a default argument expression being passed to a parameter of
============================================================
Index: gcc/cp/cp-lang.c
--- gcc/cp/cp-lang.c	18 Apr 2002 17:53:49 -0000	1.29
+++ gcc/cp/cp-lang.c	18 Apr 2002 21:36:40 -0000
@@ -136,6 +136,8 @@ static bool cxx_warn_unused_global_decl 
 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR cxx_incomplete_type_error
+#undef LANG_HOOKS_TYPE_PROMOTES_TO
+#define LANG_HOOKS_TYPE_PROMOTES_TO cxx_type_promotes_to
 
 /* Each front end provides its own hooks, for toplev.c.  */
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
============================================================
Index: gcc/cp/cp-tree.h
--- gcc/cp/cp-tree.h	18 Apr 2002 17:53:50 -0000	1.706
+++ gcc/cp/cp-tree.h	18 Apr 2002 21:36:53 -0000
@@ -3578,7 +3578,7 @@ extern int enforce_access               
 extern tree convert_default_arg                 PARAMS ((tree, tree, tree, int));
 extern tree convert_arg_to_ellipsis             PARAMS ((tree));
 extern tree build_x_va_arg                      PARAMS ((tree, tree));
-extern tree convert_type_from_ellipsis          PARAMS ((tree));
+extern tree cxx_type_promotes_to		PARAMS ((tree));
 extern int is_properly_derived_from             PARAMS ((tree, tree));
 extern tree initialize_reference                PARAMS ((tree, tree));
 extern tree strip_top_quals                     PARAMS ((tree));
============================================================
Index: gcc/cp/decl.c
--- gcc/cp/decl.c	18 Apr 2002 17:53:51 -0000	1.898
+++ gcc/cp/decl.c	18 Apr 2002 21:37:30 -0000
@@ -6579,8 +6579,6 @@ cxx_init_decl_processing ()
   vtable_index_type = ptrdiff_type_node;
 
   vtt_parm_type = build_pointer_type (const_ptr_type_node);
-  lang_type_promotes_to = convert_type_from_ellipsis;
-
   void_ftype = build_function_type (void_type_node, void_list_node);
   void_ftype_ptr = build_function_type (void_type_node,
 					tree_cons (NULL_TREE,
============================================================
Index: gcc/objc/objc-lang.c
--- gcc/objc/objc-lang.c	18 Apr 2002 17:54:11 -0000	1.17
+++ gcc/objc/objc-lang.c	18 Apr 2002 21:37:32 -0000
@@ -99,6 +99,8 @@ static void objc_post_options           
 #define LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE c_common_signed_or_unsigned_type
 #undef LANG_HOOKS_INCOMPLETE_TYPE_ERROR
 #define LANG_HOOKS_INCOMPLETE_TYPE_ERROR c_incomplete_type_error
+#undef LANG_HOOKS_TYPE_PROMOTES_TO
+#define LANG_HOOKS_TYPE_PROMOTES_TO c_type_promotes_to
 
 /* Each front end provides its own hooks, for toplev.c.  */
 const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;


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