Patch to use ARRAY_SIZE in lieu of explicit "sizeof/sizeof"

Kaveh R. Ghazi ghazi@caip.rutgers.edu
Sat Mar 2 18:32:00 GMT 2002


This patch make use of the libiberty macro ARRAY_SIZE in a bunch of
places where we were doing explicit size calculations.  Writing code
with ARRAY_SIZE is much more readable IMHO.

Bootstrapped on sparc-sun-solaris2.7, no testsuite regressions.

Ok to install?

		Thanks,
		--Kaveh


2002-02-28  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>

	* attribs.c (init_attributes, decl_attributes): Use ARRAY_SIZE in
	lieu of explicit sizeof/sizeof.
	* i386.c (override_options, ix86_init_mmx_sse_builtins,
	ix86_expand_builtin): Likewise.
	* mips.c (mips_add_gc_roots): Likewise.
	* mmix.c (mmix_output_condition): Likewise.
	* rs6000.c (rs6000_override_options, altivec_expand_builtin,
	altivec_init_builtins): Likewise.
	* sparc.c (mark_ultrasparc_pipeline_state): Likewise.
	* cppexp.c (Nsuff, parse_number): Likewise.
	* cppinit.c (builtin_array_end): Likewise.
	* gcc.c (n_default_compilers, process_command): Likewise.
	* genpreds.c (output_predicate_decls): Likewise.
	* ggc-page.c (NUM_EXTRA_ORDERS): Likewise.
	* lcm.c (N_ENTITIES): Likewise.
	* stor-layout.c (set_sizetype): Likewise.
	
ada:
	* utils.c (init_gnat_to_gnu, init_gigi_decls): Use ARRAY_SIZE in
	lieu of explicit sizeof/sizeof.

cp:
	* decl.c (cxx_init_decl_processing): Use ARRAY_SIZE in lieu of
	explicit sizeof/sizeof.
	* decl2.c (cxx_decode_option): Likewise.
	* lex.c (init_reswords, REDUCE_LENGTH, TOKEN_LENGTH): Likewise.

java:
	* class.c (init_class_processing): Use ARRAY_SIZE in lieu of
	explicit sizeof/sizeof.
	* decl.c (java_init_decl_processing): Likewise.
	* jcf-parse.c (init_jcf_parse): Likewise.
	* parse.y (init_src_parse): Likewise.

diff -rup orig/egcc-CVS20020228/gcc/attribs.c egcc-CVS20020228/gcc/attribs.c
--- orig/egcc-CVS20020228/gcc/attribs.c	Tue Feb 26 16:30:15 2002
+++ egcc-CVS20020228/gcc/attribs.c	Thu Feb 28 22:06:01 2002
@@ -177,7 +177,7 @@ static void
 init_attributes ()
 {
 #ifdef ENABLE_CHECKING
-  int i;
+  size_t i;
 #endif
 
   attribute_tables[0]
@@ -188,9 +188,7 @@ init_attributes ()
 
 #ifdef ENABLE_CHECKING
   /* Make some sanity checks on the attribute tables.  */
-  for (i = 0;
-       i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
-       i++)
+  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
     {
       int j;
 
@@ -222,9 +220,7 @@ init_attributes ()
     }
 
   /* Check that each name occurs just once in each table.  */
-  for (i = 0;
-       i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
-       i++)
+  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
     {
       int j, k;
       for (j = 0; attribute_tables[i][j].name != NULL; j++)
@@ -234,16 +230,11 @@ init_attributes ()
 	    abort ();
     }
   /* Check that no name occurs in more than one table.  */
-  for (i = 0;
-       i < (int) (sizeof (attribute_tables) / sizeof (attribute_tables[0]));
-       i++)
+  for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
     {
-      int j, k, l;
+      size_t j, k, l;
 
-      for (j = i + 1;
-	   j < ((int) (sizeof (attribute_tables)
-		       / sizeof (attribute_tables[0])));
-	   j++)
+      for (j = i + 1; j < ARRAY_SIZE (attribute_tables); j++)
 	for (k = 0; attribute_tables[i][k].name != NULL; k++)
 	  for (l = 0; attribute_tables[j][l].name != NULL; l++)
 	    if (!strcmp (attribute_tables[i][k].name,
@@ -294,10 +285,7 @@ decl_attributes (node, attributes, flags
       bool no_add_attrs = 0;
       int i;
 
-      for (i = 0;
-	   i < ((int) (sizeof (attribute_tables)
-		       / sizeof (attribute_tables[0])));
-	   i++)
+      for (i = 0; i < ARRAY_SIZE (attribute_tables); i++)
 	{
 	  int j;
 
diff -rup orig/egcc-CVS20020228/gcc/config/i386/i386.c egcc-CVS20020228/gcc/config/i386/i386.c
--- orig/egcc-CVS20020228/gcc/config/i386/i386.c	Tue Feb 26 21:13:55 2002
+++ egcc-CVS20020228/gcc/config/i386/i386.c	Thu Feb 28 22:06:01 2002
@@ -903,7 +903,7 @@ override_options ()
 				      | PTA_3DNOW_A | PTA_SSE},
     };
 
-  int const pta_size = sizeof (processor_alias_table) / sizeof (struct pta);
+  int const pta_size = ARRAY_SIZE (processor_alias_table);
 
 #ifdef SUBTARGET_OVERRIDE_OPTIONS
   SUBTARGET_OVERRIDE_OPTIONS;
@@ -11175,7 +11175,7 @@ ix86_init_mmx_sse_builtins ()
 
   /* Add all builtins that are more or less simple operations on two
      operands.  */
-  for (i = 0, d = bdesc_2arg; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
+  for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
     {
       /* Use one of the operands; the target can have a different mode for
 	 mask-generating compares.  */
@@ -11238,7 +11238,7 @@ ix86_init_mmx_sse_builtins ()
   def_builtin (MASK_MMX, "__builtin_ia32_pmaddwd", v2si_ftype_v4hi_v4hi, IX86_BUILTIN_PMADDWD);
 
   /* comi/ucomi insns.  */
-  for (i = 0, d = bdesc_comi; i < sizeof (bdesc_comi) / sizeof *d; i++, d++)
+  for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
     def_builtin (d->mask, d->name, int_ftype_v4sf_v4sf, d->code);
 
   def_builtin (MASK_MMX, "__builtin_ia32_packsswb", v8qi_ftype_v4hi_v4hi, IX86_BUILTIN_PACKSSWB);
@@ -12019,7 +12019,7 @@ ix86_expand_builtin (exp, target, subtar
       break;
     }
 
-  for (i = 0, d = bdesc_2arg; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
+  for (i = 0, d = bdesc_2arg; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
     if (d->code == fcode)
       {
 	/* Compares are treated specially.  */
@@ -12032,11 +12032,11 @@ ix86_expand_builtin (exp, target, subtar
 	return ix86_expand_binop_builtin (d->icode, arglist, target);
       }
 
-  for (i = 0, d = bdesc_1arg; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
+  for (i = 0, d = bdesc_1arg; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
     if (d->code == fcode)
       return ix86_expand_unop_builtin (d->icode, arglist, target, 0);
 
-  for (i = 0, d = bdesc_comi; i < sizeof (bdesc_comi) / sizeof *d; i++, d++)
+  for (i = 0, d = bdesc_comi; i < ARRAY_SIZE (bdesc_comi); i++, d++)
     if (d->code == fcode)
       return ix86_expand_sse_comi (d, arglist, target);
 
diff -rup orig/egcc-CVS20020228/gcc/config/mips/mips.c egcc-CVS20020228/gcc/config/mips/mips.c
--- orig/egcc-CVS20020228/gcc/config/mips/mips.c	Thu Feb 14 07:30:34 2002
+++ egcc-CVS20020228/gcc/config/mips/mips.c	Thu Feb 28 22:06:01 2002
@@ -9847,7 +9847,7 @@ mips_add_gc_roots ()
   ggc_add_rtx_root (&mips_load_reg2, 1);
   ggc_add_rtx_root (&mips_load_reg3, 1);
   ggc_add_rtx_root (&mips_load_reg4, 1);
-  ggc_add_rtx_root (branch_cmp, sizeof (branch_cmp) / sizeof (rtx));
+  ggc_add_rtx_root (branch_cmp, ARRAY_SIZE (branch_cmp));
   ggc_add_rtx_root (&embedded_pic_fnaddr_rtx, 1);
   ggc_add_rtx_root (&mips16_gp_pseudo_rtx, 1);
 }
diff -rup orig/egcc-CVS20020228/gcc/config/mmix/mmix.c egcc-CVS20020228/gcc/config/mmix/mmix.c
--- orig/egcc-CVS20020228/gcc/config/mmix/mmix.c	Wed Feb 13 00:00:15 2002
+++ egcc-CVS20020228/gcc/config/mmix/mmix.c	Thu Feb 28 22:06:01 2002
@@ -3087,13 +3087,13 @@ mmix_output_condition (stream, x, revers
        {CCmode, cc_signed_convs},
        {DImode, cc_di_convs}};
 
-  unsigned int i;
+  size_t i;
   int j;
 
   enum machine_mode mode = GET_MODE (XEXP (x, 0));
   RTX_CODE cc = GET_CODE (x);
 
-  for (i = 0; i < sizeof (cc_convs)/sizeof(*cc_convs); i++)
+  for (i = 0; i < ARRAY_SIZE (cc_convs); i++)
     {
       if (mode == cc_convs[i].cc_mode)
 	{
diff -rup orig/egcc-CVS20020228/gcc/config/rs6000/rs6000.c egcc-CVS20020228/gcc/config/rs6000/rs6000.c
--- orig/egcc-CVS20020228/gcc/config/rs6000/rs6000.c	Wed Feb 27 07:30:35 2002
+++ egcc-CVS20020228/gcc/config/rs6000/rs6000.c	Thu Feb 28 22:06:01 2002
@@ -410,7 +410,7 @@ rs6000_override_options (default_cpu)
 	    MASK_POWERPC | MASK_SOFT_FLOAT | MASK_NEW_MNEMONICS,
 	    POWER_MASKS | POWERPC_OPT_MASKS | MASK_POWERPC64}};
 
-  size_t ptt_size = sizeof (processor_target_table) / sizeof (struct ptt);
+  const size_t ptt_size = ARRAY_SIZE (processor_target_table);
 
   /* Save current -mmultiple/-mno-multiple status.  */
   int multiple = TARGET_MULTIPLE;
@@ -4018,7 +4018,7 @@ altivec_expand_builtin (exp, target)
 
   /* Handle DST variants.  */
   d = (struct builtin_description *) bdesc_dst;
-  for (i = 0; i < sizeof (bdesc_dst) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
     if (d->code == fcode)
       {
 	arg0 = TREE_VALUE (arglist);
@@ -4057,25 +4057,25 @@ altivec_expand_builtin (exp, target)
 
   /* Expand abs* operations.  */
   d = (struct builtin_description *) bdesc_abs;
-  for (i = 0; i < sizeof (bdesc_abs) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
     if (d->code == fcode)
       return altivec_expand_abs_builtin (d->icode, arglist, target);
 
   /* Handle simple unary operations.  */
   d = (struct builtin_description *) bdesc_1arg;
-  for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
     if (d->code == fcode)
       return altivec_expand_unop_builtin (d->icode, arglist, target);
 
   /* Handle simple binary operations.  */
   d = (struct builtin_description *) bdesc_2arg;
-  for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
     if (d->code == fcode)
       return altivec_expand_binop_builtin (d->icode, arglist, target);
 
   /* Expand the AltiVec predicates.  */
   dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
-  for (i = 0; i < sizeof (bdesc_altivec_preds) / sizeof *dp; i++, dp++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
     if (dp->code == fcode)
       return altivec_expand_predicate_builtin (dp->icode, dp->opcode, arglist, target);
 
@@ -4110,7 +4110,7 @@ altivec_expand_builtin (exp, target)
 
   /* Handle simple ternary operations.  */
   d = (struct builtin_description *) bdesc_3arg;
-  for (i = 0; i < sizeof  (bdesc_3arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE  (bdesc_3arg); i++, d++)
     if (d->code == fcode)
       return altivec_expand_ternop_builtin (d->icode, arglist, target);
 
@@ -4606,7 +4606,7 @@ altivec_init_builtins (void)
 
   /* Add the simple ternary operators.  */
   d = (struct builtin_description *) bdesc_3arg;
-  for (i = 0; i < sizeof (bdesc_3arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_3arg); i++, d++)
     {
       
       enum machine_mode mode0, mode1, mode2, mode3;
@@ -4699,12 +4699,12 @@ altivec_init_builtins (void)
 
   /* Add the DST variants.  */
   d = (struct builtin_description *) bdesc_dst;
-  for (i = 0; i < sizeof (bdesc_dst) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_dst); i++, d++)
     def_builtin (d->mask, d->name, void_ftype_pvoid_int_char, d->code);
 
   /* Initialize the predicates.  */
   dp = (struct builtin_description_predicates *) bdesc_altivec_preds;
-  for (i = 0; i < sizeof (bdesc_altivec_preds) / sizeof *dp; i++, dp++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_altivec_preds); i++, dp++)
     {
       enum machine_mode mode1;
       tree type;
@@ -4734,7 +4734,7 @@ altivec_init_builtins (void)
 
   /* Add the simple binary operators.  */
   d = (struct builtin_description *) bdesc_2arg;
-  for (i = 0; i < sizeof (bdesc_2arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_2arg); i++, d++)
     {
       enum machine_mode mode0, mode1, mode2;
       tree type;
@@ -4852,7 +4852,7 @@ altivec_init_builtins (void)
 
   /* Initialize the abs* operators.  */
   d = (struct builtin_description *) bdesc_abs;
-  for (i = 0; i < sizeof (bdesc_abs) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_abs); i++, d++)
     {
       enum machine_mode mode0;
       tree type;
@@ -4882,7 +4882,7 @@ altivec_init_builtins (void)
 
   /* Add the simple unary operators.  */
   d = (struct builtin_description *) bdesc_1arg;
-  for (i = 0; i < sizeof (bdesc_1arg) / sizeof *d; i++, d++)
+  for (i = 0; i < ARRAY_SIZE (bdesc_1arg); i++, d++)
     {
       enum machine_mode mode0, mode1;
       tree type;
diff -rup orig/egcc-CVS20020228/gcc/config/sparc/sparc.c egcc-CVS20020228/gcc/config/sparc/sparc.c
--- orig/egcc-CVS20020228/gcc/config/sparc/sparc.c	Thu Feb 28 15:41:45 2002
+++ egcc-CVS20020228/gcc/config/sparc/sparc.c	Thu Feb 28 22:06:01 2002
@@ -8464,7 +8464,7 @@ mark_ultrasparc_pipeline_state (arg)
   size_t i;
 
   ups = (struct ultrasparc_pipeline_state *) arg;
-  for (i = 0; i < sizeof (ups->group) / sizeof (rtx); ++i)
+  for (i = 0; i < ARRAY_SIZE (ups->group); ++i)
     ggc_mark_rtx (ups->group[i]);
 }
 
diff -rup orig/egcc-CVS20020228/gcc/ada/utils.c egcc-CVS20020228/gcc/ada/utils.c
--- orig/egcc-CVS20020228/gcc/ada/utils.c	Mon Dec 24 00:02:07 2001
+++ egcc-CVS20020228/gcc/ada/utils.c	Thu Feb 28 22:06:01 2002
@@ -165,7 +165,7 @@ init_gnat_to_gnu ()
   ggc_add_tree_root (&signed_and_unsigned_types[0][0],
 		     (sizeof signed_and_unsigned_types
 		      / sizeof signed_and_unsigned_types[0][0]));
-  ggc_add_tree_root (float_types, sizeof float_types / sizeof float_types[0]);
+  ggc_add_tree_root (float_types, ARRAY_SIZE (float_types));
 
   ggc_add_root (&current_binding_level, 1, sizeof current_binding_level,
 		mark_binding_level);
@@ -692,8 +692,7 @@ init_gigi_decls (long_long_float_type, e
   DECL_BUILT_IN_CLASS (setjmp_decl) = BUILT_IN_NORMAL;
   DECL_FUNCTION_CODE (setjmp_decl) = BUILT_IN_SETJMP;
 
-  ggc_add_tree_root (gnat_std_decls,
-		     sizeof gnat_std_decls / sizeof gnat_std_decls[0]);
+  ggc_add_tree_root (gnat_std_decls, ARRAY_SIZE (gnat_std_decls));
 }
 
 /* This routine is called in tree.c to print an error message for invalid use
diff -rup orig/egcc-CVS20020228/gcc/cp/decl.c egcc-CVS20020228/gcc/cp/decl.c
--- orig/egcc-CVS20020228/gcc/cp/decl.c	Thu Feb 28 15:41:47 2002
+++ egcc-CVS20020228/gcc/cp/decl.c	Thu Feb 28 22:06:01 2002
@@ -6610,8 +6610,8 @@ cxx_init_decl_processing ()
     flag_const_strings = 0;
 
   /* Add GC roots for all of our global variables.  */
-  ggc_add_tree_root (c_global_trees, sizeof c_global_trees / sizeof(tree));
-  ggc_add_tree_root (cp_global_trees, sizeof cp_global_trees / sizeof(tree));
+  ggc_add_tree_root (c_global_trees, ARRAY_SIZE (c_global_trees));
+  ggc_add_tree_root (cp_global_trees, ARRAY_SIZE (cp_global_trees));
   ggc_add_tree_root (&integer_three_node, 1);
   ggc_add_tree_root (&integer_two_node, 1);
   ggc_add_tree_root (&signed_size_zero_node, 1);
diff -rup orig/egcc-CVS20020228/gcc/cp/decl2.c egcc-CVS20020228/gcc/cp/decl2.c
--- orig/egcc-CVS20020228/gcc/cp/decl2.c	Wed Feb 27 16:30:50 2002
+++ egcc-CVS20020228/gcc/cp/decl2.c	Thu Feb 28 22:06:01 2002
@@ -514,8 +514,7 @@ cxx_decode_option (argc, argv)
 	 caller that the option was processed successfully.  */
       if (bsearch (&positive_option, 
 		   unsupported_options, 
-		   (sizeof (unsupported_options) 
-		    / sizeof (unsupported_options[0])),
+		   ARRAY_SIZE (unsupported_options),
 		   sizeof (unsupported_options[0]),
 		   compare_options))
 	{
@@ -560,10 +559,7 @@ cxx_decode_option (argc, argv)
 	{
 	  int found = 0;
 
-	  for (j = 0;
-	       !found && j < (sizeof (lang_f_options) 
-			      / sizeof (lang_f_options[0]));
-	       j++)
+	  for (j = 0; !found && j < ARRAY_SIZE (lang_f_options); j++)
 	    {
 	      if (!strcmp (p, lang_f_options[j].string))
 		{
diff -rup orig/egcc-CVS20020228/gcc/cp/lex.c egcc-CVS20020228/gcc/cp/lex.c
--- orig/egcc-CVS20020228/gcc/cp/lex.c	Thu Feb 28 07:38:42 2002
+++ egcc-CVS20020228/gcc/cp/lex.c	Thu Feb 28 22:06:01 2002
@@ -484,7 +484,6 @@ static const struct resword reswords[] =
   { "xor_eq",		RID_XOR_EQ,	D_OPNAME },
 
 };
-#define N_reswords (sizeof reswords / sizeof (struct resword))
 
 /* Table mapping from RID_* constants to yacc token numbers.
    Unfortunately we have to have entries for all the keywords in all
@@ -639,7 +638,7 @@ init_reswords ()
      all the trees it points to are permanently interned in the
      get_identifier hash anyway.  */
   ridpointers = (tree *) xcalloc ((int) RID_MAX, sizeof (tree));
-  for (i = 0; i < N_reswords; i++)
+  for (i = 0; i < ARRAY_SIZE (reswords); i++)
     {
       id = get_identifier (reswords[i].word);
       C_RID_CODE (id) = reswords[i].rid;
@@ -812,8 +811,8 @@ static int *reduce_count;
 int *token_count;
 
 #if 0
-#define REDUCE_LENGTH (sizeof (yyr2) / sizeof (yyr2[0]))
-#define TOKEN_LENGTH (256 + sizeof (yytname) / sizeof (yytname[0]))
+#define REDUCE_LENGTH ARRAY_SIZE (yyr2)
+#define TOKEN_LENGTH (256 + ARRAY_SIZE (yytname))
 #endif
 
 #ifdef GATHER_STATISTICS
diff -rup orig/egcc-CVS20020228/gcc/cppexp.c egcc-CVS20020228/gcc/cppexp.c
--- orig/egcc-CVS20020228/gcc/cppexp.c	Wed Feb 27 16:30:35 2002
+++ egcc-CVS20020228/gcc/cppexp.c	Thu Feb 28 22:06:01 2002
@@ -83,7 +83,6 @@ static const struct suffix vsuf_3[] = {
   { "ull", 1, 2 }, { "ULL", 1, 2 }, { "uLL", 1, 2 }, { "Ull", 1, 2 },
   { "llu", 1, 2 }, { "LLU", 1, 2 }, { "LLu", 1, 2 }, { "llU", 1, 2 }
 };
-#define Nsuff(tab) (sizeof tab / sizeof (struct suffix))
 
 /* Parse and convert what is presumably an integer in TOK.  Accepts
    decimal, hex, or octal with or without size suffixes.  Returned op
@@ -157,9 +156,9 @@ parse_number (pfile, tok)
 	 See the suffix tables, above.  */
       switch (end - p)
 	{
-	case 1: sufftab = vsuf_1; nsuff = Nsuff(vsuf_1); break;
-	case 2: sufftab = vsuf_2; nsuff = Nsuff(vsuf_2); break;
-	case 3: sufftab = vsuf_3; nsuff = Nsuff(vsuf_3); break;
+	case 1: sufftab = vsuf_1; nsuff = ARRAY_SIZE (vsuf_1); break;
+	case 2: sufftab = vsuf_2; nsuff = ARRAY_SIZE (vsuf_2); break;
+	case 3: sufftab = vsuf_3; nsuff = ARRAY_SIZE (vsuf_3); break;
 	default: goto invalid_suffix;
 	}
 
diff -rup orig/egcc-CVS20020228/gcc/cppinit.c egcc-CVS20020228/gcc/cppinit.c
--- orig/egcc-CVS20020228/gcc/cppinit.c	Sat Feb 23 16:30:15 2002
+++ egcc-CVS20020228/gcc/cppinit.c	Thu Feb 28 22:06:01 2002
@@ -690,8 +690,7 @@ static const struct builtin builtin_arra
 #undef C
 #undef X
 #undef O
-#define builtin_array_end \
- builtin_array + sizeof(builtin_array)/sizeof(struct builtin)
+#define builtin_array_end (builtin_array + ARRAY_SIZE (builtin_array))
 
 /* Subroutine of cpp_read_main_file; reads the builtins table above and
    enters them, and language-specific macros, into the hash table.  */
diff -rup orig/egcc-CVS20020228/gcc/gcc.c egcc-CVS20020228/gcc/gcc.c
--- orig/egcc-CVS20020228/gcc/gcc.c	Thu Feb 28 21:31:17 2002
+++ egcc-CVS20020228/gcc/gcc.c	Thu Feb 28 22:06:01 2002
@@ -858,8 +858,7 @@ static const struct compiler default_com
 
 /* Number of elements in default_compilers, not counting the terminator.  */
 
-static int n_default_compilers
-  = (sizeof default_compilers / sizeof (struct compiler)) - 1;
+static const int n_default_compilers = ARRAY_SIZE (default_compilers) - 1;
 
 /* A vector of options to give to the linker.
    These options are accumulated by %x,
@@ -3685,8 +3684,7 @@ warranty; not even for MERCHANTABILITY o
 #ifdef MODIFY_TARGET_NAME
 	      is_modify_target_name = 0;
 
-	      for (j = 0;
-		   j < sizeof modify_target / sizeof modify_target[0]; j++)
+	      for (j = 0; j < ARRAY_SIZE (modify_target); j++)
 		if (! strcmp (argv[i], modify_target[j].sw))
 		  {
 		    char *new_name
@@ -3821,7 +3819,7 @@ warranty; not even for MERCHANTABILITY o
 #ifdef MODIFY_TARGET_NAME
       is_modify_target_name = 0;
 
-      for (j = 0; j < sizeof modify_target / sizeof modify_target[0]; j++)
+      for (j = 0; j < ARRAY_SIZE (modify_target); j++)
 	if (! strcmp (argv[i], modify_target[j].sw))
 	  is_modify_target_name = 1;
 
diff -rup orig/egcc-CVS20020228/gcc/genpreds.c egcc-CVS20020228/gcc/genpreds.c
--- orig/egcc-CVS20020228/gcc/genpreds.c	Sun Oct  7 12:27:04 2001
+++ egcc-CVS20020228/gcc/genpreds.c	Thu Feb 28 22:06:01 2002
@@ -43,7 +43,7 @@ output_predicate_decls ()
   size_t i;
 
   puts ("#ifdef RTX_CODE\n");
-  for (i = 0; i < sizeof predicate / sizeof *predicate; i++)
+  for (i = 0; i < ARRAY_SIZE (predicate); i++)
     printf ("extern int %s PARAMS ((rtx, enum machine_mode));\n",
 	    predicate[i].name);
   puts ("\n#endif /* RTX_CODE */\n");
diff -rup orig/egcc-CVS20020228/gcc/ggc-page.c egcc-CVS20020228/gcc/ggc-page.c
--- orig/egcc-CVS20020228/gcc/ggc-page.c	Sun Jan  6 07:30:31 2002
+++ egcc-CVS20020228/gcc/ggc-page.c	Thu Feb 28 22:06:01 2002
@@ -161,8 +161,7 @@ Software Foundation, 59 Temple Place - S
 /* The number of extra orders, not corresponding to power-of-two sized
    objects.  */
 
-#define NUM_EXTRA_ORDERS \
-  (sizeof (extra_order_size_table) / sizeof (extra_order_size_table[0]))
+#define NUM_EXTRA_ORDERS ARRAY_SIZE (extra_order_size_table)
 
 /* The Ith entry is the maximum size of an object to be stored in the
    Ith extra order.  Adding a new entry to this array is the *only*
diff -rup orig/egcc-CVS20020228/gcc/java/class.c egcc-CVS20020228/gcc/java/class.c
--- orig/egcc-CVS20020228/gcc/java/class.c	Sat Feb 23 07:30:52 2002
+++ egcc-CVS20020228/gcc/java/class.c	Thu Feb 28 22:06:01 2002
@@ -2325,7 +2325,7 @@ init_class_processing ()
   registerClass_libfunc = gen_rtx (SYMBOL_REF, Pmode, "_Jv_RegisterClass");
   registerResource_libfunc = 
     gen_rtx (SYMBOL_REF, Pmode, "_Jv_RegisterResource");
-  ggc_add_tree_root (class_roots, sizeof (class_roots) / sizeof (tree));
+  ggc_add_tree_root (class_roots, ARRAY_SIZE (class_roots));
   fields_ident = get_identifier ("fields");
   info_ident = get_identifier ("info");
   ggc_add_rtx_root (&registerClass_libfunc, 1);
diff -rup orig/egcc-CVS20020228/gcc/java/decl.c egcc-CVS20020228/gcc/java/decl.c
--- orig/egcc-CVS20020228/gcc/java/decl.c	Thu Feb 28 07:39:17 2002
+++ egcc-CVS20020228/gcc/java/decl.c	Thu Feb 28 22:06:01 2002
@@ -907,8 +907,7 @@ java_init_decl_processing ()
   init_jcf_parse ();
 
   /* Register nodes with the garbage collector.  */
-  ggc_add_tree_root (java_global_trees, 
-		     sizeof (java_global_trees) / sizeof (tree));
+  ggc_add_tree_root (java_global_trees, ARRAY_SIZE (java_global_trees));
   ggc_add_tree_root (&decl_map, 1);
   ggc_add_tree_root (&pending_local_decls, 1);
 
diff -rup orig/egcc-CVS20020228/gcc/java/jcf-parse.c egcc-CVS20020228/gcc/java/jcf-parse.c
--- orig/egcc-CVS20020228/gcc/java/jcf-parse.c	Sun Feb  3 07:30:27 2002
+++ egcc-CVS20020228/gcc/java/jcf-parse.c	Thu Feb 28 22:06:01 2002
@@ -1326,7 +1326,7 @@ void
 init_jcf_parse ()
 {
   /* Register roots with the garbage collector.  */
-  ggc_add_tree_root (parse_roots, sizeof (parse_roots) / sizeof(tree));
+  ggc_add_tree_root (parse_roots, ARRAY_SIZE (parse_roots));
 
   ggc_add_root (&current_jcf, 1, sizeof (JCF), (void (*)(void *))ggc_mark_jcf);
 
diff -rup orig/egcc-CVS20020228/gcc/java/parse.y egcc-CVS20020228/gcc/java/parse.y
--- orig/egcc-CVS20020228/gcc/java/parse.y	Thu Feb 28 07:39:22 2002
+++ egcc-CVS20020228/gcc/java/parse.y	Thu Feb 28 22:06:01 2002
@@ -15973,7 +15973,7 @@ void
 init_src_parse ()
 {
   /* Register roots with the garbage collector.  */
-  ggc_add_tree_root (src_parse_roots, sizeof (src_parse_roots) / sizeof(tree));
+  ggc_add_tree_root (src_parse_roots, ARRAY_SIZE (src_parse_roots));
 }
 
 
diff -rup orig/egcc-CVS20020228/gcc/lcm.c egcc-CVS20020228/gcc/lcm.c
--- orig/egcc-CVS20020228/gcc/lcm.c	Thu Feb 28 07:33:22 2002
+++ egcc-CVS20020228/gcc/lcm.c	Thu Feb 28 22:06:01 2002
@@ -1023,7 +1023,7 @@ optimize_mode_switching (file)
   sbitmap *kill;
   struct edge_list *edge_list;
   static const int num_modes[] = NUM_MODES_FOR_MODE_SWITCHING;
-#define N_ENTITIES (sizeof num_modes / sizeof (int))
+#define N_ENTITIES ARRAY_SIZE (num_modes)
   int entity_map[N_ENTITIES];
   struct bb_info *bb_info[N_ENTITIES];
   int i, j;
diff -rup orig/egcc-CVS20020228/gcc/stor-layout.c egcc-CVS20020228/gcc/stor-layout.c
--- orig/egcc-CVS20020228/gcc/stor-layout.c	Tue Feb  5 16:30:27 2002
+++ egcc-CVS20020228/gcc/stor-layout.c	Thu Feb 28 22:06:01 2002
@@ -1816,8 +1816,7 @@ set_sizetype (type)
       TYPE_REFERENCE_TO (sizetype_tab[i]) = 0;
     }
 
-  ggc_add_tree_root ((tree *) &sizetype_tab,
-		     sizeof sizetype_tab / sizeof (tree));
+  ggc_add_tree_root ((tree *) &sizetype_tab, ARRAY_SIZE (sizetype_tab));
 
   /* Go down each of the types we already made and set the proper type
      for the sizes in them.  */



More information about the Gcc-patches mailing list