Commit ea793912 by Gabriel Dos Reis Committed by Gabriel Dos Reis

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
parent ef6838b1
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> 2002-07-25 Neil Booth <neil@daikokuya.co.uk>
* c-decl.c (c_decode_option): No need to handle switches * c-decl.c (c_decode_option): No need to handle switches
......
...@@ -2602,11 +2602,14 @@ c_common_get_alias_set (t) ...@@ -2602,11 +2602,14 @@ c_common_get_alias_set (t)
} }
/* Compute the value of 'sizeof (TYPE)' or '__alignof__ (TYPE)', where the /* 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 tree
c_sizeof_or_alignof_type (type, op) c_sizeof_or_alignof_type (type, op, complain)
tree type; tree type;
enum tree_code op; enum tree_code op;
int complain;
{ {
const char *op_name; const char *op_name;
tree value = NULL; tree value = NULL;
...@@ -2619,7 +2622,7 @@ c_sizeof_or_alignof_type (type, op) ...@@ -2619,7 +2622,7 @@ c_sizeof_or_alignof_type (type, op)
{ {
if (op == SIZEOF_EXPR) if (op == SIZEOF_EXPR)
{ {
if (pedantic || warn_pointer_arith) if (complain && (pedantic || warn_pointer_arith))
pedwarn ("invalid application of `sizeof' to a function type"); pedwarn ("invalid application of `sizeof' to a function type");
value = size_one_node; value = size_one_node;
} }
...@@ -2628,13 +2631,15 @@ c_sizeof_or_alignof_type (type, op) ...@@ -2628,13 +2631,15 @@ c_sizeof_or_alignof_type (type, op)
} }
else if (type_code == VOID_TYPE || type_code == ERROR_MARK) 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); pedwarn ("invalid application of `%s' to a void type", op_name);
value = size_one_node; value = size_one_node;
} }
else if (!COMPLETE_TYPE_P (type)) 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; value = size_zero_node;
} }
else else
......
...@@ -548,7 +548,7 @@ extern tree c_common_signed_type PARAMS ((tree)); ...@@ -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_signed_or_unsigned_type PARAMS ((int, tree));
extern tree c_common_truthvalue_conversion PARAMS ((tree)); extern tree c_common_truthvalue_conversion PARAMS ((tree));
extern void c_apply_type_quals_to_decl PARAMS ((int, 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)); extern tree c_alignof_expr PARAMS ((tree));
/* Print an error message for invalid operands to arith operation CODE. /* Print an error message for invalid operands to arith operation CODE.
NOP_EXPR is used as a special case (see truthvalue_conversion). */ NOP_EXPR is used as a special case (see truthvalue_conversion). */
...@@ -575,8 +575,8 @@ extern void unsigned_conversion_warning PARAMS ((tree, tree)); ...@@ -575,8 +575,8 @@ extern void unsigned_conversion_warning PARAMS ((tree, tree));
/* Read the rest of the current #-directive line. */ /* Read the rest of the current #-directive line. */
extern char *get_directive_line PARAMS ((void)); extern char *get_directive_line PARAMS ((void));
#define GET_DIRECTIVE_LINE() get_directive_line () #define GET_DIRECTIVE_LINE() get_directive_line ()
#define c_sizeof(T) c_sizeof_or_alignof_type (T, SIZEOF_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) #define c_alignof(T) c_sizeof_or_alignof_type (T, ALIGNOF_EXPR, 1)
/* Subroutine of build_binary_op, used for comparison operations. /* Subroutine of build_binary_op, used for comparison operations.
See if the operands have both been converted from subword integer types See if the operands have both been converted from subword integer types
......
...@@ -255,10 +255,10 @@ extern bool c_warn_unused_global_decl PARAMS ((tree)); ...@@ -255,10 +255,10 @@ extern bool c_warn_unused_global_decl PARAMS ((tree));
((CONST_P) ? TYPE_QUAL_CONST : 0) | \ ((CONST_P) ? TYPE_QUAL_CONST : 0) | \
((VOLATILE_P) ? TYPE_QUAL_VOLATILE : 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 */ /* in c-typeck.c */
extern tree require_complete_type PARAMS ((tree)); extern tree require_complete_type PARAMS ((tree));
extern int comptypes PARAMS ((tree, tree)); extern int comptypes PARAMS ((tree, tree));
extern tree c_sizeof_nowarn PARAMS ((tree));
extern tree c_size_in_bytes PARAMS ((tree)); extern tree c_size_in_bytes PARAMS ((tree));
extern bool c_mark_addressable PARAMS ((tree)); extern bool c_mark_addressable PARAMS ((tree));
extern void c_incomplete_type_error PARAMS ((tree, tree)); extern void c_incomplete_type_error PARAMS ((tree, tree));
......
...@@ -736,30 +736,6 @@ type_lists_compatible_p (args1, args2) ...@@ -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. */ /* Compute the size to increment a pointer by. */
tree tree
......
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> 2002-07-24 Geoffrey Keating <geoffk@redhat.com>
* tree.c (cp_build_qualified_type_real): When copying * tree.c (cp_build_qualified_type_real): When copying
......
...@@ -4436,8 +4436,8 @@ extern int compparms PARAMS ((tree, tree)); ...@@ -4436,8 +4436,8 @@ extern int compparms PARAMS ((tree, tree));
extern int comp_cv_qualification PARAMS ((tree, tree)); extern int comp_cv_qualification PARAMS ((tree, tree));
extern int comp_cv_qual_signature PARAMS ((tree, tree)); extern int comp_cv_qual_signature PARAMS ((tree, tree));
extern tree expr_sizeof PARAMS ((tree)); extern tree expr_sizeof PARAMS ((tree));
extern tree cxx_sizeof_or_alignof_type PARAMS ((tree, enum tree_code)); extern tree cxx_sizeof_or_alignof_type PARAMS ((tree, enum tree_code, int));
extern tree c_sizeof_nowarn PARAMS ((tree)); #define cxx_sizeof_nowarn(T) cxx_sizeof_or_alignof_type (T, SIZEOF_EXPR, false)
extern tree inline_conversion PARAMS ((tree)); extern tree inline_conversion PARAMS ((tree));
extern tree decay_conversion PARAMS ((tree)); extern tree decay_conversion PARAMS ((tree));
extern tree build_object_ref PARAMS ((tree, tree, tree)); extern tree build_object_ref PARAMS ((tree, tree, tree));
...@@ -4483,8 +4483,8 @@ extern tree merge_types PARAMS ((tree, tree)); ...@@ -4483,8 +4483,8 @@ extern tree merge_types PARAMS ((tree, tree));
extern tree check_return_expr PARAMS ((tree)); extern tree check_return_expr PARAMS ((tree));
#define cp_build_binary_op(code, arg1, arg2) \ #define cp_build_binary_op(code, arg1, arg2) \
build_binary_op(code, arg1, arg2, 1) build_binary_op(code, arg1, arg2, 1)
#define cxx_sizeof(T) cxx_sizeof_or_alignof_type (T, SIZEOF_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) #define cxx_alignof(T) cxx_sizeof_or_alignof_type (T, ALIGNOF_EXPR, true)
/* in typeck2.c */ /* in typeck2.c */
extern void cxx_incomplete_type_diagnostic PARAMS ((tree, tree, int)); extern void cxx_incomplete_type_diagnostic PARAMS ((tree, tree, int));
......
...@@ -3771,7 +3771,7 @@ build_expr_from_tree (t) ...@@ -3771,7 +3771,7 @@ build_expr_from_tree (t)
if (!TYPE_P (r)) if (!TYPE_P (r))
return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r); return TREE_CODE (t) == SIZEOF_EXPR ? expr_sizeof (r) : c_alignof_expr (r);
else 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: case MODOP_EXPR:
......
...@@ -3177,7 +3177,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete) ...@@ -3177,7 +3177,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
return void_zero_node; return void_zero_node;
return build_op_delete_call 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), LOOKUP_NORMAL | (use_global_delete * LOOKUP_GLOBAL),
NULL_TREE); NULL_TREE);
} }
...@@ -3212,7 +3212,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete) ...@@ -3212,7 +3212,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete)
/* Build the call. */ /* Build the call. */
do_delete = build_op_delete_call (DELETE_EXPR, do_delete = build_op_delete_call (DELETE_EXPR,
addr, addr,
c_sizeof_nowarn (type), cxx_sizeof_nowarn (type),
LOOKUP_NORMAL, LOOKUP_NORMAL,
NULL_TREE); NULL_TREE);
/* Call the complete object destructor. */ /* Call the complete object destructor. */
...@@ -3223,7 +3223,7 @@ build_delete (type, addr, auto_delete, flags, use_global_delete) ...@@ -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 /* Make sure we have access to the member op delete, even though
we'll actually be calling it from the destructor. */ 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); LOOKUP_NORMAL, NULL_TREE);
} }
......
...@@ -1487,9 +1487,10 @@ comp_target_parms (parms1, parms2) ...@@ -1487,9 +1487,10 @@ comp_target_parms (parms1, parms2)
} }
tree tree
cxx_sizeof_or_alignof_type (type, op) cxx_sizeof_or_alignof_type (type, op, complain)
tree type; tree type;
enum tree_code op; enum tree_code op;
int complain;
{ {
enum tree_code type_code; enum tree_code type_code;
tree value; tree value;
...@@ -1507,17 +1508,18 @@ cxx_sizeof_or_alignof_type (type, op) ...@@ -1507,17 +1508,18 @@ cxx_sizeof_or_alignof_type (type, op)
if (type_code == METHOD_TYPE) 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); pedwarn ("invalid application of `%s' to a member function", op_name);
value = size_one_node; value = size_one_node;
} }
else if (type_code == OFFSET_TYPE) 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; value = size_zero_node;
} }
else else
value = c_sizeof_or_alignof_type (complete_type (type), op); value = c_sizeof_or_alignof_type (complete_type (type), op, complain);
return value; return value;
} }
...@@ -1554,41 +1556,6 @@ expr_sizeof (e) ...@@ -1554,41 +1556,6 @@ expr_sizeof (e)
return cxx_sizeof (TREE_TYPE (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 /* Perform the array-to-pointer and function-to-pointer conversions
for EXP. for EXP.
...@@ -4377,7 +4344,7 @@ build_unary_op (code, xarg, noconvert) ...@@ -4377,7 +4344,7 @@ build_unary_op (code, xarg, noconvert)
((code == PREINCREMENT_EXPR ((code == PREINCREMENT_EXPR
|| code == POSTINCREMENT_EXPR) || code == POSTINCREMENT_EXPR)
? "increment" : "decrement"), argtype); ? "increment" : "decrement"), argtype);
inc = c_sizeof_nowarn (TREE_TYPE (argtype)); inc = cxx_sizeof_nowarn (TREE_TYPE (argtype));
} }
else else
inc = integer_one_node; inc = integer_one_node;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment