This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++ PATCH]: Fix 19964
- From: Nathan Sidwell <nathan at codesourcery dot com>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Date: Tue, 11 Oct 2005 18:14:35 +0100
- Subject: [C++ PATCH]: Fix 19964
Hi,
this patch fixes 19964, a C++ ICE after invalid regression. It affects the
common code, so I need approval.
We can create FIELD_DECLs with an error_mark type, and place_field will not set
the field offset information for them. This leads to blow up later on. One
solution would be not to create such field decls, but that leads to a worse user
experience as we can get a cascade of errors, when the user tries to use the
field. So I rejected that.
This patch simply sets the offsets to zero, when a field decl has an error_mark
type.
booted & tested on i686-pc-linux-gnu, ok?
nathan
--
Nathan Sidwell :: http://www.codesourcery.com :: CodeSourcery LLC
nathan@codesourcery.com :: http://www.planetfall.pwp.blueyonder.co.uk
2005-10-11 Nathan Sidwell <nathan@codesourcery.com>
PR c++/19964
* stor-layout.c (place_field): Set DECL_FIELD_OFFSET and
DECL_FIELD_BIT_OFFSET of FIELD_DECLs, even if they have an invalid
type.
PR c++/19964
cp/class.c (walk_subobject_offsets): Don't walk error_mark_node.
Index: stor-layout.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stor-layout.c,v
retrieving revision 1.243
diff -c -3 -p -r1.243 stor-layout.c
*** stor-layout.c 29 Sep 2005 22:11:12 -0000 1.243
--- stor-layout.c 11 Oct 2005 15:55:13 -0000
*************** place_field (record_layout_info rli, tre
*** 800,808 ****
/* The type of this field. */
tree type = TREE_TYPE (field);
! if (TREE_CODE (field) == ERROR_MARK || TREE_CODE (type) == ERROR_MARK)
! return;
/* If FIELD is static, then treat it like a separate variable, not
really like a structure field. If it is a FUNCTION_DECL, it's a
method. In both cases, all we do is lay out the decl, and we do
--- 800,818 ----
/* The type of this field. */
tree type = TREE_TYPE (field);
! gcc_assert (TREE_CODE (field) != ERROR_MARK);
+ if (TREE_CODE (type) == ERROR_MARK)
+ {
+ if (TREE_CODE (field) == FIELD_DECL)
+ {
+ DECL_FIELD_OFFSET (field) = size_int (0);
+ DECL_FIELD_BIT_OFFSET (field) = bitsize_int (0);
+ }
+
+ return;
+ }
+
/* If FIELD is static, then treat it like a separate variable, not
really like a structure field. If it is a FUNCTION_DECL, it's a
method. In both cases, all we do is lay out the decl, and we do
Index: cp/class.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/class.c,v
retrieving revision 1.733
diff -c -3 -p -r1.733 class.c
*** cp/class.c 22 Sep 2005 16:34:50 -0000 1.733
--- cp/class.c 11 Oct 2005 15:55:20 -0000
*************** walk_subobject_offsets (tree type,
*** 3101,3106 ****
--- 3101,3109 ----
if (max_offset && INT_CST_LT (max_offset, offset))
return 0;
+ if (type == error_mark_node)
+ return 0;
+
if (!TYPE_P (type))
{
if (abi_version_at_least (2))
struct A
{ // { dg-error "forward declaration" }
A : A; // { dg-error "expected|incomplete" }
A : B; // { dg-error "not declared|incomplete" }
A : A(); // { dg-error "undefined type|incomplete" }
A : B(); // { dg-error "function call|incomplete" }
A : A[]; // { dg-error "expected|array reference|incomplete" }
A : B[]; // { dg-error "not declared|expected|array reference|incomplete" }
};