builtins.c: Include langhooks.h.

* 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.

From-SVN: r52512
This commit is contained in:
Neil Booth 2002-04-19 06:22:18 +00:00 committed by Neil Booth
parent 58533fa280
commit ab393bf171
20 changed files with 101 additions and 69 deletions

View File

@ -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.

View File

@ -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) \

View File

@ -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;

View File

@ -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. */

View File

@ -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. */

View File

@ -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;

View File

@ -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);

View File

@ -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!! ### */

View File

@ -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));

View File

@ -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)),

View File

@ -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.

View File

@ -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

View File

@ -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;

View File

@ -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));

View File

@ -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,

View File

@ -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 \
}

View File

@ -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)

View File

@ -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

View File

@ -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;

View File

@ -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));