c-common.c (c_sizeof_or_alignof_type): Take a third argument for complaining.

* c-common.c (c_sizeof_or_alignof_type): Take a third argument for
	complaining.
	* c-common.h (c_sizeof): Adjust definition.
	(c_alignof): Likewise.
	* c-tree.h (c_sizeof_nowarn): Now macro.
	* c-typeck.c (c_sizeof_nowarn): Remove definition.
cp/
	* cp-tree.h (cxx_sizeof_nowarn): Now a macro.
	(cxx_sizeof_or_alignof_type): Take a third argument.
	(cxx_sizeof): Adjust definition.
	(cxx_alignof): Likewise.
	* init.c (build_delete): Use cxx_sizeof_nowarn to reflect reality.
	* typeck.c (cxx_sizeof_or_alignof_type): Take a third argument for
	complaining.
	(c_sizeof_nowarn): Remove definition.
	(build_unary_op): Use cxx_sizeof_nowarn.

From-SVN: r55744
This commit is contained in:
Gabriel Dos Reis 2002-07-25 08:58:07 +00:00 committed by Gabriel Dos Reis
parent ef6838b11c
commit ea79391291
10 changed files with 50 additions and 81 deletions

View File

@ -1,3 +1,12 @@
2002-07-25 Gabriel Dos Reis <gdr@nerim.net>
* c-common.c (c_sizeof_or_alignof_type): Take a third argument for
complaining.
* c-common.h (c_sizeof): Adjust definition.
(c_alignof): Likewise.
* c-tree.h (c_sizeof_nowarn): Now macro.
* c-typeck.c (c_sizeof_nowarn): Remove definition.
2002-07-25 Neil Booth <neil@daikokuya.co.uk>
* c-decl.c (c_decode_option): No need to handle switches

View File

@ -2602,11 +2602,14 @@ c_common_get_alias_set (t)
}
/* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the
second parameter indicates which OPERATOR is being applied. */
second parameter indicates which OPERATOR is being applied. The COMPLAIN
flag controls whether we should diagnose possibly ill-formed
constructs or not. */
tree
c_sizeof_or_alignof_type (type, op)
c_sizeof_or_alignof_type (type, op, complain)
tree type;
enum tree_code op;
int complain;
{
const char *op_name;
tree value = NULL;
@ -2619,7 +2622,7 @@ c_sizeof_or_alignof_type (type, op)
{
if (op == SIZEOF_EXPR)
{
if (pedantic || warn_pointer_arith)
if (complain && (pedantic || warn_pointer_arith))
pedwarn ("invalid application of `sizeof' to a function type");
value = size_one_node;
}
@ -2628,13 +2631,15 @@ c_sizeof_or_alignof_type (type, op)
}
else if (type_code == VOID_TYPE || type_code == ERROR_MARK)
{
if (type_code == VOID_TYPE && (pedantic || warn_pointer_arith))
if (type_code == VOID_TYPE
&& complain && (pedantic || warn_pointer_arith))
pedwarn ("invalid application of `%s' to a void type", op_name);
value = size_one_node;
}
else if (!COMPLETE_TYPE_P (type))
{
error ("invalid application of `%s' to an incomplete type", op_name);
if (complain)
error ("invalid application of `%s' to an incomplete type", op_name);
value = size_zero_node;
}
else

View File

@ -548,7 +548,7 @@ extern tree c_common_signed_type PARAMS ((tree));
extern tree c_common_signed_or_unsigned_type PARAMS ((int, tree));
extern tree c_common_truthvalue_conversion PARAMS ((tree));
extern void c_apply_type_quals_to_decl PARAMS ((int, tree));
extern tree c_sizeof_or_alignof_type PARAMS ((tree, enum tree_code));
extern tree c_sizeof_or_alignof_type PARAMS ((tree, enum tree_code, int));
extern tree c_alignof_expr PARAMS ((tree));
/* Print an error message for invalid operands to arith operation CODE.
NOP_EXPR is used as a special case (see truthvalue_conversion). */
@ -575,8 +575,8 @@ extern void unsigned_conversion_warning PARAMS ((tree, tree));
/* Read the rest of the current #-directive line. */
extern char *get_directive_line PARAMS ((void));
#define GET_DIRECTIVE_LINE() get_directive_line ()
#define c_sizeof(T) c_sizeof_or_alignof_type (T, SIZEOF_EXPR)
#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR)
#define c_sizeof(T) c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 1)
#define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR, 1)
/* Subroutine of build_binary_op, used for comparison operations.
See if the operands have both been converted from subword integer types

View File

@ -255,10 +255,10 @@ extern bool c_warn_unused_global_decl PARAMS ((tree));
((CONST_P) ? TYPE_QUAL_CONST : 0) | \
((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 0))
#define c_sizeof_nowarn(T) c_sizeof_or_alignof_type (T, SIZEOF_EXPR, 0)
/* in c-typeck.c */
extern tree require_complete_type PARAMS ((tree));
extern int comptypes PARAMS ((tree, tree));
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));

View File

@ -736,30 +736,6 @@ type_lists_compatible_p (args1, args2)
}
}
tree
c_sizeof_nowarn (type)
tree type;
{
enum tree_code code = TREE_CODE (type);
tree size;
if (code == FUNCTION_TYPE || code == VOID_TYPE || code == ERROR_MARK)
size = size_one_node;
else if (!COMPLETE_TYPE_P (type))
size = size_zero_node;
else
/* Convert in case a char is more than one unit. */
size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
size_int (TYPE_PRECISION (char_type_node)
/ BITS_PER_UNIT));
/* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
return fold (build1 (NOP_EXPR, c_size_type_node, size));
}
/* Compute the size to increment a pointer by. */
tree

View File

@ -1,3 +1,15 @@
2002-07-25 Gabriel Dos Reis <gdr@nerim.net>
* cp-tree.h (cxx_sizeof_nowarn): Now a macro.
(cxx_sizeof_or_alignof_type): Take a third argument.
(cxx_sizeof): Adjust definition.
(cxx_alignof): Likewise.
* init.c (build_delete): Use cxx_sizeof_nowarn to reflect reality.
* typeck.c (cxx_sizeof_or_alignof_type): Take a third argument for
complaining.
(c_sizeof_nowarn): Remove definition.
(build_unary_op): Use cxx_sizeof_nowarn.
2002-07-24 Geoffrey Keating <geoffk@redhat.com>
* tree.c (cp_build_qualified_type_real): When copying

View File

@ -4436,8 +4436,8 @@ extern int compparms PARAMS ((tree, tree));
extern int comp_cv_qualification PARAMS ((tree, tree));
extern int comp_cv_qual_signature PARAMS ((tree, tree));
extern tree expr_sizeof PARAMS ((tree));
extern tree cxx_sizeof_or_alignof_type PARAMS ((tree, enum tree_code));
extern tree c_sizeof_nowarn PARAMS ((tree));
extern tree cxx_sizeof_or_alignof_type PARAMS ((tree, enum tree_code, int));
#define cxx_sizeof_nowarn(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, false)
extern tree inline_conversion PARAMS ((tree));
extern tree decay_conversion PARAMS ((tree));
extern tree build_object_ref PARAMS ((tree, tree, tree));
@ -4483,8 +4483,8 @@ extern tree merge_types PARAMS ((tree, tree));
extern tree check_return_expr PARAMS ((tree));
#define cp_build_binary_op(code, arg1, arg2) \
build_binary_op(code, arg1, arg2, 1)
#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR)
#define cxx_alignof(T) cxx_sizeof_or_alignof_type (T, ALIGNOF_EXPR)
#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, true)
#define cxx_alignof(T) cxx_sizeof_or_alignof_type (T, ALIGNOF_EXPR, true)
/* in typeck2.c */
extern void cxx_incomplete_type_diagnostic PARAMS ((tree, tree, int));

View File

@ -3771,7 +3771,7 @@ build_expr_from_tree (t)
if (!TYPE_P (r))
return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r);
else
return cxx_sizeof_or_alignof_type (r, TREE_CODE (t));
return cxx_sizeof_or_alignof_type (r, TREE_CODE (t), true);
}
case MODOP_EXPR:

View File

@ -3177,7 +3177,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
return void_zero_node;
return build_op_delete_call
(DELETE_EXPR, addr, c_sizeof_nowarn (type),
(DELETE_EXPR, addr, cxx_sizeof_nowarn (type),
LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL),
NULL_TREE);
}
@ -3212,7 +3212,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
/* Build the call. */
do_delete = build_op_delete_call (DELETE_EXPR,
addr,
c_sizeof_nowarn (type),
cxx_sizeof_nowarn (type),
LOOKUP_NORMAL,
NULL_TREE);
/* Call the complete object destructor. */
@ -3223,7 +3223,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
{
/* Make sure we have access to the member op delete, even though
we'll actually be calling it from the destructor. */
build_op_delete_call (DELETE_EXPR, addr, c_sizeof_nowarn (type),
build_op_delete_call (DELETE_EXPR, addr, cxx_sizeof_nowarn (type),
LOOKUP_NORMAL, NULL_TREE);
}

View File

@ -1487,9 +1487,10 @@ comp_target_parms (parms1, parms2)
}
tree
cxx_sizeof_or_alignof_type (type, op)
cxx_sizeof_or_alignof_type (type, op, complain)
tree type;
enum tree_code op;
int complain;
{
enum tree_code type_code;
tree value;
@ -1507,17 +1508,18 @@ cxx_sizeof_or_alignof_type (type, op)
if (type_code == METHOD_TYPE)
{
if (pedantic || warn_pointer_arith)
if (complain && (pedantic || warn_pointer_arith))
pedwarn ("invalid application of `%s' to a member function", op_name);
value = size_one_node;
}
else if (type_code == OFFSET_TYPE)
{
error ("invalid application of `%s' to non-static member", op_name);
if (complain)
error ("invalid application of `%s' to non-static member", op_name);
value = size_zero_node;
}
else
value = c_sizeof_or_alignof_type (complete_type (type), op);
value = c_sizeof_or_alignof_type (complete_type (type), op, complain);
return value;
}
@ -1554,41 +1556,6 @@ expr_sizeof (e)
return cxx_sizeof (TREE_TYPE (e));
}
tree
c_sizeof_nowarn (type)
tree type;
{
enum tree_code code = TREE_CODE (type);
tree size;
if (code == FUNCTION_TYPE
|| code == METHOD_TYPE
|| code == VOID_TYPE
|| code == ERROR_MARK)
size = size_one_node;
else
{
if (code == REFERENCE_TYPE)
type = TREE_TYPE (type);
if (!COMPLETE_TYPE_P (type))
size = size_zero_node;
else
/* Convert in case a char is more than one unit. */
size = size_binop (CEIL_DIV_EXPR, TYPE_SIZE_UNIT (type),
size_int (TYPE_PRECISION (char_type_node)
/ BITS_PER_UNIT));
}
/* SIZE will have an integer type with TYPE_IS_SIZETYPE set.
TYPE_IS_SIZETYPE means that certain things (like overflow) will
never happen. However, this node should really have type
`size_t', which is just a typedef for an ordinary integer type. */
size = fold (build1 (NOP_EXPR, c_size_type_node, size));
my_friendly_assert (!TYPE_IS_SIZETYPE (TREE_TYPE (size)),
20001021);
return size;
}
/* Perform the array-to-pointer and function-to-pointer conversions
for EXP.
@ -4377,7 +4344,7 @@ build_unary_op (code, xarg, noconvert)
((code == PREINCREMENT_EXPR
|| code == POSTINCREMENT_EXPR)
? "increment" : "decrement"), argtype);
inc = c_sizeof_nowarn (TREE_TYPE (argtype));
inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
}
else
inc = integer_one_node;