From d3a4d008cbebd187459727f6433b274be03ea160 Mon Sep 17 00:00:00 2001 From: gdr Date: Thu, 25 Jul 2002 08:58:07 +0000 Subject: [PATCH] * 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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@55744 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 9 +++++++++ gcc/c-common.c | 15 ++++++++++----- gcc/c-common.h | 6 +++--- gcc/c-tree.h | 2 +- gcc/c-typeck.c | 24 ------------------------ gcc/cp/ChangeLog | 12 ++++++++++++ gcc/cp/cp-tree.h | 8 ++++---- gcc/cp/decl2.c | 2 +- gcc/cp/init.c | 6 +++--- gcc/cp/typeck.c | 47 +++++++---------------------------------------- 10 files changed, 50 insertions(+), 81 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index efb68c0..926ca17 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,12 @@ +2002-07-25 Gabriel Dos Reis + + * 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 * c-decl.c (c_decode_option): No need to handle switches diff --git a/gcc/c-common.c b/gcc/c-common.c index d7be6c8..88c3ef5 100644 --- a/gcc/c-common.c +++ b/gcc/c-common.c @@ -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 diff --git a/gcc/c-common.h b/gcc/c-common.h index fabfb16..5dfa2d6 100644 --- a/gcc/c-common.h +++ b/gcc/c-common.h @@ -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 diff --git a/gcc/c-tree.h b/gcc/c-tree.h index 64eb2e1..a2bf542 100644 --- a/gcc/c-tree.h +++ b/gcc/c-tree.h @@ -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)); diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c index f6e8d53..e9c846e 100644 --- a/gcc/c-typeck.c +++ b/gcc/c-typeck.c @@ -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 diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 659ecfa..d8289b9 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,15 @@ +2002-07-25 Gabriel Dos Reis + + * 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 * tree.c (cp_build_qualified_type_real): When copying diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h index a859d49..291caf6 100644 --- a/gcc/cp/cp-tree.h +++ b/gcc/cp/cp-tree.h @@ -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)); diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 30f7188..2b6bd25 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -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: diff --git a/gcc/cp/init.c b/gcc/cp/init.c index 1fa75b2..31c1505 100644 --- a/gcc/cp/init.c +++ b/gcc/cp/init.c @@ -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); } diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c index 6d810f5..e333d3e 100644 --- a/gcc/cp/typeck.c +++ b/gcc/cp/typeck.c @@ -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; -- 2.7.4