public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix C duplicate field detection bug (PR 46889)
@ 2010-12-30 20:52 Joseph S. Myers
  0 siblings, 0 replies; only message in thread
From: Joseph S. Myers @ 2010-12-30 20:52 UTC (permalink / raw)
  To: gcc-patches

This patch fixes PR 46889, a failure to detect duplicate field names
with anonymous structs and unions in some cases.  When anonymous
structs or unions are in use, duplicate detection must use
detect_field_duplicates_hash, but a premature optimization meant that
the loop deciding whether to use this function failed to handle the
case of the first field being the only anonymous one.

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
to mainline.

2010-12-30  Joseph Myers  <joseph@codesourcery.com>

	PR c/46889
	* c-decl.c (detect_field_duplicates): Ensure hash is used for
	finding duplicates when first field is anonymous.

testsuite:
2010-12-30  Joseph Myers  <joseph@codesourcery.com>

	PR c/46889
	* gcc.dg/anon-struct-15.c: New test.

Index: testsuite/gcc.dg/anon-struct-15.c
===================================================================
--- testsuite/gcc.dg/anon-struct-15.c	(revision 0)
+++ testsuite/gcc.dg/anon-struct-15.c	(revision 0)
@@ -0,0 +1,16 @@
+/* Test diagnostics for duplicate field names involving anonymous
+   struct or union as first field.  PR 46889.  */
+/* { dg-do compile } */
+/* { dg-options "" } */
+
+struct foo {
+  union {
+    struct {
+      unsigned long time_stamp;
+    };
+    struct {
+      int *page;
+    };
+  };
+  int *page; /* { dg-error "duplicate member" } */
+};
Index: c-decl.c
===================================================================
--- c-decl.c	(revision 168340)
+++ c-decl.c	(working copy)
@@ -6805,11 +6805,9 @@ detect_field_duplicates (tree fieldlist)
 
   /* First, see if there are more than "a few" fields.
      This is trivially true if there are zero or one fields.  */
-  if (!fieldlist)
-    return;
-  x = DECL_CHAIN (fieldlist);
-  if (!x)
+  if (!fieldlist || !DECL_CHAIN (fieldlist))
     return;
+  x = fieldlist;
   do {
     timeout--;
     if (DECL_NAME (x) == NULL_TREE

-- 
Joseph S. Myers
joseph@codesourcery.com

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2010-12-30 18:25 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-30 20:52 Fix C duplicate field detection bug (PR 46889) Joseph S. Myers

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).