This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[c++ patch] use VOID_TYPE_P
- To: gcc-patches at gcc dot gnu dot org
- Subject: [c++ patch] use VOID_TYPE_P
- From: Nathan Sidwell <nathan at codesourcery dot com>
- Date: Tue, 20 Jun 2000 16:48:01 +0100
- Organization: Codesourcery LLC
Hi,
I've installed the attached, which gets g++ using the recently introduced
VOID_TYPE_P macro. In some cases this relaxes the check, which I
believe to be corect (from similar errors in the C frontend), and
in one case directly testing for void_type_node, on a parameter list,
as that is the canonical way of doing a parameter walk.
approved by Mark, built & tested on i686-pc-linux-gnu
nathan
--
Dr Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
'But that's a lie.' - 'Yes it is. What's your point?'
nathan@codesourcery.com : http://www.cs.bris.ac.uk/~nathan/ : nathan@acm.org
2000-06-20 Nathan Sidwell <nathan@codesourcery.com>
* call.c (build_conditional_expr): Use VOID_TYPE_P.
* cvt.c (cp_convert_to_pointer): Likewise.
(convert_to_void): Likewise.
* error.c (dump_expr): Likewise.
* except.c (complete_ptr_ref_or_void_ptr_p): Likewise.
* init.c (build_delete): Likewise.
* method.c (emit_thunk): Likewise.
* optmize.c (declare_return_variable): Likewise.
* rtti.c (get_tinfo_decl_dynamic): Likewise.
(get_typeid): Likewise.
(build_dynamic_cast_1): Likewise.
* typeck.c (composite_pointer_type): Likewise.
(common_type): Likewise.
(build_indirect_ref): Likewise.
(build_binary_op): Likewise.
(build_x_compound_expr): Likewise.
(check_return_expr): Likewise.
* typeck2.c (add_exception_specifier): Likewise.
* mangle.c (write_method_parms): Use direct comparison for end
of parmlist.
Index: cp/call.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/call.c,v
retrieving revision 1.223
diff -c -3 -p -r1.223 call.c
*** call.c 2000/06/09 21:47:40 1.223
--- call.c 2000/06/20 08:53:36
*************** build_conditional_expr (arg1, arg2, arg3
*** 2858,2884 ****
and third operands. */
arg2_type = TREE_TYPE (arg2);
arg3_type = TREE_TYPE (arg3);
! if (same_type_p (TYPE_MAIN_VARIANT (arg2_type), void_type_node)
! || same_type_p (TYPE_MAIN_VARIANT (arg3_type), void_type_node))
{
- int arg2_void_p;
- int arg3_void_p;
-
/* Do the conversions. We don't these for `void' type arguments
since it can't have any effect and since decay_conversion
does not handle that case gracefully. */
! if (!same_type_p (TYPE_MAIN_VARIANT (arg2_type), void_type_node))
arg2 = decay_conversion (arg2);
! if (!same_type_p (TYPE_MAIN_VARIANT (arg3_type), void_type_node))
arg3 = decay_conversion (arg3);
arg2_type = TREE_TYPE (arg2);
arg3_type = TREE_TYPE (arg3);
- arg2_void_p = same_type_p (TYPE_MAIN_VARIANT (arg2_type),
- void_type_node);
- arg3_void_p = same_type_p (TYPE_MAIN_VARIANT (arg3_type),
- void_type_node);
-
/* [expr.cond]
One of the following shall hold:
--- 2858,2875 ----
and third operands. */
arg2_type = TREE_TYPE (arg2);
arg3_type = TREE_TYPE (arg3);
! if (VOID_TYPE_P (arg2_type) || VOID_TYPE_P (arg3_type))
{
/* Do the conversions. We don't these for `void' type arguments
since it can't have any effect and since decay_conversion
does not handle that case gracefully. */
! if (!VOID_TYPE_P (arg2_type))
arg2 = decay_conversion (arg2);
! if (!VOID_TYPE_P (arg3_type))
arg3 = decay_conversion (arg3);
arg2_type = TREE_TYPE (arg2);
arg3_type = TREE_TYPE (arg3);
/* [expr.cond]
One of the following shall hold:
*************** build_conditional_expr (arg1, arg2, arg3
*** 2893,2904 ****
^ (TREE_CODE (arg3) == THROW_EXPR))
result_type = ((TREE_CODE (arg2) == THROW_EXPR)
? arg3_type : arg2_type);
! else if (arg2_void_p && arg3_void_p)
result_type = void_type_node;
else
{
cp_error ("`%E' has type `void' and is not a throw-expression",
! arg2_void_p ? arg2 : arg3);
return error_mark_node;
}
--- 2884,2895 ----
^ (TREE_CODE (arg3) == THROW_EXPR))
result_type = ((TREE_CODE (arg2) == THROW_EXPR)
? arg3_type : arg2_type);
! else if (VOID_TYPE_P (arg2_type) && VOID_TYPE_P (arg3_type))
result_type = void_type_node;
else
{
cp_error ("`%E' has type `void' and is not a throw-expression",
! VOID_TYPE_P (arg2_type) ? arg2 : arg3);
return error_mark_node;
}
Index: cp/cvt.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/cvt.c,v
retrieving revision 1.83
diff -c -3 -p -r1.83 cvt.c
*** cvt.c 2000/04/26 15:43:47 1.83
--- cvt.c 2000/06/20 08:53:36
*************** cp_convert_to_pointer (type, expr)
*** 99,105 ****
/* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
if (TREE_CODE (type) == POINTER_TYPE
&& (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
! || TYPE_MAIN_VARIANT (TREE_TYPE (type)) == void_type_node))
{
/* Allow an implicit this pointer for pointer to member
functions. */
--- 99,105 ----
/* Handle anachronistic conversions from (::*)() to cv void* or (*)(). */
if (TREE_CODE (type) == POINTER_TYPE
&& (TREE_CODE (TREE_TYPE (type)) == FUNCTION_TYPE
! || VOID_TYPE_P (TREE_TYPE (type))))
{
/* Allow an implicit this pointer for pointer to member
functions. */
*************** convert_to_void (expr, implicit)
*** 860,866 ****
return error_mark_node;
if (!TREE_TYPE (expr))
return expr;
! if (same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)), void_type_node))
return expr;
switch (TREE_CODE (expr))
{
--- 860,866 ----
return error_mark_node;
if (!TREE_TYPE (expr))
return expr;
! if (VOID_TYPE_P (TREE_TYPE (expr)))
return expr;
switch (TREE_CODE (expr))
{
*************** convert_to_void (expr, implicit)
*** 958,965 ****
implicit, expr);
}
! if (expr != error_mark_node
! && !same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (expr)), void_type_node))
{
/* FIXME: This is where we should check for expressions with no
effects. At the moment we do that in both build_x_component_expr
--- 958,964 ----
implicit, expr);
}
! if (expr != error_mark_node && !VOID_TYPE_P (TREE_TYPE (expr)))
{
/* FIXME: This is where we should check for expressions with no
effects. At the moment we do that in both build_x_component_expr
Index: cp/error.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/error.c,v
retrieving revision 1.116
diff -c -3 -p -r1.116 error.c
*** error.c 2000/06/16 07:34:42 1.116
--- error.c 2000/06/20 08:53:37
*************** dump_expr (t, flags)
*** 1730,1738 ****
break;
case CONVERT_EXPR:
! if (same_type_p (TREE_TYPE (t), void_type_node))
{
! OB_PUTS ("(void)");
dump_expr (TREE_OPERAND (t, 0), flags);
}
else
--- 1730,1740 ----
break;
case CONVERT_EXPR:
! if (VOID_TYPE_P (TREE_TYPE (t)))
{
! OB_PUTC ('(');
! dump_type (TREE_TYPE (t), flags);
! OB_PUTC (')');
dump_expr (TREE_OPERAND (t, 0), flags);
}
else
Index: cp/except.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/except.c,v
retrieving revision 1.111
diff -c -3 -p -r1.111 except.c
*** except.c 2000/05/24 06:15:04 1.111
--- except.c 2000/06/20 08:53:37
*************** complete_ptr_ref_or_void_ptr_p (type, fr
*** 1073,1079 ****
{
tree core = TREE_TYPE (type);
! if (is_ptr && same_type_p (TYPE_MAIN_VARIANT (core), void_type_node))
/* OK */;
else if (!complete_type_or_else (core, from))
return 0;
--- 1073,1079 ----
{
tree core = TREE_TYPE (type);
! if (is_ptr && VOID_TYPE_P (core))
/* OK */;
else if (!complete_type_or_else (core, from))
return 0;
Index: cp/init.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/init.c,v
retrieving revision 1.202
diff -c -3 -p -r1.202 init.c
*** init.c 2000/06/19 18:40:21 1.202
--- init.c 2000/06/20 08:53:39
*************** build_delete (type, addr, auto_delete, f
*** 3163,3169 ****
if (TREE_CODE (type) == POINTER_TYPE)
{
type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
! if (type != void_type_node && !complete_type_or_else (type, addr))
return error_mark_node;
if (TREE_CODE (type) == ARRAY_TYPE)
goto handle_array;
--- 3163,3169 ----
if (TREE_CODE (type) == POINTER_TYPE)
{
type = TYPE_MAIN_VARIANT (TREE_TYPE (type));
! if (!VOID_TYPE_P (type) && !complete_type_or_else (type, addr))
return error_mark_node;
if (TREE_CODE (type) == ARRAY_TYPE)
goto handle_array;
Index: cp/mangle.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/mangle.c,v
retrieving revision 1.8
diff -c -3 -p -r1.8 mangle.c
*** mangle.c 2000/06/12 06:43:27 1.8
--- mangle.c 2000/06/20 08:53:39
*************** write_method_parms (parm_list, method_p)
*** 1467,1473 ****
{
tree parm = TREE_VALUE (parm_list);
! if (same_type_p (parm, void_type_node))
{
/* "Empty parameter lists, whether declared as () or
conventionally as (void), are encoded with a void parameter
--- 1467,1473 ----
{
tree parm = TREE_VALUE (parm_list);
! if (parm == void_type_node)
{
/* "Empty parameter lists, whether declared as () or
conventionally as (void), are encoded with a void parameter
Index: cp/method.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/method.c,v
retrieving revision 1.168
diff -c -3 -p -r1.168 method.c
*** method.c 2000/06/16 07:34:43 1.168
--- method.c 2000/06/20 08:53:40
*************** emit_thunk (thunk_fndecl)
*** 2271,2280 ****
t = tree_cons (NULL_TREE, a, t);
t = nreverse (t);
t = build_call (function, t);
! if (!same_type_p (TREE_TYPE (t), void_type_node))
! finish_return_stmt (t);
! else
finish_expr_stmt (t);
/* The back-end expects DECL_INITIAL to contain a BLOCK, so we
create one. */
--- 2271,2280 ----
t = tree_cons (NULL_TREE, a, t);
t = nreverse (t);
t = build_call (function, t);
! if (VOID_TYPE_P (TREE_TYPE (t)))
finish_expr_stmt (t);
+ else
+ finish_return_stmt (t);
/* The back-end expects DECL_INITIAL to contain a BLOCK, so we
create one. */
Index: cp/optimize.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/optimize.c,v
retrieving revision 1.38
diff -c -3 -p -r1.38 optimize.c
*** optimize.c 2000/06/15 21:24:38 1.38
--- optimize.c 2000/06/20 08:53:41
*************** declare_return_variable (id, use_stmt)
*** 477,484 ****
/* We don't need to do anything for functions that don't return
anything. */
! if (!result || same_type_p (TYPE_MAIN_VARIANT (TREE_TYPE (result)),
! void_type_node))
{
*use_stmt = NULL_TREE;
return NULL_TREE;
--- 477,483 ----
/* We don't need to do anything for functions that don't return
anything. */
! if (!result || VOID_TYPE_P (TREE_TYPE (result)))
{
*use_stmt = NULL_TREE;
return NULL_TREE;
Index: cp/rtti.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/rtti.c,v
retrieving revision 1.95
diff -c -3 -p -r1.95 rtti.c
*** rtti.c 2000/06/14 05:30:05 1.95
--- rtti.c 2000/06/20 08:53:46
*************** get_tinfo_decl_dynamic (exp)
*** 233,239 ****
/* Peel off cv qualifiers. */
type = TYPE_MAIN_VARIANT (type);
! if (type != void_type_node)
type = complete_type_or_else (type, exp);
if (!type)
--- 233,239 ----
/* Peel off cv qualifiers. */
type = TYPE_MAIN_VARIANT (type);
! if (!VOID_TYPE_P (type))
type = complete_type_or_else (type, exp);
if (!type)
*************** get_typeid (type)
*** 513,519 ****
that is the operand of typeid are always ignored. */
type = TYPE_MAIN_VARIANT (type);
! if (type != void_type_node)
type = complete_type_or_else (type, NULL_TREE);
if (!type)
--- 513,519 ----
that is the operand of typeid are always ignored. */
type = TYPE_MAIN_VARIANT (type);
! if (!VOID_TYPE_P (type))
type = complete_type_or_else (type, NULL_TREE);
if (!type)
*************** build_dynamic_cast_1 (type, expr)
*** 702,709 ****
{
tree expr1;
/* if TYPE is `void *', return pointer to complete object. */
! if (tc == POINTER_TYPE
! && TYPE_MAIN_VARIANT (TREE_TYPE (type)) == void_type_node)
{
/* if b is an object, dynamic_cast<void *>(&b) == (void *)&b. */
if (TREE_CODE (expr) == ADDR_EXPR
--- 702,708 ----
{
tree expr1;
/* if TYPE is `void *', return pointer to complete object. */
! if (tc == POINTER_TYPE && VOID_TYPE_P (TREE_TYPE (type)))
{
/* if b is an object, dynamic_cast<void *>(&b) == (void *)&b. */
if (TREE_CODE (expr) == ADDR_EXPR
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.290
diff -c -3 -p -r1.290 typeck.c
*** typeck.c 2000/06/15 21:24:39 1.290
--- typeck.c 2000/06/20 08:53:48
*************** composite_pointer_type (t1, t2, arg1, ar
*** 443,455 ****
if (comp_target_types (t1, t2, 1))
result_type = common_type (t1, t2);
! else if (TYPE_MAIN_VARIANT (TREE_TYPE (t1)) == void_type_node)
{
if (pedantic && TREE_CODE (t2) == FUNCTION_TYPE)
pedwarn ("ISO C++ forbids %s between pointer of type `void *' and pointer-to-function", location);
result_type = qualify_type (t1, t2);
}
! else if (TYPE_MAIN_VARIANT (TREE_TYPE (t2)) == void_type_node)
{
if (pedantic && TREE_CODE (t1) == FUNCTION_TYPE)
pedwarn ("ISO C++ forbids %s between pointer of type `void *' and pointer-to-function", location);
--- 443,455 ----
if (comp_target_types (t1, t2, 1))
result_type = common_type (t1, t2);
! else if (VOID_TYPE_P (TREE_TYPE (t1)))
{
if (pedantic && TREE_CODE (t2) == FUNCTION_TYPE)
pedwarn ("ISO C++ forbids %s between pointer of type `void *' and pointer-to-function", location);
result_type = qualify_type (t1, t2);
}
! else if (VOID_TYPE_P (TREE_TYPE (t2)))
{
if (pedantic && TREE_CODE (t1) == FUNCTION_TYPE)
pedwarn ("ISO C++ forbids %s between pointer of type `void *' and pointer-to-function", location);
*************** common_type (t1, t2)
*** 600,606 ****
if (tt1 == tt2)
target = tt1;
! else if (tt1 == void_type_node || tt2 == void_type_node)
target = void_type_node;
else if (tt1 == unknown_type_node)
target = tt2;
--- 600,606 ----
if (tt1 == tt2)
target = tt1;
! else if (VOID_TYPE_P (tt1) || VOID_TYPE_P (tt2))
target = void_type_node;
else if (tt1 == unknown_type_node)
target = tt2;
*************** build_indirect_ref (ptr, errorstring)
*** 2330,2336 ****
types. */
tree t = canonical_type_variant (TREE_TYPE (type));
! if (same_type_p (TYPE_MAIN_VARIANT (t), void_type_node))
{
/* A pointer to incomplete type (other than cv void) can be
dereferenced [expr.unary.op]/1 */
--- 2330,2336 ----
types. */
tree t = canonical_type_variant (TREE_TYPE (type));
! if (VOID_TYPE_P (t))
{
/* A pointer to incomplete type (other than cv void) can be
dereferenced [expr.unary.op]/1 */
*************** build_binary_op (code, orig_op0, orig_op
*** 3582,3588 ****
if (comp_target_types (type0, type1, 1))
result_type = common_type (type0, type1);
! else if (tt0 == void_type_node)
{
if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE
&& tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1)))
--- 3582,3588 ----
if (comp_target_types (type0, type1, 1))
result_type = common_type (type0, type1);
! else if (VOID_TYPE_P (tt0))
{
if (pedantic && TREE_CODE (tt1) == FUNCTION_TYPE
&& tree_int_cst_lt (TYPE_SIZE (type0), TYPE_SIZE (type1)))
*************** build_binary_op (code, orig_op0, orig_op
*** 3590,3596 ****
else if (TREE_CODE (tt1) == OFFSET_TYPE)
pedwarn ("ISO C++ forbids conversion of a pointer to member to `void *'");
}
! else if (tt1 == void_type_node)
{
if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE
&& tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0)))
--- 3590,3596 ----
else if (TREE_CODE (tt1) == OFFSET_TYPE)
pedwarn ("ISO C++ forbids conversion of a pointer to member to `void *'");
}
! else if (VOID_TYPE_P (tt1))
{
if (pedantic && TREE_CODE (tt0) == FUNCTION_TYPE
&& tree_int_cst_lt (TYPE_SIZE (type1), TYPE_SIZE (type0)))
*************** build_x_compound_expr (list)
*** 5058,5064 ****
unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused_value)
&& !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
! && TREE_TYPE (TREE_VALUE(list)) == void_type_node))
warning("left-hand operand of comma expression has no effect");
}
#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
--- 5058,5064 ----
unless it was explicitly cast to (void). */
if ((extra_warnings || warn_unused_value)
&& !(TREE_CODE (TREE_VALUE(list)) == CONVERT_EXPR
! && VOID_TYPE_P (TREE_TYPE (TREE_VALUE(list)))))
warning("left-hand operand of comma expression has no effect");
}
#if 0 /* this requires a gcc backend patch to export warn_if_unused_value */
*************** check_return_expr (retval)
*** 6799,6805 ****
result = DECL_RESULT (current_function_decl);
valtype = TREE_TYPE (result);
my_friendly_assert (valtype != NULL_TREE, 19990924);
! fn_returns_value_p = !same_type_p (valtype, void_type_node);
if (!retval && DECL_NAME (result) && fn_returns_value_p)
retval = result;
--- 6799,6805 ----
result = DECL_RESULT (current_function_decl);
valtype = TREE_TYPE (result);
my_friendly_assert (valtype != NULL_TREE, 19990924);
! fn_returns_value_p = !VOID_TYPE_P (valtype);
if (!retval && DECL_NAME (result) && fn_returns_value_p)
retval = result;
*************** check_return_expr (retval)
*** 6817,6823 ****
isn't supposed to return a value. */
else if (retval && !fn_returns_value_p)
{
! if (same_type_p (TREE_TYPE (retval), void_type_node))
/* You can return a `void' value from a function of `void'
type. In that case, we have to evaluate the expression for
its side-effects. */
--- 6817,6823 ----
isn't supposed to return a value. */
else if (retval && !fn_returns_value_p)
{
! if (VOID_TYPE_P (TREE_TYPE (retval)))
/* You can return a `void' value from a function of `void'
type. In that case, we have to evaluate the expression for
its side-effects. */
Index: cp/typeck2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck2.c,v
retrieving revision 1.83
diff -c -3 -p -r1.83 typeck2.c
*** typeck2.c 2000/05/01 16:51:17 1.83
--- typeck2.c 2000/06/20 08:53:49
*************** add_exception_specifier (list, spec, com
*** 1466,1472 ****
core = TREE_TYPE (core);
if (complain < 0)
ok = 1;
! else if (TYPE_MAIN_VARIANT (core) == void_type_node)
ok = is_ptr;
else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
ok = 1;
--- 1466,1472 ----
core = TREE_TYPE (core);
if (complain < 0)
ok = 1;
! else if (VOID_TYPE_P (core))
ok = is_ptr;
else if (TREE_CODE (core) == TEMPLATE_TYPE_PARM)
ok = 1;