This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Patch to use ARRAY_SIZE in more places
- From: "Kaveh R. Ghazi" <ghazi at caip dot rutgers dot edu>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 9 Jul 2003 21:53:18 -0400 (EDT)
- Subject: Patch to use ARRAY_SIZE in more places
This patch uses the more readable ARRAY_SIZE macro in a few places
where explicit sizeof/sizeof calculations crept in since my last
sweep.
Tested via building cc1 in cross-compilers targetted to:
arm-unknown-linux-gnu frv-unknown-elf sh-unknown-linux-gnu
and ensuring that no new warnings arose from <cpu>.o.
I also configured with --enable-languages=treelang, linked `tree1' and
ensured treetree.o compiled without incident.
Ok for mainline?
Thanks,
--Kaveh
2003-07-09 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* config/arm/arm.c (arm_init_iwmmxt_builtins, arm_expand_builtin):
Use ARRAY_SIZE.
* config/frv/frv.c (frv_expand_builtin): Likewise.
* config/sh/sh.c (sh_media_init_builtins): Likewise.
treelang:
* treetree.c (N_reswords): Delete.
(treelang_init_decl_processing): Use ARRAY_SIZE.
diff -rup orig/egcc-CVS20030709/gcc/config/arm/arm.c egcc-CVS20030709/gcc/config/arm/arm.c
--- orig/egcc-CVS20030709/gcc/config/arm/arm.c Tue Jul 1 20:01:45 2003
+++ egcc-CVS20030709/gcc/config/arm/arm.c Wed Jul 9 19:47:30 2003
@@ -10715,7 +10715,7 @@ arm_init_iwmmxt_builtins (void)
/* 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. */
@@ -11155,11 +11155,11 @@ arm_expand_builtin (tree exp,
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 == (const enum arm_builtins) fcode)
return arm_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 == (const enum arm_builtins) fcode)
return arm_expand_unop_builtin (d->icode, arglist, target, 0);
diff -rup orig/egcc-CVS20030709/gcc/config/frv/frv.c egcc-CVS20030709/gcc/config/frv/frv.c
--- orig/egcc-CVS20030709/gcc/config/frv/frv.c Sat Jun 28 20:01:14 2003
+++ egcc-CVS20030709/gcc/config/frv/frv.c Wed Jul 9 19:43:49 2003
@@ -9649,53 +9649,38 @@ frv_expand_builtin (exp, target, subtarg
/* Expand groups of builtins. */
- for (i = 0, d = bdesc_set; i < sizeof (bdesc_set) / sizeof *d; i++, d++)
+ for (i = 0, d = bdesc_set; i < ARRAY_SIZE (bdesc_set); i++, d++)
if (d->code == fcode)
return frv_expand_set_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 frv_expand_unop_builtin (d->icode, arglist, target);
- 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)
return frv_expand_binop_builtin (d->icode, arglist, target);
- for (i = 0, d = bdesc_cut; i < sizeof (bdesc_cut) / sizeof *d; i++, d++)
+ for (i = 0, d = bdesc_cut; i < ARRAY_SIZE (bdesc_cut); i++, d++)
if (d->code == fcode)
return frv_expand_cut_builtin (d->icode, arglist, target);
- for (i = 0, d = bdesc_2argimm;
- i < sizeof (bdesc_2argimm) / sizeof *d;
- i++, d++)
- {
- if (d->code == fcode)
- return frv_expand_binopimm_builtin (d->icode, arglist, target);
- }
-
- for (i = 0, d = bdesc_void2arg;
- i < sizeof (bdesc_void2arg) / sizeof *d;
- i++, d++)
- {
- if (d->code == fcode)
- return frv_expand_voidbinop_builtin (d->icode, arglist);
- }
-
- for (i = 0, d = bdesc_void3arg;
- i < sizeof (bdesc_void3arg) / sizeof *d;
- i++, d++)
- {
- if (d->code == fcode)
- return frv_expand_voidtriop_builtin (d->icode, arglist);
- }
-
- for (i = 0, d = bdesc_voidacc;
- i < sizeof (bdesc_voidacc) / sizeof *d;
- i++, d++)
- {
- if (d->code == fcode)
- return frv_expand_voidaccop_builtin (d->icode, arglist);
- }
+ for (i = 0, d = bdesc_2argimm; i < ARRAY_SIZE (bdesc_2argimm); i++, d++)
+ if (d->code == fcode)
+ return frv_expand_binopimm_builtin (d->icode, arglist, target);
+
+ for (i = 0, d = bdesc_void2arg; i < ARRAY_SIZE (bdesc_void2arg); i++, d++)
+ if (d->code == fcode)
+ return frv_expand_voidbinop_builtin (d->icode, arglist);
+
+ for (i = 0, d = bdesc_void3arg; i < ARRAY_SIZE (bdesc_void3arg); i++, d++)
+ if (d->code == fcode)
+ return frv_expand_voidtriop_builtin (d->icode, arglist);
+
+ for (i = 0, d = bdesc_voidacc; i < ARRAY_SIZE (bdesc_voidacc); i++, d++)
+ if (d->code == fcode)
+ return frv_expand_voidaccop_builtin (d->icode, arglist);
+
return 0;
}
diff -rup orig/egcc-CVS20030709/gcc/config/sh/sh.c egcc-CVS20030709/gcc/config/sh/sh.c
--- orig/egcc-CVS20030709/gcc/config/sh/sh.c Thu Jul 3 13:51:55 2003
+++ egcc-CVS20030709/gcc/config/sh/sh.c Wed Jul 9 19:34:08 2003
@@ -8226,7 +8226,7 @@ sh_media_init_builtins ()
const struct builtin_description *d;
memset (shared, 0, sizeof shared);
- for (d = bdesc; d - bdesc < (int) (sizeof bdesc / sizeof bdesc[0]); d++)
+ for (d = bdesc; d - bdesc < (int) ARRAY_SIZE (bdesc); d++)
{
tree type, arg_type;
int signature = d->signature;
diff -rup orig/egcc-CVS20030709/gcc/treelang/treetree.c egcc-CVS20030709/gcc/treelang/treetree.c
--- orig/egcc-CVS20030709/gcc/treelang/treetree.c Mon Jul 7 14:09:53 2003
+++ egcc-CVS20030709/gcc/treelang/treetree.c Wed Jul 9 19:36:41 2003
@@ -1223,7 +1223,6 @@ static const struct resword reswords[] =
{ "volatile", RID_VOLATILE, 0 },
{ "while", RID_WHILE, 0 },
};
-#define N_reswords (sizeof reswords / sizeof (struct resword))
/* Init enough to allow the C decl code to work, then clean up
afterwards. */
@@ -1236,7 +1235,7 @@ treelang_init_decl_processing ()
ridpointers = (tree *) ggc_calloc ((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;