Patch for bug 18498

Joseph S. Myers joseph@codesourcery.com
Mon Nov 15 22:44:00 GMT 2004


This patch fixes bug 18498, a regression in 3.4 and 4.0 where the
check for invalid bit-field types was too early.

Bootstrapped with no regressions on i686-pc-linux-gnu.  Applied to
mainline.  Will be applied to 3.4 branch after testing there.

-- 
Joseph S. Myers               http://www.srcf.ucam.org/~jsm28/gcc/
    jsm@polyomino.org.uk (personal mail)
    joseph@codesourcery.com (CodeSourcery mail)
    jsm28@gcc.gnu.org (Bugzilla assignments and CCs)

2004-11-15  Joseph S. Myers  <joseph@codesourcery.com>

	PR c/18498
	* c-decl.c (grokdeclarator): Call check_bitfield_type_and_width
	after processing the declarator.

testsuite:
2004-11-15  Joseph S. Myers  <joseph@codesourcery.com>

	PR c/18498
	* gcc.dg/bitfld-13.c: New test.

diff -rupN GCC.orig/gcc/c-decl.c GCC/gcc/c-decl.c
--- GCC.orig/gcc/c-decl.c	2004-11-09 10:17:21.000000000 +0000
+++ GCC/gcc/c-decl.c	2004-11-15 13:37:05.000000000 +0000
@@ -3809,10 +3809,6 @@ grokdeclarator (const struct c_declarato
       && TREE_CODE (type) == INTEGER_TYPE)
     type = c_common_unsigned_type (type);
 
-  /* Check the type and width of a bit-field.  */
-  if (bitfield)
-    check_bitfield_type_and_width (&type, width, orig_name);
-
   /* Figure out the type qualifiers for the declaration.  There are
      two ways a declaration can become qualified.  One is something
      like `const int i' where the `const' is explicit.  Another is
@@ -4252,6 +4248,10 @@ grokdeclarator (const struct c_declarato
 
   /* Now TYPE has the actual type.  */
 
+  /* Check the type and width of a bit-field.  */
+  if (bitfield)
+    check_bitfield_type_and_width (&type, width, orig_name);
+
   /* Did array size calculations overflow?  */
 
   if (TREE_CODE (type) == ARRAY_TYPE
diff -rupN GCC.orig/gcc/testsuite/gcc.dg/bitfld-13.c GCC/gcc/testsuite/gcc.dg/bitfld-13.c
--- GCC.orig/gcc/testsuite/gcc.dg/bitfld-13.c	1970-01-01 00:00:00.000000000 +0000
+++ GCC/gcc/testsuite/gcc.dg/bitfld-13.c	2004-11-15 13:34:53.000000000 +0000
@@ -0,0 +1,14 @@
+/* Test invalid bit-field types: bug 18498.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+int
+main(void)
+{
+  struct X {
+    int s[20] : 1; /* { dg-error "error: bit-field 's' has invalid type" } */
+    int *p : 2; /* { dg-error "error: bit-field 'p' has invalid type" } */
+    int (*f)(float) : 3; /* { dg-error "error: bit-field 'f' has invalid type" } */
+  } x;
+  return 0;
+}



More information about the Gcc-patches mailing list