This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] Fix PR c/26818: ICE packing erroneous files in structs


The C compiler crashes since GCC 4.1.0 when a struct with an erroneous
(e.g. incomplete) field is attributed with "packed":

  struct __attribute__ ((packed)) A
  {
    struct B b;
  };

bug.c:3: error: field 'b' has incomplete type
bug.c:4: internal compiler error: tree check: expected class 'type', have 'exceptional' (error_mark) in finish_struct, at c-decl.c:5367
Please submit a full bug report, [etc.]

The following patch fixes that by skipping fields whose TREE_TYPE
is error_mark_node when processing the field sizes in finish_struct.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.
Ok for mainline and 4.1 branch?

Regards,
Volker

:ADDPATCH C:


2006-03-27  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/26818
	* c-decl.c (finish_struct): Skip erroneous fields.

===================================================================
--- gcc/gcc/c-decl.c	(revision 112406)
+++ gcc/gcc/c-decl.c	(working copy)
@@ -5362,6 +5362,9 @@ finish_struct (tree t, tree fieldlist, tree
   saw_named_field = 0;
   for (x = fieldlist; x; x = TREE_CHAIN (x))
     {
+      if (TREE_TYPE (x) == error_mark_node)
+	continue;
+
       DECL_CONTEXT (x) = t;
 
       if (TYPE_PACKED (t) && TYPE_ALIGN (TREE_TYPE (x)) > BITS_PER_UNIT)
===================================================================

2006-03-27  Volker Reichelt  <reichelt@igpm.rwth-aachen.de>

	PR c/26818
	* testsuite/gcc.dg/struct-incompl-1.c: New test.

===================================================================
--- gcc/gcc/testsuite/gcc.dg/struct-incompl-1.c	2005-08-29 00:25:44 +0200
+++ gcc/gcc/testsuite/gcc.dg/struct-incompl-1.c	2006-03-27 16:27:57 +0200
@@ -0,0 +1,4 @@
+struct __attribute__ ((packed)) A
+{
+  struct B b; /* { dg-error "incomplete" } */
+};
===================================================================



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]