summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog23
-rw-r--r--gcc/Makefile.in2
-rw-r--r--gcc/builtins.c6
-rw-r--r--gcc/c-common.c30
-rw-r--r--gcc/c-common.h1
-rw-r--r--gcc/c-decl.c8
-rw-r--r--gcc/c-format.c9
-rw-r--r--gcc/c-lang.c2
-rw-r--r--gcc/c-tree.h1
-rw-r--r--gcc/c-typeck.c26
-rw-r--r--gcc/cp/ChangeLog7
-rw-r--r--gcc/cp/call.c25
-rw-r--r--gcc/cp/cp-lang.c2
-rw-r--r--gcc/cp/cp-tree.h2
-rw-r--r--gcc/cp/decl.c2
-rw-r--r--gcc/langhooks-def.h3
-rw-r--r--gcc/langhooks.c8
-rw-r--r--gcc/langhooks.h6
-rw-r--r--gcc/objc/objc-lang.c2
-rw-r--r--gcc/tree.h5
20 files changed, 101 insertions, 69 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index dabbf94c453..097cf31ba5b 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,26 @@
+2002-04-19 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * 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.
+objc:
+ * objc-lang.c (LANG_HOOKS_TYPE_PROMOTES_TO): Redefine.
+
2002-04-18 Richard Henderson <rth@redhat.com>
* function.c: Revert patch for c/6358.
diff --git a/gcc/Makefile.in b/gcc/Makefile.in
index 5a386eaad69..bb8e29ed032 100644
--- a/gcc/Makefile.in
+++ b/gcc/Makefile.in
@@ -1221,7 +1221,7 @@ attribs.o : attribs.c $(CONFIG_H) $(SYSTEM_H) $(TREE_H) $(OBSTACK_H) flags.h \
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) \
diff --git a/gcc/builtins.c b/gcc/builtins.c
index dcbc6dab23e..a1ffe0a1d69 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -41,6 +41,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#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) END_BUILTINS] =
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;
diff --git a/gcc/c-common.c b/gcc/c-common.c
index 1e7a0656c55..c1201cdbc54 100644
--- a/gcc/c-common.c
+++ b/gcc/c-common.c
@@ -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
@@ -3075,32 +3071,6 @@ c_promoting_integer_type_p (t)
}
}
-/* 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
and none of their types is affected by default promotions. */
diff --git a/gcc/c-common.h b/gcc/c-common.h
index f0b92ed48dd..e3d00e92f0c 100644
--- a/gcc/c-common.h
+++ b/gcc/c-common.h
@@ -568,7 +568,6 @@ extern void c_common_parse_file PARAMS ((void));
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. */
diff --git a/gcc/c-decl.c b/gcc/c-decl.c
index 3487aef05d9..7db66d78db7 100644
--- a/gcc/c-decl.c
+++ b/gcc/c-decl.c
@@ -1550,7 +1550,7 @@ duplicate_decls (newdecl, olddecl, different_binding_level)
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, decl_context, initialized)
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;
diff --git a/gcc/c-format.c b/gcc/c-format.c
index c1211674cdc..e5be439c53f 100644
--- a/gcc/c-format.c
+++ b/gcc/c-format.c
@@ -27,7 +27,7 @@ Software Foundation, 59 Temple Place - Suite 330, Boston, MA
#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);
diff --git a/gcc/c-lang.c b/gcc/c-lang.c
index 741aa1d3670..ec1f1521867 100644
--- a/gcc/c-lang.c
+++ b/gcc/c-lang.c
@@ -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!! ### */
diff --git a/gcc/c-tree.h b/gcc/c-tree.h
index 3d152fb8320..21f1146ff56 100644
--- a/gcc/c-tree.h
+++ b/gcc/c-tree.h
@@ -251,6 +251,7 @@ extern tree c_sizeof_nowarn PARAMS ((tree));
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));
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 6b198f9310d..47fa1855ad3 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -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)),
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index a9b6023b1c5..7a139f4d52d 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -1,3 +1,10 @@
+2002-04-19 Neil Booth <neil@daikokuya.demon.co.uk>
+
+ * 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.
+
2002-04-18 Neil Booth <neil@daikokuya.demon.co.uk>
* call.c (build_new_method_call): Update.
diff --git a/gcc/cp/call.c b/gcc/cp/call.c
index f9ca9a08f5f..233f98c21f8 100644
--- a/gcc/cp/call.c
+++ b/gcc/cp/call.c
@@ -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
diff --git a/gcc/cp/cp-lang.c b/gcc/cp/cp-lang.c
index 1ac312222bb..d37cd111658 100644
--- a/gcc/cp/cp-lang.c
+++ b/gcc/cp/cp-lang.c
@@ -136,6 +136,8 @@ static bool cxx_warn_unused_global_decl PARAMS ((tree));
#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;
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 41bde3813f1..5b56331f83b 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -3578,7 +3578,7 @@ extern int enforce_access PARAMS ((tree, tree));
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));
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 51efa3574ec..ec087983f70 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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,
diff --git a/gcc/langhooks-def.h b/gcc/langhooks-def.h
index 0f08524a048..abbe734e057 100644
--- a/gcc/langhooks-def.h
+++ b/gcc/langhooks-def.h
@@ -58,6 +58,7 @@ extern void lhd_print_error_function PARAMS ((struct diagnostic_context *,
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 ((tree));
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 ((tree));
LANG_HOOKS_UNSIGNED_TYPE, \
LANG_HOOKS_SIGNED_TYPE, \
LANG_HOOKS_SIGNED_OR_UNSIGNED_TYPE, \
+ LANG_HOOKS_TYPE_PROMOTES_TO, \
LANG_HOOKS_INCOMPLETE_TYPE_ERROR \
}
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index c48ea2cba2b..cc08e465034 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -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)
diff --git a/gcc/langhooks.h b/gcc/langhooks.h
index a2069d62ed5..5b128a7adaa 100644
--- a/gcc/langhooks.h
+++ b/gcc/langhooks.h
@@ -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
diff --git a/gcc/objc/objc-lang.c b/gcc/objc/objc-lang.c
index 247280318a7..fef5196645f 100644
--- a/gcc/objc/objc-lang.c
+++ b/gcc/objc/objc-lang.c
@@ -99,6 +99,8 @@ static void objc_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
/* Each front end provides its own hooks, for toplev.c. */
const struct lang_hooks lang_hooks = LANG_HOOKS_INITIALIZER;
diff --git a/gcc/tree.h b/gcc/tree.h
index 58113ca9571..0eae44844a7 100644
--- a/gcc/tree.h
+++ b/gcc/tree.h
@@ -2799,11 +2799,6 @@ extern void rrotate_double PARAMS ((unsigned HOST_WIDE_INT, HOST_WIDE_INT,
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));