diff mbox

fix PR 47786, DECL_CHAIN fallout with -flto

Message ID 20110223191408.GX26625@codesourcery.com
State New
Headers show

Commit Message

Nathan Froyd Feb. 23, 2011, 7:14 p.m. UTC
The patch below fixes PR 47786, a bit of DECL_CHAIN fallout.  The patch
is trivial, even obvious, since it replaces the custom loop with
list_length.

The only problem is adding a testcase.  I can't add the existing
testcase from the PR to gcc.dg/lto/ because the bug isn't triggered when
compiling the files separately; the bug is only triggered when both
source files are specified on the command line to cc1 (*not* to
[x]gcc).  AFAIK, there's no infrastructure for doing something like that
in the current testsuite.

Any ideas for putting together a testcase, or should I just commit
as-is?

-Nathan

	* c-common.c (c_type_hash): Call list_length instead of iterating
	through DECL_CHAIN.  Rename 'i' to 'n_elements'.

   tree t2;
@@ -4064,14 +4064,15 @@ c_type_hash (const void *p)
     default:
       gcc_unreachable ();
     }
-  for (; t2; t2 = DECL_CHAIN (t2))
-    i++;
+  /* FIXME: We want to use a DECL_CHAIN iteration method here, but
+     TYPE_VALUES of ENUMERAL_TYPEs is stored as a TREE_LIST.  */
+  n_elements = list_length (t2);
   /* We might have a VLA here.  */
   if (TREE_CODE (TYPE_SIZE (t)) != INTEGER_CST)
     size = 0;
   else
     size = TREE_INT_CST_LOW (TYPE_SIZE (t));
-  return ((size << 24) | (i << shift));
+  return ((size << 24) | (n_elements << shift));
 }
 
 static GTY((param_is (union tree_node))) htab_t type_hash_table;

Comments

Nathan Froyd March 7, 2011, 3:33 p.m. UTC | #1
On Wed, Feb 23, 2011 at 11:14:08AM -0800, Nathan Froyd wrote:
> The patch below fixes PR 47786, a bit of DECL_CHAIN fallout.  The patch
> is trivial, even obvious, since it replaces the custom loop with
> list_length.
> 
> The only problem is adding a testcase.  I can't add the existing
> testcase from the PR to gcc.dg/lto/ because the bug isn't triggered when
> compiling the files separately; the bug is only triggered when both
> source files are specified on the command line to cc1 (*not* to
> [x]gcc).  AFAIK, there's no infrastructure for doing something like that
> in the current testsuite.

In the absence of comments and inspiration about what to do, I've
committed this patch sans testcase.

-Nathan
diff mbox

Patch

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index d696b5f..f029661 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4035,7 +4035,7 @@  c_apply_type_quals_to_decl (int type_quals, tree
decl)
 static hashval_t
 c_type_hash (const void *p)
 {
-  int i = 0;
+  int n_elements;
   int shift, size;
   const_tree const t = (const_tree) p;