[C++ PATCH]: size_zero_node
Nathan Sidwell
nathan@codesourcery.com
Mon Mar 20 05:54:00 GMT 2000
Hi,
Attached is a patch and test case for last week's problems with incomplete
types. I've created a new global tree node `size_incompletable_node' which is
an INT_CST of type bitsize_type. This is guaranteed to be a different
tree node to one which happens to have a value zero by dint of being the size of
a zero sized array. I then use a check for that TYPE_SIZE to determine if a type
is incompletable. (A type which is incomplete, but might be completed later will
have a NULL_TREE TYPE_SIZE.)
The attached test case passes with this patch
bootstrapped and tested on i686-pc-linux-gnu
ok?
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-03-20 Nathan Sidwell <nathan@codesourcery.com>
* tree.h (TI_SIZE_INCOMPLETABLE): New enumeration.
(size_incompletable_node): New node.
* tree.c (build_common_tree_nodes_2): Create
size_incompletable_node.
* stor-layout.c (layout_type) Use size_incompletable_node for
VOID_TYPE.
* cp/typeck.c (require_complete_type): size_incompletable_node
indicates an incompletable type.
(complete_type_or_else): Likewise.
Index: tree.h
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.h,v
retrieving revision 1.144
diff -c -3 -p -r1.144 tree.h
*** tree.h 2000/03/17 22:40:45 1.144
--- tree.h 2000/03/20 08:47:32
*************** enum tree_index
*** 1533,1538 ****
--- 1533,1539 ----
TI_SIZE_ZERO,
TI_SIZE_ONE,
+ TI_SIZE_INCOMPLETABLE,
TI_COMPLEX_INTEGER_TYPE,
TI_COMPLEX_FLOAT_TYPE,
*************** extern tree global_trees[TI_MAX];
*** 1584,1589 ****
--- 1585,1591 ----
#define integer_one_node global_trees[TI_INTEGER_ONE]
#define size_zero_node global_trees[TI_SIZE_ZERO]
#define size_one_node global_trees[TI_SIZE_ONE]
+ #define size_incompletable_node global_trees[TI_SIZE_INCOMPLETABLE]
#define null_pointer_node global_trees[TI_NULL_POINTER]
#define float_type_node global_trees[TI_FLOAT_TYPE]
Index: tree.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/tree.c,v
retrieving revision 1.125
diff -c -3 -p -r1.125 tree.c
*** tree.c 2000/03/17 22:40:45 1.125
--- tree.c 2000/03/20 08:47:29
*************** build_common_tree_nodes_2 (short_double)
*** 5646,5651 ****
--- 5646,5658 ----
size_one_node = build_int_2 (1, 0);
TREE_TYPE (size_one_node) = sizetype;
+ /* A special size to indicate an incomplete type that cannot be completed.
+ Because of our zero sized array extension, we have to distinguish
+ between an incompletable type and a zero sized array. We must have a
+ unique node, so cannot use bitsize_int which caches small values. */
+ size_incompletable_node = build_int_2 (0, 0);
+ TREE_TYPE (size_incompletable_node) = bitsizetype;
+
void_type_node = make_node (VOID_TYPE);
layout_type (void_type_node);
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/stor-layout.c,v
retrieving revision 1.57
diff -c -3 -p -r1.57 stor-layout.c
*** stor-layout.c 2000/03/15 00:12:37 1.57
--- stor-layout.c 2000/03/20 08:47:27
*************** layout_type (type)
*** 1174,1180 ****
break;
case VOID_TYPE:
! TYPE_SIZE (type) = bitsize_int (0);
TYPE_SIZE_UNIT (type) = size_zero_node;
TYPE_ALIGN (type) = 1;
TYPE_MODE (type) = VOIDmode;
--- 1174,1180 ----
break;
case VOID_TYPE:
! TYPE_SIZE (type) = size_incompletable_node;
TYPE_SIZE_UNIT (type) = size_zero_node;
TYPE_ALIGN (type) = 1;
TYPE_MODE (type) = VOIDmode;
Index: cp/typeck.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/typeck.c,v
retrieving revision 1.266
diff -c -3 -p -r1.266 typeck.c
*** typeck.c 2000/03/17 17:31:56 1.266
--- typeck.c 2000/03/20 08:47:56
*************** require_complete_type (value)
*** 106,112 ****
type = TREE_TYPE (value);
/* First, detect a valid value with a complete type. */
! if (TYPE_SIZE (type) && !integer_zerop (TYPE_SIZE (type)))
return value;
/* If we see X::Y, we build an OFFSET_TYPE which has
--- 106,112 ----
type = TREE_TYPE (value);
/* First, detect a valid value with a complete type. */
! if (TYPE_SIZE (type) && TYPE_SIZE (type) != size_incompletable_node)
return value;
/* If we see X::Y, we build an OFFSET_TYPE which has
*************** complete_type_or_else (type, value)
*** 176,182 ****
if (type == error_mark_node)
/* We already issued an error. */
return NULL_TREE;
! else if (!TYPE_SIZE (type) || integer_zerop (TYPE_SIZE (type)))
{
incomplete_type_error (value, type);
return NULL_TREE;
--- 176,182 ----
if (type == error_mark_node)
/* We already issued an error. */
return NULL_TREE;
! else if (!TYPE_SIZE (type) || TYPE_SIZE (type) == size_incompletable_node)
{
incomplete_type_error (value, type);
return NULL_TREE;
More information about the Gcc-bugs
mailing list