public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE.
@ 2022-05-04 12:31 Martin Liska
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Liska @ 2022-05-04 12:31 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:97d5320a22374064633bcc76d673d32572b87b2c

commit 97d5320a22374064633bcc76d673d32572b87b2c
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 13 18:46:26 2022 +0100

    Use more ARRAY_SIZE.
    
    gcc/ada/ChangeLog:
    
            * locales.c (iso_639_1_to_639_3): Use ARRAY_SIZE.
            (language_name_to_639_3): Likewise.
            (country_name_to_3166): Likewise.
    
    gcc/analyzer/ChangeLog:
    
            * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
            * function-set.cc (test_stdio_example): Likewise.
            * sm-file.cc (get_file_using_fns): Likewise.
            * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
            * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
    
    gcc/ChangeLog:
    
            * attribs.cc (diag_attr_exclusions): Use ARRAY_SIZE.
            (decls_mismatched_attributes): Likewise.
            * builtins.cc (c_strlen): Likewise.
            * cfg.cc (DEF_BASIC_BLOCK_FLAG): Likewise.
            * common/config/aarch64/aarch64-common.cc (aarch64_option_init_struct): Likewise.
            * config/aarch64/aarch64-builtins.cc (aarch64_lookup_simd_builtin_type): Likewise.
            (aarch64_init_simd_builtin_types): Likewise.
            (aarch64_init_builtin_rsqrt): Likewise.
            * config/aarch64/aarch64.cc (is_madd_op): Likewise.
            * config/arm/arm-builtins.cc (arm_lookup_simd_builtin_type): Likewise.
            (arm_init_simd_builtin_types): Likewise.
            * config/avr/gen-avr-mmcu-texi.cc (mcus[ARRAY_SIZE): Likewise.
            (c_prefix): Likewise.
            (main): Likewise.
            * config/c6x/c6x.cc (N_SAVE_ORDER): Likewise.
            * config/darwin-c.cc (darwin_register_frameworks): Likewise.
            * config/gcn/mkoffload.cc (process_obj): Likewise.
            * config/i386/i386-builtins.cc (get_builtin_code_for_version): Likewise.
            (fold_builtin_cpu): Likewise.
            * config/m32c/m32c.cc (PUSHM_N): Likewise.
            * config/nvptx/mkoffload.cc (process): Likewise.
            * config/rs6000/driver-rs6000.cc (host_detect_local_cpu): Likewise.
            * config/rs6000/rs6000.cc (rs6000_hash_constant): Likewise.
            * config/s390/s390.cc (NR_C_MODES): Likewise.
            * config/tilepro/gen-mul-tables.cc (find_sequences): Likewise.
            (create_insn_code_compression_table): Likewise.
            * config/vms/vms.cc (NBR_CRTL_NAMES): Likewise.
            * diagnostic-format-json.cc (json_from_expanded_location): Likewise.
            * dwarf2out.cc (ARRAY_SIZE): Likewise.
            * genautomata.cc (output_get_cpu_unit_code_func): Likewise.
            * genhooks.cc (emit_documentation): Likewise.
            (emit_init_macros): Likewise.
            * gimple-ssa-sprintf.cc (format_floating): Likewise.
            * gimple-ssa-warn-access.cc (memmodel_name): Likewise.
            * godump.cc (keyword_hash_init): Likewise.
            * hash-table.cc (hash_table_higher_prime_index): Likewise.
            * input.cc (for_each_line_table_case): Likewise.
            * ipa-free-lang-data.cc (free_lang_data): Likewise.
            * ipa-inline.cc (sanitize_attrs_match_for_inline_p): Likewise.
            * optc-save-gen.awk: Likewise.
            * spellcheck.cc (test_metric_conditions): Likewise.
            * sreal.cc (sreal_verify_arithmetics): Likewise.
            (sreal_verify_shifting): Likewise.
            * tree-vect-slp-patterns.cc (sizeof): Likewise.
            (ARRAY_SIZE): Likewise.
            * tree.cc (build_common_tree_nodes): Likewise.
    
    gcc/c-family/ChangeLog:
    
            * c-attribs.cc (handle_access_attribute): Use ARRAY_SIZE.
            * c-common.cc (ARRAY_SIZE): Likewise.
            (c_common_nodes_and_builtins): Likewise.
            * c-format.cc (check_tokens): Likewise.
            (check_plain): Likewise.
            * c-pragma.cc (c_pp_lookup_pragma): Likewise.
            (init_pragma): Likewise.
            * c-warn.cc (warn_parm_array_mismatch): Likewise.
            * known-headers.cc (get_string_macro_hint): Likewise.
            (get_stdlib_header_for_name): Likewise.
    
    gcc/c/ChangeLog:
    
            * c-decl.cc (match_builtin_function_types): Use ARRAY_SIZE.
    
    gcc/cp/ChangeLog:
    
            * module.cc (depset::entity_kind_name): Use ARRAY_SIZE.
            * name-lookup.cc (get_std_name_hint): Likewise.
            * parser.cc (cp_parser_new): Likewise.
    
    gcc/d/ChangeLog:
    
            * longdouble.h: Use ARRAY_SIZE.
    
    gcc/fortran/ChangeLog:
    
            * frontend-passes.cc (gfc_code_walker): Use ARRAY_SIZE.
            * openmp.cc (gfc_match_omp_context_selector_specification): Likewise.
            * trans-intrinsic.cc (conv_intrinsic_ieee_builtin): Likewise.
            * trans-types.cc (gfc_get_array_descr_info): Likewise.
    
    gcc/jit/ChangeLog:
    
            * jit-builtins.cc (find_builtin_by_name): Use ARRAY_SIZE.
            (get_string_for_type_id): Likewise.
            * jit-recording.cc (recording::context::context): Likewise.
    
    gcc/lto/ChangeLog:
    
            * lto-common.cc (lto_resolution_read): Use ARRAY_SIZE.
            * lto-lang.cc (lto_init): Likewise.

Diff:
---
 gcc/ada/locales.c                           |  6 +++---
 gcc/analyzer/engine.cc                      |  2 +-
 gcc/analyzer/function-set.cc                |  2 +-
 gcc/analyzer/sm-file.cc                     |  3 +--
 gcc/analyzer/sm-malloc.cc                   |  3 +--
 gcc/analyzer/sm-signal.cc                   |  3 +--
 gcc/attribs.cc                              |  4 ++--
 gcc/builtins.cc                             |  2 +-
 gcc/c-family/c-attribs.cc                   |  3 +--
 gcc/c-family/c-common.cc                    |  7 ++-----
 gcc/c-family/c-format.cc                    | 12 ++++++------
 gcc/c-family/c-pragma.cc                    |  9 ++++-----
 gcc/c-family/c-warn.cc                      |  2 +-
 gcc/c-family/known-headers.cc               |  5 ++---
 gcc/c/c-decl.cc                             |  8 +++-----
 gcc/cfg.cc                                  |  2 +-
 gcc/common/config/aarch64/aarch64-common.cc |  3 +--
 gcc/config/aarch64/aarch64-builtins.cc      |  6 +++---
 gcc/config/aarch64/aarch64.cc               |  2 +-
 gcc/config/arm/arm-builtins.cc              |  4 ++--
 gcc/config/avr/gen-avr-mmcu-texi.cc         |  6 +++---
 gcc/config/c6x/c6x.cc                       |  2 +-
 gcc/config/darwin-c.cc                      |  2 +-
 gcc/config/gcn/mkoffload.cc                 |  2 +-
 gcc/config/i386/i386-builtins.cc            |  6 ++----
 gcc/config/m32c/m32c.cc                     |  2 +-
 gcc/config/nvptx/mkoffload.cc               |  6 +++---
 gcc/config/rs6000/driver-rs6000.cc          |  2 +-
 gcc/config/rs6000/rs6000.cc                 |  2 +-
 gcc/config/s390/s390.cc                     |  2 +-
 gcc/config/tilepro/gen-mul-tables.cc        |  4 ++--
 gcc/config/vms/vms.cc                       |  2 +-
 gcc/cp/module.cc                            |  2 +-
 gcc/cp/name-lookup.cc                       |  2 +-
 gcc/cp/parser.cc                            |  2 +-
 gcc/d/longdouble.h                          |  2 +-
 gcc/diagnostic-format-json.cc               |  2 +-
 gcc/dwarf2out.cc                            |  3 +--
 gcc/fortran/frontend-passes.cc              |  4 +---
 gcc/fortran/openmp.cc                       |  3 +--
 gcc/fortran/trans-intrinsic.cc              |  2 +-
 gcc/fortran/trans-types.cc                  |  2 +-
 gcc/genautomata.cc                          |  4 ++--
 gcc/genhooks.cc                             |  9 ++++-----
 gcc/gimple-ssa-sprintf.cc                   |  2 +-
 gcc/gimple-ssa-warn-access.cc               |  2 +-
 gcc/godump.cc                               |  2 +-
 gcc/hash-table.cc                           |  2 +-
 gcc/input.cc                                |  3 +--
 gcc/ipa-free-lang-data.cc                   |  4 +---
 gcc/ipa-inline.cc                           |  2 +-
 gcc/jit/jit-builtins.cc                     |  6 ++----
 gcc/jit/jit-recording.cc                    |  4 +---
 gcc/lto/lto-common.cc                       |  3 +--
 gcc/lto/lto-lang.cc                         |  4 +---
 gcc/optc-save-gen.awk                       | 16 ++++++++--------
 gcc/spellcheck.cc                           |  2 +-
 gcc/sreal.cc                                |  4 ++--
 gcc/tree-vect-slp-patterns.cc               |  2 +-
 gcc/tree.cc                                 |  4 +---
 60 files changed, 97 insertions(+), 128 deletions(-)

diff --git a/gcc/ada/locales.c b/gcc/ada/locales.c
index ee1385a6bdc..2aaa2121a50 100644
--- a/gcc/ada/locales.c
+++ b/gcc/ada/locales.c
@@ -649,7 +649,7 @@ str_get_last_byte (char *lc_all) {
 
 static char*
 iso_639_1_to_639_3(char* iso_639_1_code) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -673,7 +673,7 @@ iso_639_1_to_639_3(char* iso_639_1_code) {
 
 static char*
 language_name_to_639_3(char* name) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -695,7 +695,7 @@ language_name_to_639_3(char* name) {
 
 static char*
 country_name_to_3166 (char* name) {
-  int len = sizeof(iso_3166)/sizeof(iso_3166[0]);
+  int len = ARRAY_SIZE (iso_3166);
   char **p = iso_3166;
   int j;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index e43406e3556..9c0c9719fc2 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1139,7 +1139,7 @@ exploded_node::get_dot_fillcolor () const
 	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
 	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
 	   "wheat", "seashell"};
-      const int num_colors = sizeof (colors) / sizeof (colors[0]);
+      const int num_colors = ARRAY_SIZE (colors);
       return colors[total_sm_state % num_colors];
     }
   else
diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc
index 8d9237deb63..be04186ed0d 100644
--- a/gcc/analyzer/function-set.cc
+++ b/gcc/analyzer/function-set.cc
@@ -166,7 +166,7 @@ test_stdio_example ()
     "getwc_unlocked",
     "putc_unlocked"
   };
-  const size_t count = sizeof(example) / sizeof (example[0]);
+  const size_t count = ARRAY_SIZE (example);
   function_set fs (example, count);
   fs.assert_sorted ();
   fs.assert_sane ();
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index ffc2809dc57..3a45e627b35 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -329,8 +329,7 @@ get_file_using_fns ()
     "ungetc",
     "vfprintf"
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
   return fs;
 }
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 4c030803e59..20c1677c498 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -2054,8 +2054,7 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl)
     /* This array must be kept sorted.  */
     "strsep",
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
 
   if (fs.contains_decl_p (fndecl))
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 77044e10805..9b0213e89b7 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -309,8 +309,7 @@ get_async_signal_unsafe_fns ()
     "vsnprintf",
     "vsprintf"
   };
-  const size_t count
-    = sizeof(async_signal_unsafe_fns) / sizeof (async_signal_unsafe_fns[0]);
+  const size_t count = ARRAY_SIZE (async_signal_unsafe_fns);
   function_set fs (async_signal_unsafe_fns, count);
   return fs;
 }
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index b219f878042..6d4a30dc412 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -499,7 +499,7 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
 
   /* Iterate over the mutually exclusive attribute names and verify
      that the symbol doesn't contain it.  */
-  for (unsigned i = 0; i != sizeof attrs / sizeof *attrs; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
     {
       if (!attrs[i])
 	continue;
@@ -2106,7 +2106,7 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
   };
 
   for (unsigned i = 0; i != 2; ++i)
-    for (unsigned j = 0; j != sizeof whitelist / sizeof *whitelist; ++j)
+    for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
       if (lookup_attribute (whitelist[j], tmpl_attrs[i])
 	  || lookup_attribute (whitelist[j], decl_attrs[i]))
 	return 0;
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 5b085e3a14f..2548ce43910 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -613,7 +613,7 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize)
   if (eltsize != tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src)))))
     return NULL_TREE;
 
-  /* Set MAXELTS to sizeof (SRC) / sizeof (*SRC) - 1, the maximum possible
+  /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
      length of SRC.  Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
      in case the latter is less than the size of the array, such as when
      SRC refers to a short string literal used to initialize a large array.
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b1953a45f9b..67a8e3dc965 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -4941,8 +4941,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags,
   int imode;
 
   {
-    const int nmodes =
-      sizeof attr_access::mode_names / sizeof *attr_access::mode_names;
+    const int nmodes = ARRAY_SIZE (attr_access::mode_names);
 
     for (imode = 0; imode != nmodes; ++imode)
       if (!strncmp (ps, attr_access::mode_names[imode],
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 730faa9e87f..ed5d25e5d11 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -602,8 +602,7 @@ const struct c_common_resword c_common_reswords[] =
   { "null_resettable",	RID_NULL_RESETTABLE,	D_OBJC },
 };
 
-const unsigned int num_c_common_reswords =
-  sizeof c_common_reswords / sizeof (struct c_common_resword);
+const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
 
 /* Return identifier for address space AS.  */
 
@@ -4482,9 +4481,7 @@ c_common_nodes_and_builtins (void)
 
   /* Make fileptr_type_node a distinct void * type until
      FILE type is defined.  Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node
       = build_variant_type_copy (builtin_structptr_types[i].base);
 
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 98f28c0dcc6..57dba9b3a6d 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -3195,7 +3195,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
   else
     {
       /* Diagnose some common misspellings.  */
-      for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
+      for (unsigned i = 0; i != ARRAY_SIZE (badwords); ++i)
 	{
 	  unsigned badwlen = strspn (badwords[i].name, " -");
 	  if (wlen >= badwlen
@@ -3390,14 +3390,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISPUNCT (format_chars[0]))
     {
-      size_t nelts = sizeof c_opers / sizeof *c_opers;
+      size_t nelts = ARRAY_SIZE (c_opers);
       if (const char *ret = check_tokens (c_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_opers / sizeof *cxx_opers : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_opers) : 0;
       if (const char *ret = check_tokens (cxx_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3407,14 +3407,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISALPHA (format_chars[0]))
     {
-      size_t nelts = sizeof c_keywords / sizeof *c_keywords;
+      size_t nelts = ARRAY_SIZE (c_keywords);
       if (const char *ret = check_tokens (c_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_keywords / sizeof *cxx_keywords : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_keywords) : 0;
       if (const char *ret = check_tokens (cxx_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3533,7 +3533,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 	  && ISALPHA (format_chars[1]))
 	{
 	  /* Diagnose a subset of contractions that are best avoided.  */
-	  for (unsigned i = 0; i != sizeof contrs / sizeof *contrs; ++i)
+	  for (unsigned i = 0; i != ARRAY_SIZE (contrs); ++i)
 	    {
 	      const char *apos = strchr (contrs[i].name, '\'');
 	      gcc_assert (apos != NULL);
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 4c80bdd26d6..cc05b2580fa 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1400,8 +1400,8 @@ static const struct omp_pragma_def omp_pragmas_simd[] = {
 void
 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
 {
-  const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
-  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+  const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+  const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
   const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
 				 / sizeof (*omp_pragmas);
   int i;
@@ -1576,8 +1576,7 @@ init_pragma (void)
 {
   if (flag_openacc)
     {
-      const int n_oacc_pragmas
-	= sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
+      const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
       int i;
 
       for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1587,7 +1586,7 @@ init_pragma (void)
 
   if (flag_openmp)
     {
-      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+      const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
       int i;
 
       for (i = 0; i < n_omp_pragmas; ++i)
diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc
index f24ac5d0539..cef4dd4ba55 100644
--- a/gcc/c-family/c-warn.cc
+++ b/gcc/c-family/c-warn.cc
@@ -3712,7 +3712,7 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
    to an array and the divisor does not equal the size of the array element.
    For instance:
 
-     sizeof (ARR) / sizeof (OP)
+     ARRAY_SIZE (ARR)
 
    ARR is the array argument of the first sizeof, ARR_TYPE is its ARRAY_TYPE.
    OP1 is the whole second SIZEOF_EXPR, or its argument; TYPE1 is the type
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 8ad3eb3f466..01c86b27dc8 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -79,8 +79,7 @@ get_string_macro_hint (const char *name, enum stdlib lib)
   if ((lib == STDLIB_C && flag_isoc99)
       || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
     {
-      const size_t num_c99_cxx11_macros
-	= sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+      const size_t num_c99_cxx11_macros = ARRAY_SIZE (c99_cxx11_macros);
       for (size_t i = 0; i < num_c99_cxx11_macros; i++)
 	if (strcmp (name, c99_cxx11_macros[i]) == 0)
 	  return lib == STDLIB_C ? "<inttypes.h>" : "<cinttypes>";
@@ -204,7 +203,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
     {"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     if (strcmp (name, hints[i].name) == 0)
       return hints[i].header[lib];
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c701f07befe..e49879ab286 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1658,7 +1658,7 @@ c_bind (location_t loc, tree decl, bool is_global)
    Used only by match_builtin_function_types.  */
 
 static const unsigned builtin_structptr_type_count
-  = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  = ARRAY_SIZE (builtin_structptr_types);
 
 static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
 
@@ -1705,10 +1705,8 @@ match_builtin_function_types (tree newtype, tree oldtype,
   tree newargs = TYPE_ARG_TYPES (newtype);
   tree tryargs = newargs;
 
-  const unsigned nlst
-    = sizeof last_structptr_types / sizeof last_structptr_types[0];
-  const unsigned nbst
-    = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  const unsigned nlst = ARRAY_SIZE (last_structptr_types);
+  const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
 
   gcc_checking_assert (nlst == nbst);
 
diff --git a/gcc/cfg.cc b/gcc/cfg.cc
index da781ba2da8..bbd01ba21bb 100644
--- a/gcc/cfg.cc
+++ b/gcc/cfg.cc
@@ -787,7 +787,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags,
       NULL
 #undef DEF_BASIC_BLOCK_FLAG
     };
-  const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  const unsigned n_bitnames = ARRAY_SIZE (bb_bitnames);
   bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
index dfda5b8372a..7fac90d313b 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -314,8 +314,7 @@ aarch64_option_init_struct (struct gcc_options *opts ATTRIBUTE_UNUSED)
        pop and attribute change (arm_neon headers, lto etc all cause this to
        happen quite frequently).  It is a trade-off between time and space and
        so time won.  */
-    int n_extensions
-      = sizeof (all_extensions) / sizeof (struct aarch64_option_extension);
+    int n_extensions = ARRAY_SIZE (all_extensions);
     qsort (&all_extensions_by_on, n_extensions,
 	   sizeof (struct aarch64_option_extension), opt_ext_cmp);
 }
diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
index c21476d7ae9..e0a741ac663 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -832,7 +832,7 @@ aarch64_lookup_simd_builtin_type (machine_mode mode,
 				  enum aarch64_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -869,7 +869,7 @@ static void
 aarch64_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
@@ -1434,7 +1434,7 @@ aarch64_init_builtin_rsqrt (void)
   };
 
   builtin_decls_data *bdd = bdda;
-  builtin_decls_data *bdd_end = bdd + (sizeof (bdda) / sizeof (builtin_decls_data));
+  builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda));
 
   for (; bdd < bdd_end; bdd++)
   {
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index f650abbc4ce..6f2f5d27ddc 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20755,7 +20755,7 @@ is_madd_op (enum attr_type t1)
     TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
   };
 
-  for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
+  for (i = 0; i < ARRAY_SIZE (mlatypes); i++)
     {
       if (t1 == mlatypes[i])
 	return true;
diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index 36a40a1dc80..d917137e5ee 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -1471,7 +1471,7 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 			      enum arm_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -1503,7 +1503,7 @@ static void
 arm_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
   tree tdecl;
 
   /* Poly types are a world of their own.  In order to maintain legacy
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.cc b/gcc/config/avr/gen-avr-mmcu-texi.cc
index d9c3a30877d..dcd1e0d532f 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.cc
+++ b/gcc/config/avr/gen-avr-mmcu-texi.cc
@@ -26,7 +26,7 @@
 #include "avr-devices.cc"
 
 static const avr_mcu_t*
-mcus[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
+mcus[ARRAY_SIZE (avr_mcu_types);
 
 static int letter (char c)
 {
@@ -56,7 +56,7 @@ c_prefix (const char *str)
       "attiny", "atmega", "atxmega", "ata", "at90"
     };
 
-  int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
+  int i, n = (int) (ARRAY_SIZE (prefixes));
 
   for (i = 0; i < n; i++)
     if (str_prefix_p (str, prefixes[i]))
@@ -185,7 +185,7 @@ int main (void)
 	  print_mcus (n_mcus);
 	  n_mcus = 0;
 
-	  for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
+	  for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
 	    if (arch_id == avr_texinfo[i].arch_id)
 	      printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
 	}
diff --git a/gcc/config/c6x/c6x.cc b/gcc/config/c6x/c6x.cc
index 7fe18d69c7f..dc01a6e47c4 100644
--- a/gcc/config/c6x/c6x.cc
+++ b/gcc/config/c6x/c6x.cc
@@ -2580,7 +2580,7 @@ static unsigned reg_save_order[] =
   REG_B14, REG_A15
 };
 
-#define N_SAVE_ORDER (sizeof reg_save_order / sizeof *reg_save_order)
+#define N_SAVE_ORDER (ARRAY_SIZE (reg_save_order))
 
 /* Compute the layout of the stack frame and store it in FRAME.  */
 
diff --git a/gcc/config/darwin-c.cc b/gcc/config/darwin-c.cc
index 3770857aa42..9203c84d2c2 100644
--- a/gcc/config/darwin-c.cc
+++ b/gcc/config/darwin-c.cc
@@ -505,7 +505,7 @@ darwin_register_frameworks (const char *sysroot,
       size_t i;
 
       /* Setup default search path for frameworks.  */
-      for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
+      for (i = 0; i < ARRAY_SIZE (framework_defaults); ++i)
 	{
 	  char *str;
 	  if (sysroot)
diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 94ba7ffa5af..9db2124b129 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -723,7 +723,7 @@ process_obj (FILE *in, FILE *cfile)
 	   "  unsigned global_variable_count;\n"
 	   "} target_data = {\n"
 	   "  &gcn_image,\n"
-	   "  sizeof (gcn_kernels) / sizeof (gcn_kernels[0]),\n"
+	   "  ARRAY_SIZE (gcn_kernels),\n"
 	   "  gcn_kernels,\n"
 	   "  gcn_num_vars\n"
 	   "};\n\n");
diff --git a/gcc/config/i386/i386-builtins.cc b/gcc/config/i386/i386-builtins.cc
index 8c6d0fe9631..0ea0eee5624 100644
--- a/gcc/config/i386/i386-builtins.cc
+++ b/gcc/config/i386/i386-builtins.cc
@@ -1936,8 +1936,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
 
   enum feature_priority priority = P_NONE;
 
-  static unsigned int NUM_FEATURES
-    = sizeof (isa_names_table) / sizeof (_isa_names_table);
+  static unsigned int NUM_FEATURES = ARRAY_SIZE (isa_names_table);
 
   unsigned int i;
 
@@ -2290,8 +2289,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
       tree final;
 
       unsigned int field_val = 0;
-      unsigned int NUM_ISA_NAMES
-	= sizeof (isa_names_table) / sizeof (struct _isa_names_table);
+      unsigned int NUM_ISA_NAMES = ARRAY_SIZE (isa_names_table);
 
       for (i = 0; i < NUM_ISA_NAMES; i++)
 	if (strcmp (isa_names_table[i].name,
diff --git a/gcc/config/m32c/m32c.cc b/gcc/config/m32c/m32c.cc
index 11ca9a43a0b..5a19faa063c 100644
--- a/gcc/config/m32c/m32c.cc
+++ b/gcc/config/m32c/m32c.cc
@@ -1090,7 +1090,7 @@ static struct
   { FB_REGNO, 0x01, 2, 4 }
 };
 
-#define PUSHM_N (sizeof(pushm_info)/sizeof(pushm_info[0]))
+#define PUSHM_N (ARRAY_SIZE (pushm_info))
 
 /* Returns TRUE if we need to save/restore the given register.  We
    save everything for exception handlers, so that any register can be
diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index b28c1a32292..fa3b4b76821 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -316,11 +316,11 @@ process (FILE *in, FILE *out)
 	   "  const struct nvptx_fn *fn_names;\n"
 	   "  unsigned fn_num;\n"
 	   "} target_data = {\n"
-	   "  ptx_objs, sizeof (ptx_objs) / sizeof (ptx_objs[0]),\n"
+	   "  ptx_objs, ARRAY_SIZE (ptx_objs),\n"
 	   "  var_mappings,"
-	   "  sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+	   "  ARRAY_SIZE (var_mappings),\n"
 	   "  func_mappings,"
-	   "  sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+	   "  ARRAY_SIZE (func_mappings)\n"
 	   "};\n\n");
 
   fprintf (out, "#ifdef __cplusplus\n"
diff --git a/gcc/config/rs6000/driver-rs6000.cc b/gcc/config/rs6000/driver-rs6000.cc
index ec890e0db3a..b871f0a36a8 100644
--- a/gcc/config/rs6000/driver-rs6000.cc
+++ b/gcc/config/rs6000/driver-rs6000.cc
@@ -599,7 +599,7 @@ host_detect_local_cpu (int argc, const char **argv)
 
   if (assembler)
     {
-      for (i = 0; i < sizeof (asm_names) / sizeof (asm_names[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (asm_names); i++)
 	{
 	  if (!asm_names[i].cpu || !strcmp (asm_names[i].cpu, cpu))
 	    return asm_names[i].asm_sw;
diff --git a/gcc/config/rs6000/rs6000.cc b/gcc/config/rs6000/rs6000.cc
index bc619592b9e..1ddf9f1532a 100644
--- a/gcc/config/rs6000/rs6000.cc
+++ b/gcc/config/rs6000/rs6000.cc
@@ -16974,7 +16974,7 @@ rs6000_hash_constant (rtx k)
 	else
 	  {
 	    size_t i;
-	    for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++)
+	    for (i = 0; i < ARRAY_SIZE (HOST_WIDE_INT); i++)
 	      result = result * 613 + (unsigned) (XWINT (k, fidx)
 						  >> CHAR_BIT * i);
 	  }
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 7c3bd6cbe7f..90ca50515a7 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -8768,7 +8768,7 @@ static machine_mode constant_modes[] =
   QImode,
   V1QImode
 };
-#define NR_C_MODES (sizeof (constant_modes) / sizeof (constant_modes[0]))
+#define NR_C_MODES (ARRAY_SIZE (constant_modes))
 
 struct constant
 {
diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index c9649fb9c70..798766a723b 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -462,7 +462,7 @@ find_sequences (ExpressionTree &s, ExpressionTreeMap &best_solution)
   const Operator *const prev_op = s.m_exprs[num_vals - 1].m_op;
   const int prev_top_index = (prev_op != NULL) ? prev_op->m_top_index : -1;
 
-  for (size_t f = 0; f < sizeof ops / sizeof ops[0]; f++)
+  for (size_t f = 0; f < ARRAY_SIZE (ops); f++)
     {
       const Operator *const op = &ops[f];
 
@@ -564,7 +564,7 @@ create_insn_code_compression_table ()
   printf ("const enum insn_code %s_multiply_insn_seq_decode_opcode[] = {\n"
 	  "  CODE_FOR_nothing /* must be first */ ", ARCH);
 
-  for (size_t i = 0; i < sizeof ops / sizeof ops[0]; i++)
+  for (size_t i = 0; i < ARRAY_SIZE (ops); i++)
     {
       Operator *op = &ops[i];
       int index = -1;
diff --git a/gcc/config/vms/vms.cc b/gcc/config/vms/vms.cc
index 5d565e35fb4..d0d44bad2ce 100644
--- a/gcc/config/vms/vms.cc
+++ b/gcc/config/vms/vms.cc
@@ -99,7 +99,7 @@ static const struct vms_crtl_name vms_crtl_names[] =
 
 /* Number of entires in the above array.  */
 
-#define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
+#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names))
 
 /* List of aliased identifiers.  They must be persistent across gc.  */
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index cebf9c35c1d..7c722af6960 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2615,7 +2615,7 @@ depset::entity_kind_name () const
     {"decl", "specialization", "partial", "using",
      "namespace", "redirect", "binding"};
   entity_kind kind = get_entity_kind ();
-  gcc_checking_assert (kind < sizeof (names) / sizeof(names[0]));
+  gcc_checking_assert (kind < ARRAY_SIZE (names));
   return names[kind];
 }
 
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7b0638d3166..05f29cebac2 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -6915,7 +6915,7 @@ get_std_name_hint (const char *name)
     /* <vector>.  */
     {"vector", "<vector>", cxx98},
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     {
       if (strcmp (name, hints[i].name) == 0)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index a5cbb3e896f..2c5ab1edf52 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -4200,7 +4200,7 @@ cp_parser_new (cp_lexer *lexer)
 {
   /* Initialize the binops_by_token so that we can get the tree
      directly from the token.  */
-  for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (binops); i++)
     binops_by_token[binops[i].token_type] = binops[i];
 
   cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
diff --git a/gcc/d/longdouble.h b/gcc/d/longdouble.h
index 1e457ae04d6..2d9695a4309 100644
--- a/gcc/d/longdouble.h
+++ b/gcc/d/longdouble.h
@@ -117,7 +117,7 @@ public:
 private:
   /* Including gcc/real.h presents too many problems, so just
      statically allocate enough space for REAL_VALUE_TYPE.  */
-  long realvalue[(2 + (16 + sizeof (long)) / sizeof (long))];
+  long realvalue[(2 + (16 + ARRAY_SIZE (long))];
 };
 
 /* Declared, but "volatile" is not required.  */
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index def371816e6..62594ebb4d7 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -62,7 +62,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
     {"byte-column", DIAGNOSTICS_COLUMN_UNIT_BYTE}
   };
   int the_column = INT_MIN;
-  for (int i = 0; i != sizeof column_fields / sizeof (*column_fields); ++i)
+  for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
     {
       context->column_unit = column_fields[i].unit;
       const int col = diagnostic_converted_column (context, exploc);
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 5681b01749a..4ef644c5fae 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -13532,8 +13532,7 @@ static const dwarf_qual_info_t dwarf_qual_info[] =
   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
 };
-static const unsigned int dwarf_qual_info_size
-  = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
+static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
 
 /* If DIE is a qualified DIE of some base DIE with the same parent,
    return the base DIE, otherwise return NULL.  Set MASK to the
diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 5eba6345145..612c12d233d 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5654,9 +5654,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 		  WALK_SUBEXPR (co->ext.omp_clauses->detach);
 		  for (idx = 0; idx < OMP_IF_LAST; idx++)
 		    WALK_SUBEXPR (co->ext.omp_clauses->if_exprs[idx]);
-		  for (idx = 0;
-		       idx < sizeof (list_types) / sizeof (list_types[0]);
-		       idx++)
+		  for (idx = 0; idx < ARRAY_SIZE (list_types); idx++)
 		    for (n = co->ext.omp_clauses->lists[list_types[idx]];
 			 n; n = n->next)
 		      WALK_SUBEXPR (n->expr);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 714148138c2..5b3d0bd0709 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -4902,8 +4902,7 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
       match m;
       const char *selector_sets[] = { "construct", "device",
 				      "implementation", "user" };
-      const int selector_set_count
-	= sizeof (selector_sets) / sizeof (*selector_sets);
+      const int selector_set_count = ARRAY_SIZE (selector_sets);
       int i;
       char buf[GFC_MAX_SYMBOL_LEN + 1];
 
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 2249723540d..6884060fd6f 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -9784,7 +9784,7 @@ conv_intrinsic_ieee_builtin (gfc_se * se, gfc_expr * expr,
 			     enum built_in_function code, int nargs)
 {
   tree args[2];
-  gcc_assert ((unsigned) nargs <= sizeof(args)/sizeof(args[0]));
+  gcc_assert ((unsigned) nargs <= ARRAY_SIZE (args));
 
   conv_ieee_function_args (se, expr, args, nargs);
   se->expr = build_call_expr_loc_array (input_location,
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 3cdc529eb28..3742bf312cd 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3420,7 +3420,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
     }
 
   rank = GFC_TYPE_ARRAY_RANK (type);
-  if (rank >= (int) (sizeof (info->dimen) / sizeof (info->dimen[0])))
+  if (rank >= (int) (ARRAY_SIZE (info->dimen)))
     return false;
 
   etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
diff --git a/gcc/genautomata.cc b/gcc/genautomata.cc
index e43314e4ea3..2d5bacf7bb8 100644
--- a/gcc/genautomata.cc
+++ b/gcc/genautomata.cc
@@ -8623,8 +8623,8 @@ output_get_cpu_unit_code_func (void)
   fprintf (output_file, "    };\n\n");
   fprintf (output_file, "  /* The following is binary search: */\n");
   fprintf (output_file, "  %s = 0;\n", LOW_VARIABLE_NAME);
-  fprintf (output_file, "  %s = sizeof (%s) / sizeof (struct %s) - 1;\n",
-	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME, NAME_CODE_STRUCT_NAME);
+  fprintf (output_file, "  %s = ARRAY_SIZE (%s) - 1;\n",
+	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME);
   fprintf (output_file, "  while (%s <= %s)\n    {\n",
 	   LOW_VARIABLE_NAME, HIGH_VARIABLE_NAME);
   fprintf (output_file, "      %s = (%s + %s) / 2;\n",
diff --git a/gcc/genhooks.cc b/gcc/genhooks.cc
index 20ad607b158..6bae85d7b8d 100644
--- a/gcc/genhooks.cc
+++ b/gcc/genhooks.cc
@@ -128,7 +128,7 @@ emit_documentation (const char *in_fname)
     }
   fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
     {
       struct s_hook sh, *shp;
       void *p;
@@ -223,7 +223,7 @@ emit_documentation (const char *in_fname)
 	      /* POD-valued hooks sometimes come in groups with common
 		 documentation.*/
 	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
+		   j < (int) (ARRAY_SIZE (hook_array))
 		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
 		{
 		  char *namex = upstrdup (hook_array[j].name);
@@ -246,8 +246,7 @@ emit_documentation (const char *in_fname)
 		  printf ("\n@end %s", deftype);
 		}
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
+	  if (++i >= (int) (ARRAY_SIZE (hook_array)) || !hook_array[i].doc)
 	    break;
 	  free (name);
 	  sh.name = name = upstrdup (hook_array[i].name);
@@ -270,7 +269,7 @@ emit_init_macros (const char *docname)
 
   for (print_nest = 0; print_nest <= MAX_NEST; print_nest++)
     {
-      for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+      for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
 	{
 	  char *name = upstrdup (hook_array[i].name);
 
diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc
index 9a84fffed1a..eb05be8c0ed 100644
--- a/gcc/gimple-ssa-sprintf.cc
+++ b/gcc/gimple-ssa-sprintf.cc
@@ -1953,7 +1953,7 @@ format_floating (const directive &dir, tree arg, pointer_query &)
       &res.range.min, &res.range.max
     };
 
-    for (int i = 0; i != sizeof minmax / sizeof *minmax; ++i)
+    for (int i = 0; i != ARRAY_SIZE (minmax); ++i)
       {
 	/* Convert the GCC real value representation with the precision
 	   of the real type to the mpfr_t format rounding down in the
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 39aa8186de6..ec458b0c0d3 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2853,7 +2853,7 @@ memmodel_name (unsigned HOST_WIDE_INT val)
 {
   val = memmodel_base (val);
 
-  for (unsigned i = 0; i != sizeof memory_models / sizeof *memory_models; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (memory_models); ++i)
     {
       if (val == memory_models[i].modval)
 	return memory_models[i].modname;
diff --git a/gcc/godump.cc b/gcc/godump.cc
index 669168806f3..2ae0bcc9672 100644
--- a/gcc/godump.cc
+++ b/gcc/godump.cc
@@ -1326,7 +1326,7 @@ static void
 keyword_hash_init (class godump_container *container)
 {
   size_t i;
-  size_t count = sizeof (keywords) / sizeof (keywords[0]);
+  size_t count = ARRAY_SIZE (keywords);
   void **slot;
 
   for (i = 0; i < count; i++)
diff --git a/gcc/hash-table.cc b/gcc/hash-table.cc
index dad1d21f099..1015c1ee6e9 100644
--- a/gcc/hash-table.cc
+++ b/gcc/hash-table.cc
@@ -84,7 +84,7 @@ unsigned int
 hash_table_higher_prime_index (unsigned long n)
 {
   unsigned int low = 0;
-  unsigned int high = sizeof (prime_tab) / sizeof (prime_tab[0]);
+  unsigned int high = ARRAY_SIZE (prime_tab);
 
   while (low != high)
     {
diff --git a/gcc/input.cc b/gcc/input.cc
index b3970613d81..58beba05072 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -3724,8 +3724,7 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
     {
       /* ...and use each of the "interesting" location values as
 	 the starting location within line_table.  */
-      const int num_boundary_locations
-	= sizeof (boundary_locations) / sizeof (boundary_locations[0]);
+      const int num_boundary_locations = ARRAY_SIZE (boundary_locations);
       for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++)
 	{
 	  line_table_case c (default_range_bits, boundary_locations[loc_idx]);
diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index a742156858c..f99f7be1c58 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -1109,9 +1109,7 @@ free_lang_data (void)
   free_lang_data_in_cgraph (&fld);
 
   /* Create gimple variants for common types.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index f8bb072c422..22a009b7435 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -278,7 +278,7 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
       SANITIZE_POINTER_SUBTRACT
     };
 
-  for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (codes); i++)
     if (sanitize_flags_p (codes[i], caller)
 	!= sanitize_flags_p (codes[i], callee))
       return false;
diff --git a/gcc/jit/jit-builtins.cc b/gcc/jit/jit-builtins.cc
index b949b734332..fb86c77d0fe 100644
--- a/gcc/jit/jit-builtins.cc
+++ b/gcc/jit/jit-builtins.cc
@@ -109,9 +109,7 @@ find_builtin_by_name (const char *in_name,
 
      We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
      has a NULL name.  */
-  for (unsigned int i = 1;
-       i < sizeof (builtin_data) / sizeof (builtin_data[0]);
-       i++)
+  for (unsigned int i = 1; i < ARRAY_SIZE (builtin_data); i++)
     {
       const struct builtin_data& bd = builtin_data[i];
       if (matches_builtin (in_name, bd))
@@ -320,7 +318,7 @@ static const char * const type_names[] = {
 static const char *
 get_string_for_type_id (enum jit_builtin_type type_id)
 {
-  gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0]));
+  gcc_assert (type_id < ARRAY_SIZE (type_names));
   return type_names[type_id];
 }
 
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index a31720f043e..4305a961489 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -568,9 +568,7 @@ recording::context::context (context *parent_ctxt)
   if (parent_ctxt)
     {
       /* Inherit options from parent.  */
-      for (unsigned i = 0;
-	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
-	   i++)
+      for (unsigned i = 0; i < ARRAY_SIZE (m_str_options); i++)
 	{
 	  const char *parent_opt = parent_ctxt->m_str_options[i];
 	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index ca28586a1e8..d8d0404c54e 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2104,8 +2104,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
       char r_str[27];
       enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
       unsigned int j;
-      unsigned int lto_resolution_str_len
-	= sizeof (lto_resolution_str) / sizeof (char *);
+      unsigned int lto_resolution_str_len = ARRAY_SIZE (lto_resolution_str);
       res_pair rp;
 
       t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index 8d58d924dff..972a0336f75 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -1319,9 +1319,7 @@ lto_init (void)
      distinction should only be relevant to the front-end, so we
      always use the C definition here in lto1.
      Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     {
       gcc_assert (builtin_structptr_types[i].node
 		  == builtin_structptr_types[i].base);
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 9911bab6668..233d1fbb637 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1104,7 +1104,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 	print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 	print "      return false;"
 }
@@ -1152,7 +1152,7 @@ for (i = 0; i < n_target_val; i++) {
 	print "  hstate.add_hwi (ptr->" name");";
 }
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 }
 
@@ -1192,7 +1192,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 }
 
@@ -1235,7 +1235,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 }
 
@@ -1317,7 +1317,7 @@ for (i = 0; i < n_opt_val; i++) {
 	else
 		print "  hstate.add_hwi (ptr->" name");";
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 print "  return hstate.end ();";
 print "}";
@@ -1346,7 +1346,7 @@ for (i = 0; i < n_opt_val; i++) {
 		print "    return false;";
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 print "      return false;"
 print "  return true;";
@@ -1380,7 +1380,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 print "}";
 
@@ -1412,7 +1412,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 print "}";
 print "/* Free heap memory used by optimization options  */";
diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc
index 3e58344f510..c7bb0122545 100644
--- a/gcc/spellcheck.cc
+++ b/gcc/spellcheck.cc
@@ -489,7 +489,7 @@ static const char * const test_data[] = {
 static void
 test_metric_conditions ()
 {
-  const int num_test_cases = sizeof (test_data) / sizeof (test_data[0]);
+  const int num_test_cases = ARRAY_SIZE (test_data);
 
   for (int i = 0; i < num_test_cases; i++)
     {
diff --git a/gcc/sreal.cc b/gcc/sreal.cc
index 75c360e3970..7463edf1225 100644
--- a/gcc/sreal.cc
+++ b/gcc/sreal.cc
@@ -323,7 +323,7 @@ static void
 sreal_verify_arithmetics (void)
 {
   int values[] = {-14123413, -7777, -17, -10, -2, 0, 17, 139, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     for (unsigned j = 0; j < c; j++)
@@ -359,7 +359,7 @@ static void
 sreal_verify_shifting (void)
 {
   int values[] = {0, 17, 32, 139, 1024, 55555, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     verify_shifting (values[i]);
diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc
index 879d17fd947..a6b0d106d5f 100644
--- a/gcc/tree-vect-slp-patterns.cc
+++ b/gcc/tree-vect-slp-patterns.cc
@@ -1637,4 +1637,4 @@ vect_pattern_decl_t slp_patterns[]
 #undef SLP_PATTERN
 
 /* Set the number of SLP pattern matchers available.  */
-size_t num__slp_patterns = sizeof(slp_patterns)/sizeof(vect_pattern_decl_t);
+size_t num__slp_patterns = ARRAY_SIZE (slp_patterns);
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 4cf3785270b..69c0de0aaa2 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -9412,9 +9412,7 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE.
@ 2022-05-09 10:54 Martin Liska
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Liska @ 2022-05-09 10:54 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:5ad8fe059d3419446647eadf8785c768b647d15b

commit 5ad8fe059d3419446647eadf8785c768b647d15b
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 13 18:46:26 2022 +0100

    Use more ARRAY_SIZE.
    
    gcc/ada/ChangeLog:
    
            * locales.c (iso_639_1_to_639_3): Use ARRAY_SIZE.
            (language_name_to_639_3): Likewise.
            (country_name_to_3166): Likewise.
    
    gcc/analyzer/ChangeLog:
    
            * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
            * function-set.cc (test_stdio_example): Likewise.
            * sm-file.cc (get_file_using_fns): Likewise.
            * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
            * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
    
    gcc/ChangeLog:
    
            * attribs.cc (diag_attr_exclusions): Use ARRAY_SIZE.
            (decls_mismatched_attributes): Likewise.
            * builtins.cc (c_strlen): Likewise.
            * cfg.cc (DEF_BASIC_BLOCK_FLAG): Likewise.
            * common/config/aarch64/aarch64-common.cc (aarch64_option_init_struct): Likewise.
            * config/aarch64/aarch64-builtins.cc (aarch64_lookup_simd_builtin_type): Likewise.
            (aarch64_init_simd_builtin_types): Likewise.
            (aarch64_init_builtin_rsqrt): Likewise.
            * config/aarch64/aarch64.cc (is_madd_op): Likewise.
            * config/arm/arm-builtins.cc (arm_lookup_simd_builtin_type): Likewise.
            (arm_init_simd_builtin_types): Likewise.
            * config/avr/gen-avr-mmcu-texi.cc (mcus[ARRAY_SIZE): Likewise.
            (c_prefix): Likewise.
            (main): Likewise.
            * config/c6x/c6x.cc (N_SAVE_ORDER): Likewise.
            * config/darwin-c.cc (darwin_register_frameworks): Likewise.
            * config/gcn/mkoffload.cc (process_obj): Likewise.
            * config/i386/i386-builtins.cc (get_builtin_code_for_version): Likewise.
            (fold_builtin_cpu): Likewise.
            * config/m32c/m32c.cc (PUSHM_N): Likewise.
            * config/nvptx/mkoffload.cc (process): Likewise.
            * config/rs6000/driver-rs6000.cc (host_detect_local_cpu): Likewise.
            * config/s390/s390.cc (NR_C_MODES): Likewise.
            * config/tilepro/gen-mul-tables.cc (find_sequences): Likewise.
            (create_insn_code_compression_table): Likewise.
            * config/vms/vms.cc (NBR_CRTL_NAMES): Likewise.
            * diagnostic-format-json.cc (json_from_expanded_location): Likewise.
            * dwarf2out.cc (ARRAY_SIZE): Likewise.
            * genhooks.cc (emit_documentation): Likewise.
            (emit_init_macros): Likewise.
            * gimple-ssa-sprintf.cc (format_floating): Likewise.
            * gimple-ssa-warn-access.cc (memmodel_name): Likewise.
            * godump.cc (keyword_hash_init): Likewise.
            * hash-table.cc (hash_table_higher_prime_index): Likewise.
            * input.cc (for_each_line_table_case): Likewise.
            * ipa-free-lang-data.cc (free_lang_data): Likewise.
            * ipa-inline.cc (sanitize_attrs_match_for_inline_p): Likewise.
            * optc-save-gen.awk: Likewise.
            * spellcheck.cc (test_metric_conditions): Likewise.
            * tree-vect-slp-patterns.cc (sizeof): Likewise.
            (ARRAY_SIZE): Likewise.
            * tree.cc (build_common_tree_nodes): Likewise.
    
    gcc/c-family/ChangeLog:
    
            * c-common.cc (ARRAY_SIZE): Use ARRAY_SIZE.
            (c_common_nodes_and_builtins): Likewise.
            * c-format.cc (check_tokens): Likewise.
            (check_plain): Likewise.
            * c-pragma.cc (c_pp_lookup_pragma): Likewise.
            (init_pragma): Likewise.
            * known-headers.cc (get_string_macro_hint): Likewise.
            (get_stdlib_header_for_name): Likewise.
            * c-attribs.cc: Likewise.
    
    gcc/c/ChangeLog:
    
            * c-decl.cc (match_builtin_function_types): Use ARRAY_SIZE.
    
    gcc/cp/ChangeLog:
    
            * module.cc (depset::entity_kind_name): Use ARRAY_SIZE.
            * name-lookup.cc (get_std_name_hint): Likewise.
            * parser.cc (cp_parser_new): Likewise.
    
    gcc/fortran/ChangeLog:
    
            * frontend-passes.cc (gfc_code_walker): Use ARRAY_SIZE.
            * openmp.cc (gfc_match_omp_context_selector_specification): Likewise.
            * trans-intrinsic.cc (conv_intrinsic_ieee_builtin): Likewise.
            * trans-types.cc (gfc_get_array_descr_info): Likewise.
    
    gcc/jit/ChangeLog:
    
            * jit-builtins.cc (find_builtin_by_name): Use ARRAY_SIZE.
            (get_string_for_type_id): Likewise.
            * jit-recording.cc (recording::context::context): Likewise.
    
    gcc/lto/ChangeLog:
    
            * lto-common.cc (lto_resolution_read): Use ARRAY_SIZE.
            * lto-lang.cc (lto_init): Likewise.

Diff:
---
 gcc/ada/locales.c                           |  8 +++++---
 gcc/analyzer/engine.cc                      |  2 +-
 gcc/analyzer/function-set.cc                |  2 +-
 gcc/analyzer/sm-file.cc                     |  3 +--
 gcc/analyzer/sm-malloc.cc                   |  3 +--
 gcc/analyzer/sm-signal.cc                   |  3 +--
 gcc/attribs.cc                              |  4 ++--
 gcc/builtins.cc                             |  2 +-
 gcc/c-family/c-attribs.cc                   |  3 +--
 gcc/c-family/c-common.cc                    |  7 ++-----
 gcc/c-family/c-format.cc                    | 12 ++++++------
 gcc/c-family/c-pragma.cc                    |  9 ++++-----
 gcc/c-family/known-headers.cc               |  5 ++---
 gcc/c/c-decl.cc                             |  8 +++-----
 gcc/cfg.cc                                  |  2 +-
 gcc/common/config/aarch64/aarch64-common.cc |  3 +--
 gcc/config/aarch64/aarch64-builtins.cc      |  6 +++---
 gcc/config/aarch64/aarch64.cc               |  2 +-
 gcc/config/arm/arm-builtins.cc              |  4 ++--
 gcc/config/avr/gen-avr-mmcu-texi.cc         |  8 +++++---
 gcc/config/c6x/c6x.cc                       |  2 +-
 gcc/config/darwin-c.cc                      |  2 +-
 gcc/config/gcn/mkoffload.cc                 |  2 +-
 gcc/config/i386/i386-builtins.cc            |  6 ++----
 gcc/config/m32c/m32c.cc                     |  2 +-
 gcc/config/nvptx/mkoffload.cc               |  6 +++---
 gcc/config/rs6000/driver-rs6000.cc          |  2 +-
 gcc/config/s390/s390.cc                     |  2 +-
 gcc/config/tilepro/gen-mul-tables.cc        |  4 ++--
 gcc/config/vms/vms.cc                       |  2 +-
 gcc/cp/module.cc                            |  2 +-
 gcc/cp/name-lookup.cc                       |  2 +-
 gcc/cp/parser.cc                            |  2 +-
 gcc/diagnostic-format-json.cc               |  2 +-
 gcc/dwarf2out.cc                            |  3 +--
 gcc/fortran/frontend-passes.cc              |  4 +---
 gcc/fortran/openmp.cc                       |  3 +--
 gcc/fortran/trans-intrinsic.cc              |  2 +-
 gcc/fortran/trans-types.cc                  |  2 +-
 gcc/genhooks.cc                             |  9 ++++-----
 gcc/gimple-ssa-sprintf.cc                   |  2 +-
 gcc/gimple-ssa-warn-access.cc               |  2 +-
 gcc/godump.cc                               |  2 +-
 gcc/hash-table.cc                           |  2 +-
 gcc/input.cc                                |  3 +--
 gcc/ipa-free-lang-data.cc                   |  4 +---
 gcc/ipa-inline.cc                           |  2 +-
 gcc/jit/jit-builtins.cc                     |  6 ++----
 gcc/jit/jit-recording.cc                    |  4 +---
 gcc/lto/lto-common.cc                       |  3 +--
 gcc/lto/lto-lang.cc                         |  4 +---
 gcc/optc-save-gen.awk                       | 16 ++++++++--------
 gcc/spellcheck.cc                           |  2 +-
 gcc/tree-vect-slp-patterns.cc               |  2 +-
 gcc/tree.cc                                 |  4 +---
 55 files changed, 94 insertions(+), 121 deletions(-)

diff --git a/gcc/ada/locales.c b/gcc/ada/locales.c
index ee1385a6bdc..01cb45bc21f 100644
--- a/gcc/ada/locales.c
+++ b/gcc/ada/locales.c
@@ -35,6 +35,8 @@
 #include <ctype.h>
 #include <stddef.h>
 
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
 typedef char char4 [4];
 
 /* Table containing equivalences between ISO_639_1 codes and their ISO_639_3
@@ -649,7 +651,7 @@ str_get_last_byte (char *lc_all) {
 
 static char*
 iso_639_1_to_639_3(char* iso_639_1_code) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -673,7 +675,7 @@ iso_639_1_to_639_3(char* iso_639_1_code) {
 
 static char*
 language_name_to_639_3(char* name) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -695,7 +697,7 @@ language_name_to_639_3(char* name) {
 
 static char*
 country_name_to_3166 (char* name) {
-  int len = sizeof(iso_3166)/sizeof(iso_3166[0]);
+  int len = ARRAY_SIZE (iso_3166);
   char **p = iso_3166;
   int j;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index e43406e3556..9c0c9719fc2 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1139,7 +1139,7 @@ exploded_node::get_dot_fillcolor () const
 	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
 	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
 	   "wheat", "seashell"};
-      const int num_colors = sizeof (colors) / sizeof (colors[0]);
+      const int num_colors = ARRAY_SIZE (colors);
       return colors[total_sm_state % num_colors];
     }
   else
diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc
index 8d9237deb63..be04186ed0d 100644
--- a/gcc/analyzer/function-set.cc
+++ b/gcc/analyzer/function-set.cc
@@ -166,7 +166,7 @@ test_stdio_example ()
     "getwc_unlocked",
     "putc_unlocked"
   };
-  const size_t count = sizeof(example) / sizeof (example[0]);
+  const size_t count = ARRAY_SIZE (example);
   function_set fs (example, count);
   fs.assert_sorted ();
   fs.assert_sane ();
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index ffc2809dc57..3a45e627b35 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -329,8 +329,7 @@ get_file_using_fns ()
     "ungetc",
     "vfprintf"
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
   return fs;
 }
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 4c030803e59..20c1677c498 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -2054,8 +2054,7 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl)
     /* This array must be kept sorted.  */
     "strsep",
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
 
   if (fs.contains_decl_p (fndecl))
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 77044e10805..9b0213e89b7 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -309,8 +309,7 @@ get_async_signal_unsafe_fns ()
     "vsnprintf",
     "vsprintf"
   };
-  const size_t count
-    = sizeof(async_signal_unsafe_fns) / sizeof (async_signal_unsafe_fns[0]);
+  const size_t count = ARRAY_SIZE (async_signal_unsafe_fns);
   function_set fs (async_signal_unsafe_fns, count);
   return fs;
 }
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index b219f878042..6d4a30dc412 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -499,7 +499,7 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
 
   /* Iterate over the mutually exclusive attribute names and verify
      that the symbol doesn't contain it.  */
-  for (unsigned i = 0; i != sizeof attrs / sizeof *attrs; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
     {
       if (!attrs[i])
 	continue;
@@ -2106,7 +2106,7 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
   };
 
   for (unsigned i = 0; i != 2; ++i)
-    for (unsigned j = 0; j != sizeof whitelist / sizeof *whitelist; ++j)
+    for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
       if (lookup_attribute (whitelist[j], tmpl_attrs[i])
 	  || lookup_attribute (whitelist[j], decl_attrs[i]))
 	return 0;
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 5b085e3a14f..2548ce43910 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -613,7 +613,7 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize)
   if (eltsize != tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src)))))
     return NULL_TREE;
 
-  /* Set MAXELTS to sizeof (SRC) / sizeof (*SRC) - 1, the maximum possible
+  /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
      length of SRC.  Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
      in case the latter is less than the size of the array, such as when
      SRC refers to a short string literal used to initialize a large array.
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 0f047a105c2..e50e79e0cd1 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -4952,8 +4952,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags,
   int imode;
 
   {
-    const int nmodes =
-      sizeof attr_access::mode_names / sizeof *attr_access::mode_names;
+    const int nmodes = ARRAY_SIZE (attr_access::mode_names);
 
     for (imode = 0; imode != nmodes; ++imode)
       if (!strncmp (ps, attr_access::mode_names[imode],
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 6156e5fcb0c..c9c9e720bc8 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -602,8 +602,7 @@ const struct c_common_resword c_common_reswords[] =
   { "null_resettable",	RID_NULL_RESETTABLE,	D_OBJC },
 };
 
-const unsigned int num_c_common_reswords =
-  sizeof c_common_reswords / sizeof (struct c_common_resword);
+const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
 
 /* Return identifier for address space AS.  */
 
@@ -4482,9 +4481,7 @@ c_common_nodes_and_builtins (void)
 
   /* Make fileptr_type_node a distinct void * type until
      FILE type is defined.  Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node
       = build_variant_type_copy (builtin_structptr_types[i].base);
 
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index ea57fde801c..25b1c1d0f15 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -3189,7 +3189,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
   else
     {
       /* Diagnose some common misspellings.  */
-      for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
+      for (unsigned i = 0; i != ARRAY_SIZE (badwords); ++i)
 	{
 	  unsigned badwlen = strspn (badwords[i].name, " -");
 	  if (wlen >= badwlen
@@ -3384,14 +3384,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISPUNCT (format_chars[0]))
     {
-      size_t nelts = sizeof c_opers / sizeof *c_opers;
+      size_t nelts = ARRAY_SIZE (c_opers);
       if (const char *ret = check_tokens (c_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_opers / sizeof *cxx_opers : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_opers) : 0;
       if (const char *ret = check_tokens (cxx_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3401,14 +3401,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISALPHA (format_chars[0]))
     {
-      size_t nelts = sizeof c_keywords / sizeof *c_keywords;
+      size_t nelts = ARRAY_SIZE (c_keywords);
       if (const char *ret = check_tokens (c_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_keywords / sizeof *cxx_keywords : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_keywords) : 0;
       if (const char *ret = check_tokens (cxx_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3527,7 +3527,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 	  && ISALPHA (format_chars[1]))
 	{
 	  /* Diagnose a subset of contractions that are best avoided.  */
-	  for (unsigned i = 0; i != sizeof contrs / sizeof *contrs; ++i)
+	  for (unsigned i = 0; i != ARRAY_SIZE (contrs); ++i)
 	    {
 	      const char *apos = strchr (contrs[i].name, '\'');
 	      gcc_assert (apos != NULL);
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 4c80bdd26d6..cc05b2580fa 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1400,8 +1400,8 @@ static const struct omp_pragma_def omp_pragmas_simd[] = {
 void
 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
 {
-  const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
-  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+  const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+  const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
   const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
 				 / sizeof (*omp_pragmas);
   int i;
@@ -1576,8 +1576,7 @@ init_pragma (void)
 {
   if (flag_openacc)
     {
-      const int n_oacc_pragmas
-	= sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
+      const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
       int i;
 
       for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1587,7 +1586,7 @@ init_pragma (void)
 
   if (flag_openmp)
     {
-      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+      const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
       int i;
 
       for (i = 0; i < n_omp_pragmas; ++i)
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 8ad3eb3f466..01c86b27dc8 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -79,8 +79,7 @@ get_string_macro_hint (const char *name, enum stdlib lib)
   if ((lib == STDLIB_C && flag_isoc99)
       || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
     {
-      const size_t num_c99_cxx11_macros
-	= sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+      const size_t num_c99_cxx11_macros = ARRAY_SIZE (c99_cxx11_macros);
       for (size_t i = 0; i < num_c99_cxx11_macros; i++)
 	if (strcmp (name, c99_cxx11_macros[i]) == 0)
 	  return lib == STDLIB_C ? "<inttypes.h>" : "<cinttypes>";
@@ -204,7 +203,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
     {"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     if (strcmp (name, hints[i].name) == 0)
       return hints[i].header[lib];
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c701f07befe..e49879ab286 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1658,7 +1658,7 @@ c_bind (location_t loc, tree decl, bool is_global)
    Used only by match_builtin_function_types.  */
 
 static const unsigned builtin_structptr_type_count
-  = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  = ARRAY_SIZE (builtin_structptr_types);
 
 static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
 
@@ -1705,10 +1705,8 @@ match_builtin_function_types (tree newtype, tree oldtype,
   tree newargs = TYPE_ARG_TYPES (newtype);
   tree tryargs = newargs;
 
-  const unsigned nlst
-    = sizeof last_structptr_types / sizeof last_structptr_types[0];
-  const unsigned nbst
-    = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  const unsigned nlst = ARRAY_SIZE (last_structptr_types);
+  const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
 
   gcc_checking_assert (nlst == nbst);
 
diff --git a/gcc/cfg.cc b/gcc/cfg.cc
index da781ba2da8..bbd01ba21bb 100644
--- a/gcc/cfg.cc
+++ b/gcc/cfg.cc
@@ -787,7 +787,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags,
       NULL
 #undef DEF_BASIC_BLOCK_FLAG
     };
-  const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  const unsigned n_bitnames = ARRAY_SIZE (bb_bitnames);
   bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
index dfda5b8372a..7fac90d313b 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -314,8 +314,7 @@ aarch64_option_init_struct (struct gcc_options *opts ATTRIBUTE_UNUSED)
        pop and attribute change (arm_neon headers, lto etc all cause this to
        happen quite frequently).  It is a trade-off between time and space and
        so time won.  */
-    int n_extensions
-      = sizeof (all_extensions) / sizeof (struct aarch64_option_extension);
+    int n_extensions = ARRAY_SIZE (all_extensions);
     qsort (&all_extensions_by_on, n_extensions,
 	   sizeof (struct aarch64_option_extension), opt_ext_cmp);
 }
diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
index c21476d7ae9..e0a741ac663 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -832,7 +832,7 @@ aarch64_lookup_simd_builtin_type (machine_mode mode,
 				  enum aarch64_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -869,7 +869,7 @@ static void
 aarch64_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
@@ -1434,7 +1434,7 @@ aarch64_init_builtin_rsqrt (void)
   };
 
   builtin_decls_data *bdd = bdda;
-  builtin_decls_data *bdd_end = bdd + (sizeof (bdda) / sizeof (builtin_decls_data));
+  builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda));
 
   for (; bdd < bdd_end; bdd++)
   {
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index f650abbc4ce..6f2f5d27ddc 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20755,7 +20755,7 @@ is_madd_op (enum attr_type t1)
     TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
   };
 
-  for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
+  for (i = 0; i < ARRAY_SIZE (mlatypes); i++)
     {
       if (t1 == mlatypes[i])
 	return true;
diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index 36a40a1dc80..d917137e5ee 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -1471,7 +1471,7 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 			      enum arm_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -1503,7 +1503,7 @@ static void
 arm_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
   tree tdecl;
 
   /* Poly types are a world of their own.  In order to maintain legacy
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.cc b/gcc/config/avr/gen-avr-mmcu-texi.cc
index d9c3a30877d..a44e18e4c35 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.cc
+++ b/gcc/config/avr/gen-avr-mmcu-texi.cc
@@ -23,10 +23,12 @@
 
 #define IN_GEN_AVR_MMCU_TEXI
 
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
 #include "avr-devices.cc"
 
 static const avr_mcu_t*
-mcus[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
+mcus[ARRAY_SIZE (avr_mcu_types)];
 
 static int letter (char c)
 {
@@ -56,7 +58,7 @@ c_prefix (const char *str)
       "attiny", "atmega", "atxmega", "ata", "at90"
     };
 
-  int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
+  int i, n = (int) (ARRAY_SIZE (prefixes));
 
   for (i = 0; i < n; i++)
     if (str_prefix_p (str, prefixes[i]))
@@ -185,7 +187,7 @@ int main (void)
 	  print_mcus (n_mcus);
 	  n_mcus = 0;
 
-	  for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
+	  for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
 	    if (arch_id == avr_texinfo[i].arch_id)
 	      printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
 	}
diff --git a/gcc/config/c6x/c6x.cc b/gcc/config/c6x/c6x.cc
index 7fe18d69c7f..dc01a6e47c4 100644
--- a/gcc/config/c6x/c6x.cc
+++ b/gcc/config/c6x/c6x.cc
@@ -2580,7 +2580,7 @@ static unsigned reg_save_order[] =
   REG_B14, REG_A15
 };
 
-#define N_SAVE_ORDER (sizeof reg_save_order / sizeof *reg_save_order)
+#define N_SAVE_ORDER (ARRAY_SIZE (reg_save_order))
 
 /* Compute the layout of the stack frame and store it in FRAME.  */
 
diff --git a/gcc/config/darwin-c.cc b/gcc/config/darwin-c.cc
index 3770857aa42..9203c84d2c2 100644
--- a/gcc/config/darwin-c.cc
+++ b/gcc/config/darwin-c.cc
@@ -505,7 +505,7 @@ darwin_register_frameworks (const char *sysroot,
       size_t i;
 
       /* Setup default search path for frameworks.  */
-      for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
+      for (i = 0; i < ARRAY_SIZE (framework_defaults); ++i)
 	{
 	  char *str;
 	  if (sysroot)
diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 94ba7ffa5af..9db2124b129 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -723,7 +723,7 @@ process_obj (FILE *in, FILE *cfile)
 	   "  unsigned global_variable_count;\n"
 	   "} target_data = {\n"
 	   "  &gcn_image,\n"
-	   "  sizeof (gcn_kernels) / sizeof (gcn_kernels[0]),\n"
+	   "  ARRAY_SIZE (gcn_kernels),\n"
 	   "  gcn_kernels,\n"
 	   "  gcn_num_vars\n"
 	   "};\n\n");
diff --git a/gcc/config/i386/i386-builtins.cc b/gcc/config/i386/i386-builtins.cc
index 8c6d0fe9631..0ea0eee5624 100644
--- a/gcc/config/i386/i386-builtins.cc
+++ b/gcc/config/i386/i386-builtins.cc
@@ -1936,8 +1936,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
 
   enum feature_priority priority = P_NONE;
 
-  static unsigned int NUM_FEATURES
-    = sizeof (isa_names_table) / sizeof (_isa_names_table);
+  static unsigned int NUM_FEATURES = ARRAY_SIZE (isa_names_table);
 
   unsigned int i;
 
@@ -2290,8 +2289,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
       tree final;
 
       unsigned int field_val = 0;
-      unsigned int NUM_ISA_NAMES
-	= sizeof (isa_names_table) / sizeof (struct _isa_names_table);
+      unsigned int NUM_ISA_NAMES = ARRAY_SIZE (isa_names_table);
 
       for (i = 0; i < NUM_ISA_NAMES; i++)
 	if (strcmp (isa_names_table[i].name,
diff --git a/gcc/config/m32c/m32c.cc b/gcc/config/m32c/m32c.cc
index 11ca9a43a0b..5a19faa063c 100644
--- a/gcc/config/m32c/m32c.cc
+++ b/gcc/config/m32c/m32c.cc
@@ -1090,7 +1090,7 @@ static struct
   { FB_REGNO, 0x01, 2, 4 }
 };
 
-#define PUSHM_N (sizeof(pushm_info)/sizeof(pushm_info[0]))
+#define PUSHM_N (ARRAY_SIZE (pushm_info))
 
 /* Returns TRUE if we need to save/restore the given register.  We
    save everything for exception handlers, so that any register can be
diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index b28c1a32292..fa3b4b76821 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -316,11 +316,11 @@ process (FILE *in, FILE *out)
 	   "  const struct nvptx_fn *fn_names;\n"
 	   "  unsigned fn_num;\n"
 	   "} target_data = {\n"
-	   "  ptx_objs, sizeof (ptx_objs) / sizeof (ptx_objs[0]),\n"
+	   "  ptx_objs, ARRAY_SIZE (ptx_objs),\n"
 	   "  var_mappings,"
-	   "  sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+	   "  ARRAY_SIZE (var_mappings),\n"
 	   "  func_mappings,"
-	   "  sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+	   "  ARRAY_SIZE (func_mappings)\n"
 	   "};\n\n");
 
   fprintf (out, "#ifdef __cplusplus\n"
diff --git a/gcc/config/rs6000/driver-rs6000.cc b/gcc/config/rs6000/driver-rs6000.cc
index ec890e0db3a..b871f0a36a8 100644
--- a/gcc/config/rs6000/driver-rs6000.cc
+++ b/gcc/config/rs6000/driver-rs6000.cc
@@ -599,7 +599,7 @@ host_detect_local_cpu (int argc, const char **argv)
 
   if (assembler)
     {
-      for (i = 0; i < sizeof (asm_names) / sizeof (asm_names[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (asm_names); i++)
 	{
 	  if (!asm_names[i].cpu || !strcmp (asm_names[i].cpu, cpu))
 	    return asm_names[i].asm_sw;
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 7c3bd6cbe7f..90ca50515a7 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -8768,7 +8768,7 @@ static machine_mode constant_modes[] =
   QImode,
   V1QImode
 };
-#define NR_C_MODES (sizeof (constant_modes) / sizeof (constant_modes[0]))
+#define NR_C_MODES (ARRAY_SIZE (constant_modes))
 
 struct constant
 {
diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index c9649fb9c70..798766a723b 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -462,7 +462,7 @@ find_sequences (ExpressionTree &s, ExpressionTreeMap &best_solution)
   const Operator *const prev_op = s.m_exprs[num_vals - 1].m_op;
   const int prev_top_index = (prev_op != NULL) ? prev_op->m_top_index : -1;
 
-  for (size_t f = 0; f < sizeof ops / sizeof ops[0]; f++)
+  for (size_t f = 0; f < ARRAY_SIZE (ops); f++)
     {
       const Operator *const op = &ops[f];
 
@@ -564,7 +564,7 @@ create_insn_code_compression_table ()
   printf ("const enum insn_code %s_multiply_insn_seq_decode_opcode[] = {\n"
 	  "  CODE_FOR_nothing /* must be first */ ", ARCH);
 
-  for (size_t i = 0; i < sizeof ops / sizeof ops[0]; i++)
+  for (size_t i = 0; i < ARRAY_SIZE (ops); i++)
     {
       Operator *op = &ops[i];
       int index = -1;
diff --git a/gcc/config/vms/vms.cc b/gcc/config/vms/vms.cc
index 5d565e35fb4..d0d44bad2ce 100644
--- a/gcc/config/vms/vms.cc
+++ b/gcc/config/vms/vms.cc
@@ -99,7 +99,7 @@ static const struct vms_crtl_name vms_crtl_names[] =
 
 /* Number of entires in the above array.  */
 
-#define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
+#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names))
 
 /* List of aliased identifiers.  They must be persistent across gc.  */
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 18dabfcc9ac..f0f57b1c690 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2615,7 +2615,7 @@ depset::entity_kind_name () const
     {"decl", "specialization", "partial", "using",
      "namespace", "redirect", "binding"};
   entity_kind kind = get_entity_kind ();
-  gcc_checking_assert (kind < sizeof (names) / sizeof(names[0]));
+  gcc_checking_assert (kind < ARRAY_SIZE (names));
   return names[kind];
 }
 
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7b0638d3166..05f29cebac2 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -6915,7 +6915,7 @@ get_std_name_hint (const char *name)
     /* <vector>.  */
     {"vector", "<vector>", cxx98},
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     {
       if (strcmp (name, hints[i].name) == 0)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index a28e0e20c75..4a78ef30622 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -4200,7 +4200,7 @@ cp_parser_new (cp_lexer *lexer)
 {
   /* Initialize the binops_by_token so that we can get the tree
      directly from the token.  */
-  for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (binops); i++)
     binops_by_token[binops[i].token_type] = binops[i];
 
   cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index def371816e6..62594ebb4d7 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -62,7 +62,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
     {"byte-column", DIAGNOSTICS_COLUMN_UNIT_BYTE}
   };
   int the_column = INT_MIN;
-  for (int i = 0; i != sizeof column_fields / sizeof (*column_fields); ++i)
+  for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
     {
       context->column_unit = column_fields[i].unit;
       const int col = diagnostic_converted_column (context, exploc);
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 5681b01749a..4ef644c5fae 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -13532,8 +13532,7 @@ static const dwarf_qual_info_t dwarf_qual_info[] =
   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
 };
-static const unsigned int dwarf_qual_info_size
-  = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
+static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
 
 /* If DIE is a qualified DIE of some base DIE with the same parent,
    return the base DIE, otherwise return NULL.  Set MASK to the
diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 5eba6345145..612c12d233d 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5654,9 +5654,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 		  WALK_SUBEXPR (co->ext.omp_clauses->detach);
 		  for (idx = 0; idx < OMP_IF_LAST; idx++)
 		    WALK_SUBEXPR (co->ext.omp_clauses->if_exprs[idx]);
-		  for (idx = 0;
-		       idx < sizeof (list_types) / sizeof (list_types[0]);
-		       idx++)
+		  for (idx = 0; idx < ARRAY_SIZE (list_types); idx++)
 		    for (n = co->ext.omp_clauses->lists[list_types[idx]];
 			 n; n = n->next)
 		      WALK_SUBEXPR (n->expr);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 4d3fcc8bb78..8643e43005f 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -4902,8 +4902,7 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
       match m;
       const char *selector_sets[] = { "construct", "device",
 				      "implementation", "user" };
-      const int selector_set_count
-	= sizeof (selector_sets) / sizeof (*selector_sets);
+      const int selector_set_count = ARRAY_SIZE (selector_sets);
       int i;
       char buf[GFC_MAX_SYMBOL_LEN + 1];
 
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 2249723540d..6884060fd6f 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -9784,7 +9784,7 @@ conv_intrinsic_ieee_builtin (gfc_se * se, gfc_expr * expr,
 			     enum built_in_function code, int nargs)
 {
   tree args[2];
-  gcc_assert ((unsigned) nargs <= sizeof(args)/sizeof(args[0]));
+  gcc_assert ((unsigned) nargs <= ARRAY_SIZE (args));
 
   conv_ieee_function_args (se, expr, args, nargs);
   se->expr = build_call_expr_loc_array (input_location,
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 3cdc529eb28..3742bf312cd 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3420,7 +3420,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
     }
 
   rank = GFC_TYPE_ARRAY_RANK (type);
-  if (rank >= (int) (sizeof (info->dimen) / sizeof (info->dimen[0])))
+  if (rank >= (int) (ARRAY_SIZE (info->dimen)))
     return false;
 
   etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
diff --git a/gcc/genhooks.cc b/gcc/genhooks.cc
index 20ad607b158..6bae85d7b8d 100644
--- a/gcc/genhooks.cc
+++ b/gcc/genhooks.cc
@@ -128,7 +128,7 @@ emit_documentation (const char *in_fname)
     }
   fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
     {
       struct s_hook sh, *shp;
       void *p;
@@ -223,7 +223,7 @@ emit_documentation (const char *in_fname)
 	      /* POD-valued hooks sometimes come in groups with common
 		 documentation.*/
 	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
+		   j < (int) (ARRAY_SIZE (hook_array))
 		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
 		{
 		  char *namex = upstrdup (hook_array[j].name);
@@ -246,8 +246,7 @@ emit_documentation (const char *in_fname)
 		  printf ("\n@end %s", deftype);
 		}
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
+	  if (++i >= (int) (ARRAY_SIZE (hook_array)) || !hook_array[i].doc)
 	    break;
 	  free (name);
 	  sh.name = name = upstrdup (hook_array[i].name);
@@ -270,7 +269,7 @@ emit_init_macros (const char *docname)
 
   for (print_nest = 0; print_nest <= MAX_NEST; print_nest++)
     {
-      for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+      for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
 	{
 	  char *name = upstrdup (hook_array[i].name);
 
diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc
index 9a84fffed1a..eb05be8c0ed 100644
--- a/gcc/gimple-ssa-sprintf.cc
+++ b/gcc/gimple-ssa-sprintf.cc
@@ -1953,7 +1953,7 @@ format_floating (const directive &dir, tree arg, pointer_query &)
       &res.range.min, &res.range.max
     };
 
-    for (int i = 0; i != sizeof minmax / sizeof *minmax; ++i)
+    for (int i = 0; i != ARRAY_SIZE (minmax); ++i)
       {
 	/* Convert the GCC real value representation with the precision
 	   of the real type to the mpfr_t format rounding down in the
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 39aa8186de6..ec458b0c0d3 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2853,7 +2853,7 @@ memmodel_name (unsigned HOST_WIDE_INT val)
 {
   val = memmodel_base (val);
 
-  for (unsigned i = 0; i != sizeof memory_models / sizeof *memory_models; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (memory_models); ++i)
     {
       if (val == memory_models[i].modval)
 	return memory_models[i].modname;
diff --git a/gcc/godump.cc b/gcc/godump.cc
index 669168806f3..2ae0bcc9672 100644
--- a/gcc/godump.cc
+++ b/gcc/godump.cc
@@ -1326,7 +1326,7 @@ static void
 keyword_hash_init (class godump_container *container)
 {
   size_t i;
-  size_t count = sizeof (keywords) / sizeof (keywords[0]);
+  size_t count = ARRAY_SIZE (keywords);
   void **slot;
 
   for (i = 0; i < count; i++)
diff --git a/gcc/hash-table.cc b/gcc/hash-table.cc
index dad1d21f099..1015c1ee6e9 100644
--- a/gcc/hash-table.cc
+++ b/gcc/hash-table.cc
@@ -84,7 +84,7 @@ unsigned int
 hash_table_higher_prime_index (unsigned long n)
 {
   unsigned int low = 0;
-  unsigned int high = sizeof (prime_tab) / sizeof (prime_tab[0]);
+  unsigned int high = ARRAY_SIZE (prime_tab);
 
   while (low != high)
     {
diff --git a/gcc/input.cc b/gcc/input.cc
index b3970613d81..58beba05072 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -3724,8 +3724,7 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
     {
       /* ...and use each of the "interesting" location values as
 	 the starting location within line_table.  */
-      const int num_boundary_locations
-	= sizeof (boundary_locations) / sizeof (boundary_locations[0]);
+      const int num_boundary_locations = ARRAY_SIZE (boundary_locations);
       for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++)
 	{
 	  line_table_case c (default_range_bits, boundary_locations[loc_idx]);
diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index a742156858c..f99f7be1c58 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -1109,9 +1109,7 @@ free_lang_data (void)
   free_lang_data_in_cgraph (&fld);
 
   /* Create gimple variants for common types.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index f8bb072c422..22a009b7435 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -278,7 +278,7 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
       SANITIZE_POINTER_SUBTRACT
     };
 
-  for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (codes); i++)
     if (sanitize_flags_p (codes[i], caller)
 	!= sanitize_flags_p (codes[i], callee))
       return false;
diff --git a/gcc/jit/jit-builtins.cc b/gcc/jit/jit-builtins.cc
index b949b734332..fb86c77d0fe 100644
--- a/gcc/jit/jit-builtins.cc
+++ b/gcc/jit/jit-builtins.cc
@@ -109,9 +109,7 @@ find_builtin_by_name (const char *in_name,
 
      We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
      has a NULL name.  */
-  for (unsigned int i = 1;
-       i < sizeof (builtin_data) / sizeof (builtin_data[0]);
-       i++)
+  for (unsigned int i = 1; i < ARRAY_SIZE (builtin_data); i++)
     {
       const struct builtin_data& bd = builtin_data[i];
       if (matches_builtin (in_name, bd))
@@ -320,7 +318,7 @@ static const char * const type_names[] = {
 static const char *
 get_string_for_type_id (enum jit_builtin_type type_id)
 {
-  gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0]));
+  gcc_assert (type_id < ARRAY_SIZE (type_names));
   return type_names[type_id];
 }
 
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index a31720f043e..4305a961489 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -568,9 +568,7 @@ recording::context::context (context *parent_ctxt)
   if (parent_ctxt)
     {
       /* Inherit options from parent.  */
-      for (unsigned i = 0;
-	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
-	   i++)
+      for (unsigned i = 0; i < ARRAY_SIZE (m_str_options); i++)
 	{
 	  const char *parent_opt = parent_ctxt->m_str_options[i];
 	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index ca28586a1e8..d8d0404c54e 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2104,8 +2104,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
       char r_str[27];
       enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
       unsigned int j;
-      unsigned int lto_resolution_str_len
-	= sizeof (lto_resolution_str) / sizeof (char *);
+      unsigned int lto_resolution_str_len = ARRAY_SIZE (lto_resolution_str);
       res_pair rp;
 
       t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index 8d58d924dff..972a0336f75 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -1319,9 +1319,7 @@ lto_init (void)
      distinction should only be relevant to the front-end, so we
      always use the C definition here in lto1.
      Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     {
       gcc_assert (builtin_structptr_types[i].node
 		  == builtin_structptr_types[i].base);
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 9911bab6668..233d1fbb637 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1104,7 +1104,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 	print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 	print "      return false;"
 }
@@ -1152,7 +1152,7 @@ for (i = 0; i < n_target_val; i++) {
 	print "  hstate.add_hwi (ptr->" name");";
 }
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 }
 
@@ -1192,7 +1192,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 }
 
@@ -1235,7 +1235,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 }
 
@@ -1317,7 +1317,7 @@ for (i = 0; i < n_opt_val; i++) {
 	else
 		print "  hstate.add_hwi (ptr->" name");";
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 print "  return hstate.end ();";
 print "}";
@@ -1346,7 +1346,7 @@ for (i = 0; i < n_opt_val; i++) {
 		print "    return false;";
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 print "      return false;"
 print "  return true;";
@@ -1380,7 +1380,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 print "}";
 
@@ -1412,7 +1412,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 print "}";
 print "/* Free heap memory used by optimization options  */";
diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc
index 3e58344f510..c7bb0122545 100644
--- a/gcc/spellcheck.cc
+++ b/gcc/spellcheck.cc
@@ -489,7 +489,7 @@ static const char * const test_data[] = {
 static void
 test_metric_conditions ()
 {
-  const int num_test_cases = sizeof (test_data) / sizeof (test_data[0]);
+  const int num_test_cases = ARRAY_SIZE (test_data);
 
   for (int i = 0; i < num_test_cases; i++)
     {
diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc
index 879d17fd947..a6b0d106d5f 100644
--- a/gcc/tree-vect-slp-patterns.cc
+++ b/gcc/tree-vect-slp-patterns.cc
@@ -1637,4 +1637,4 @@ vect_pattern_decl_t slp_patterns[]
 #undef SLP_PATTERN
 
 /* Set the number of SLP pattern matchers available.  */
-size_t num__slp_patterns = sizeof(slp_patterns)/sizeof(vect_pattern_decl_t);
+size_t num__slp_patterns = ARRAY_SIZE (slp_patterns);
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 5e8876d2b38..df441c6b223 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -9408,9 +9408,7 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE.
@ 2022-05-05 13:41 Martin Liska
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Liska @ 2022-05-05 13:41 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:8d9630e411321c8584dd83ff64ec6fefad48813e

commit 8d9630e411321c8584dd83ff64ec6fefad48813e
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 13 18:46:26 2022 +0100

    Use more ARRAY_SIZE.
    
    gcc/ada/ChangeLog:
    
            * locales.c (iso_639_1_to_639_3): Use ARRAY_SIZE.
            (language_name_to_639_3): Likewise.
            (country_name_to_3166): Likewise.
    
    gcc/analyzer/ChangeLog:
    
            * engine.cc (exploded_node::get_dot_fillcolor): Use ARRAY_SIZE.
            * function-set.cc (test_stdio_example): Likewise.
            * sm-file.cc (get_file_using_fns): Likewise.
            * sm-malloc.cc (malloc_state_machine::unaffected_by_call_p): Likewise.
            * sm-signal.cc (get_async_signal_unsafe_fns): Likewise.
    
    gcc/ChangeLog:
    
            * attribs.cc (diag_attr_exclusions): Use ARRAY_SIZE.
            (decls_mismatched_attributes): Likewise.
            * builtins.cc (c_strlen): Likewise.
            * cfg.cc (DEF_BASIC_BLOCK_FLAG): Likewise.
            * common/config/aarch64/aarch64-common.cc (aarch64_option_init_struct): Likewise.
            * config/aarch64/aarch64-builtins.cc (aarch64_lookup_simd_builtin_type): Likewise.
            (aarch64_init_simd_builtin_types): Likewise.
            (aarch64_init_builtin_rsqrt): Likewise.
            * config/aarch64/aarch64.cc (is_madd_op): Likewise.
            * config/arm/arm-builtins.cc (arm_lookup_simd_builtin_type): Likewise.
            (arm_init_simd_builtin_types): Likewise.
            * config/avr/gen-avr-mmcu-texi.cc (mcus[ARRAY_SIZE): Likewise.
            (c_prefix): Likewise.
            (main): Likewise.
            * config/c6x/c6x.cc (N_SAVE_ORDER): Likewise.
            * config/darwin-c.cc (darwin_register_frameworks): Likewise.
            * config/gcn/mkoffload.cc (process_obj): Likewise.
            * config/i386/i386-builtins.cc (get_builtin_code_for_version): Likewise.
            (fold_builtin_cpu): Likewise.
            * config/m32c/m32c.cc (PUSHM_N): Likewise.
            * config/nvptx/mkoffload.cc (process): Likewise.
            * config/rs6000/driver-rs6000.cc (host_detect_local_cpu): Likewise.
            * config/s390/s390.cc (NR_C_MODES): Likewise.
            * config/tilepro/gen-mul-tables.cc (find_sequences): Likewise.
            (create_insn_code_compression_table): Likewise.
            * config/vms/vms.cc (NBR_CRTL_NAMES): Likewise.
            * diagnostic-format-json.cc (json_from_expanded_location): Likewise.
            * dwarf2out.cc (ARRAY_SIZE): Likewise.
            * genhooks.cc (emit_documentation): Likewise.
            (emit_init_macros): Likewise.
            * gimple-ssa-sprintf.cc (format_floating): Likewise.
            * gimple-ssa-warn-access.cc (memmodel_name): Likewise.
            * godump.cc (keyword_hash_init): Likewise.
            * hash-table.cc (hash_table_higher_prime_index): Likewise.
            * input.cc (for_each_line_table_case): Likewise.
            * ipa-free-lang-data.cc (free_lang_data): Likewise.
            * ipa-inline.cc (sanitize_attrs_match_for_inline_p): Likewise.
            * optc-save-gen.awk: Likewise.
            * spellcheck.cc (test_metric_conditions): Likewise.
            * tree-vect-slp-patterns.cc (sizeof): Likewise.
            (ARRAY_SIZE): Likewise.
            * tree.cc (build_common_tree_nodes): Likewise.
    
    gcc/c-family/ChangeLog:
    
            * c-common.cc (ARRAY_SIZE): Use ARRAY_SIZE.
            (c_common_nodes_and_builtins): Likewise.
            * c-format.cc (check_tokens): Likewise.
            (check_plain): Likewise.
            * c-pragma.cc (c_pp_lookup_pragma): Likewise.
            (init_pragma): Likewise.
            * known-headers.cc (get_string_macro_hint): Likewise.
            (get_stdlib_header_for_name): Likewise.
            * c-attribs.cc: Likewise.
    
    gcc/c/ChangeLog:
    
            * c-decl.cc (match_builtin_function_types): Use ARRAY_SIZE.
    
    gcc/cp/ChangeLog:
    
            * module.cc (depset::entity_kind_name): Use ARRAY_SIZE.
            * name-lookup.cc (get_std_name_hint): Likewise.
            * parser.cc (cp_parser_new): Likewise.
    
    gcc/fortran/ChangeLog:
    
            * frontend-passes.cc (gfc_code_walker): Use ARRAY_SIZE.
            * openmp.cc (gfc_match_omp_context_selector_specification): Likewise.
            * trans-intrinsic.cc (conv_intrinsic_ieee_builtin): Likewise.
            * trans-types.cc (gfc_get_array_descr_info): Likewise.
    
    gcc/jit/ChangeLog:
    
            * jit-builtins.cc (find_builtin_by_name): Use ARRAY_SIZE.
            (get_string_for_type_id): Likewise.
            * jit-recording.cc (recording::context::context): Likewise.
    
    gcc/lto/ChangeLog:
    
            * lto-common.cc (lto_resolution_read): Use ARRAY_SIZE.
            * lto-lang.cc (lto_init): Likewise.

Diff:
---
 gcc/ada/locales.c                           |  6 +++---
 gcc/analyzer/engine.cc                      |  2 +-
 gcc/analyzer/function-set.cc                |  2 +-
 gcc/analyzer/sm-file.cc                     |  3 +--
 gcc/analyzer/sm-malloc.cc                   |  3 +--
 gcc/analyzer/sm-signal.cc                   |  3 +--
 gcc/attribs.cc                              |  4 ++--
 gcc/builtins.cc                             |  2 +-
 gcc/c-family/c-attribs.cc                   |  3 +--
 gcc/c-family/c-common.cc                    |  7 ++-----
 gcc/c-family/c-format.cc                    | 12 ++++++------
 gcc/c-family/c-pragma.cc                    |  9 ++++-----
 gcc/c-family/known-headers.cc               |  5 ++---
 gcc/c/c-decl.cc                             |  8 +++-----
 gcc/cfg.cc                                  |  2 +-
 gcc/common/config/aarch64/aarch64-common.cc |  3 +--
 gcc/config/aarch64/aarch64-builtins.cc      |  6 +++---
 gcc/config/aarch64/aarch64.cc               |  2 +-
 gcc/config/arm/arm-builtins.cc              |  4 ++--
 gcc/config/avr/gen-avr-mmcu-texi.cc         |  8 +++++---
 gcc/config/c6x/c6x.cc                       |  2 +-
 gcc/config/darwin-c.cc                      |  2 +-
 gcc/config/gcn/mkoffload.cc                 |  2 +-
 gcc/config/i386/i386-builtins.cc            |  6 ++----
 gcc/config/m32c/m32c.cc                     |  2 +-
 gcc/config/nvptx/mkoffload.cc               |  6 +++---
 gcc/config/rs6000/driver-rs6000.cc          |  2 +-
 gcc/config/s390/s390.cc                     |  2 +-
 gcc/config/tilepro/gen-mul-tables.cc        |  4 ++--
 gcc/config/vms/vms.cc                       |  2 +-
 gcc/cp/module.cc                            |  2 +-
 gcc/cp/name-lookup.cc                       |  2 +-
 gcc/cp/parser.cc                            |  2 +-
 gcc/diagnostic-format-json.cc               |  2 +-
 gcc/dwarf2out.cc                            |  3 +--
 gcc/fortran/frontend-passes.cc              |  4 +---
 gcc/fortran/openmp.cc                       |  3 +--
 gcc/fortran/trans-intrinsic.cc              |  2 +-
 gcc/fortran/trans-types.cc                  |  2 +-
 gcc/genhooks.cc                             |  9 ++++-----
 gcc/gimple-ssa-sprintf.cc                   |  2 +-
 gcc/gimple-ssa-warn-access.cc               |  2 +-
 gcc/godump.cc                               |  2 +-
 gcc/hash-table.cc                           |  2 +-
 gcc/input.cc                                |  3 +--
 gcc/ipa-free-lang-data.cc                   |  4 +---
 gcc/ipa-inline.cc                           |  2 +-
 gcc/jit/jit-builtins.cc                     |  6 ++----
 gcc/jit/jit-recording.cc                    |  4 +---
 gcc/lto/lto-common.cc                       |  3 +--
 gcc/lto/lto-lang.cc                         |  4 +---
 gcc/optc-save-gen.awk                       | 16 ++++++++--------
 gcc/spellcheck.cc                           |  2 +-
 gcc/tree-vect-slp-patterns.cc               |  2 +-
 gcc/tree.cc                                 |  4 +---
 55 files changed, 92 insertions(+), 121 deletions(-)

diff --git a/gcc/ada/locales.c b/gcc/ada/locales.c
index ee1385a6bdc..2aaa2121a50 100644
--- a/gcc/ada/locales.c
+++ b/gcc/ada/locales.c
@@ -649,7 +649,7 @@ str_get_last_byte (char *lc_all) {
 
 static char*
 iso_639_1_to_639_3(char* iso_639_1_code) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -673,7 +673,7 @@ iso_639_1_to_639_3(char* iso_639_1_code) {
 
 static char*
 language_name_to_639_3(char* name) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -695,7 +695,7 @@ language_name_to_639_3(char* name) {
 
 static char*
 country_name_to_3166 (char* name) {
-  int len = sizeof(iso_3166)/sizeof(iso_3166[0]);
+  int len = ARRAY_SIZE (iso_3166);
   char **p = iso_3166;
   int j;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index e43406e3556..9c0c9719fc2 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1139,7 +1139,7 @@ exploded_node::get_dot_fillcolor () const
 	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
 	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
 	   "wheat", "seashell"};
-      const int num_colors = sizeof (colors) / sizeof (colors[0]);
+      const int num_colors = ARRAY_SIZE (colors);
       return colors[total_sm_state % num_colors];
     }
   else
diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc
index 8d9237deb63..be04186ed0d 100644
--- a/gcc/analyzer/function-set.cc
+++ b/gcc/analyzer/function-set.cc
@@ -166,7 +166,7 @@ test_stdio_example ()
     "getwc_unlocked",
     "putc_unlocked"
   };
-  const size_t count = sizeof(example) / sizeof (example[0]);
+  const size_t count = ARRAY_SIZE (example);
   function_set fs (example, count);
   fs.assert_sorted ();
   fs.assert_sane ();
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index ffc2809dc57..3a45e627b35 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -329,8 +329,7 @@ get_file_using_fns ()
     "ungetc",
     "vfprintf"
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
   return fs;
 }
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 4c030803e59..20c1677c498 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -2054,8 +2054,7 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl)
     /* This array must be kept sorted.  */
     "strsep",
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
 
   if (fs.contains_decl_p (fndecl))
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 77044e10805..9b0213e89b7 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -309,8 +309,7 @@ get_async_signal_unsafe_fns ()
     "vsnprintf",
     "vsprintf"
   };
-  const size_t count
-    = sizeof(async_signal_unsafe_fns) / sizeof (async_signal_unsafe_fns[0]);
+  const size_t count = ARRAY_SIZE (async_signal_unsafe_fns);
   function_set fs (async_signal_unsafe_fns, count);
   return fs;
 }
diff --git a/gcc/attribs.cc b/gcc/attribs.cc
index b219f878042..6d4a30dc412 100644
--- a/gcc/attribs.cc
+++ b/gcc/attribs.cc
@@ -499,7 +499,7 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
 
   /* Iterate over the mutually exclusive attribute names and verify
      that the symbol doesn't contain it.  */
-  for (unsigned i = 0; i != sizeof attrs / sizeof *attrs; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
     {
       if (!attrs[i])
 	continue;
@@ -2106,7 +2106,7 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
   };
 
   for (unsigned i = 0; i != 2; ++i)
-    for (unsigned j = 0; j != sizeof whitelist / sizeof *whitelist; ++j)
+    for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
       if (lookup_attribute (whitelist[j], tmpl_attrs[i])
 	  || lookup_attribute (whitelist[j], decl_attrs[i]))
 	return 0;
diff --git a/gcc/builtins.cc b/gcc/builtins.cc
index 5b085e3a14f..2548ce43910 100644
--- a/gcc/builtins.cc
+++ b/gcc/builtins.cc
@@ -613,7 +613,7 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize)
   if (eltsize != tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src)))))
     return NULL_TREE;
 
-  /* Set MAXELTS to sizeof (SRC) / sizeof (*SRC) - 1, the maximum possible
+  /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
      length of SRC.  Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
      in case the latter is less than the size of the array, such as when
      SRC refers to a short string literal used to initialize a large array.
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index b1953a45f9b..67a8e3dc965 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -4941,8 +4941,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags,
   int imode;
 
   {
-    const int nmodes =
-      sizeof attr_access::mode_names / sizeof *attr_access::mode_names;
+    const int nmodes = ARRAY_SIZE (attr_access::mode_names);
 
     for (imode = 0; imode != nmodes; ++imode)
       if (!strncmp (ps, attr_access::mode_names[imode],
diff --git a/gcc/c-family/c-common.cc b/gcc/c-family/c-common.cc
index 730faa9e87f..ed5d25e5d11 100644
--- a/gcc/c-family/c-common.cc
+++ b/gcc/c-family/c-common.cc
@@ -602,8 +602,7 @@ const struct c_common_resword c_common_reswords[] =
   { "null_resettable",	RID_NULL_RESETTABLE,	D_OBJC },
 };
 
-const unsigned int num_c_common_reswords =
-  sizeof c_common_reswords / sizeof (struct c_common_resword);
+const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
 
 /* Return identifier for address space AS.  */
 
@@ -4482,9 +4481,7 @@ c_common_nodes_and_builtins (void)
 
   /* Make fileptr_type_node a distinct void * type until
      FILE type is defined.  Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node
       = build_variant_type_copy (builtin_structptr_types[i].base);
 
diff --git a/gcc/c-family/c-format.cc b/gcc/c-family/c-format.cc
index 98f28c0dcc6..57dba9b3a6d 100644
--- a/gcc/c-family/c-format.cc
+++ b/gcc/c-family/c-format.cc
@@ -3195,7 +3195,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
   else
     {
       /* Diagnose some common misspellings.  */
-      for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
+      for (unsigned i = 0; i != ARRAY_SIZE (badwords); ++i)
 	{
 	  unsigned badwlen = strspn (badwords[i].name, " -");
 	  if (wlen >= badwlen
@@ -3390,14 +3390,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISPUNCT (format_chars[0]))
     {
-      size_t nelts = sizeof c_opers / sizeof *c_opers;
+      size_t nelts = ARRAY_SIZE (c_opers);
       if (const char *ret = check_tokens (c_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_opers / sizeof *cxx_opers : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_opers) : 0;
       if (const char *ret = check_tokens (cxx_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3407,14 +3407,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISALPHA (format_chars[0]))
     {
-      size_t nelts = sizeof c_keywords / sizeof *c_keywords;
+      size_t nelts = ARRAY_SIZE (c_keywords);
       if (const char *ret = check_tokens (c_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_keywords / sizeof *cxx_keywords : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_keywords) : 0;
       if (const char *ret = check_tokens (cxx_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3533,7 +3533,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 	  && ISALPHA (format_chars[1]))
 	{
 	  /* Diagnose a subset of contractions that are best avoided.  */
-	  for (unsigned i = 0; i != sizeof contrs / sizeof *contrs; ++i)
+	  for (unsigned i = 0; i != ARRAY_SIZE (contrs); ++i)
 	    {
 	      const char *apos = strchr (contrs[i].name, '\'');
 	      gcc_assert (apos != NULL);
diff --git a/gcc/c-family/c-pragma.cc b/gcc/c-family/c-pragma.cc
index 4c80bdd26d6..cc05b2580fa 100644
--- a/gcc/c-family/c-pragma.cc
+++ b/gcc/c-family/c-pragma.cc
@@ -1400,8 +1400,8 @@ static const struct omp_pragma_def omp_pragmas_simd[] = {
 void
 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
 {
-  const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
-  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+  const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+  const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
   const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
 				 / sizeof (*omp_pragmas);
   int i;
@@ -1576,8 +1576,7 @@ init_pragma (void)
 {
   if (flag_openacc)
     {
-      const int n_oacc_pragmas
-	= sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
+      const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
       int i;
 
       for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1587,7 +1586,7 @@ init_pragma (void)
 
   if (flag_openmp)
     {
-      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+      const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
       int i;
 
       for (i = 0; i < n_omp_pragmas; ++i)
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 8ad3eb3f466..01c86b27dc8 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -79,8 +79,7 @@ get_string_macro_hint (const char *name, enum stdlib lib)
   if ((lib == STDLIB_C && flag_isoc99)
       || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
     {
-      const size_t num_c99_cxx11_macros
-	= sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+      const size_t num_c99_cxx11_macros = ARRAY_SIZE (c99_cxx11_macros);
       for (size_t i = 0; i < num_c99_cxx11_macros; i++)
 	if (strcmp (name, c99_cxx11_macros[i]) == 0)
 	  return lib == STDLIB_C ? "<inttypes.h>" : "<cinttypes>";
@@ -204,7 +203,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
     {"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     if (strcmp (name, hints[i].name) == 0)
       return hints[i].header[lib];
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc
index c701f07befe..e49879ab286 100644
--- a/gcc/c/c-decl.cc
+++ b/gcc/c/c-decl.cc
@@ -1658,7 +1658,7 @@ c_bind (location_t loc, tree decl, bool is_global)
    Used only by match_builtin_function_types.  */
 
 static const unsigned builtin_structptr_type_count
-  = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  = ARRAY_SIZE (builtin_structptr_types);
 
 static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
 
@@ -1705,10 +1705,8 @@ match_builtin_function_types (tree newtype, tree oldtype,
   tree newargs = TYPE_ARG_TYPES (newtype);
   tree tryargs = newargs;
 
-  const unsigned nlst
-    = sizeof last_structptr_types / sizeof last_structptr_types[0];
-  const unsigned nbst
-    = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  const unsigned nlst = ARRAY_SIZE (last_structptr_types);
+  const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
 
   gcc_checking_assert (nlst == nbst);
 
diff --git a/gcc/cfg.cc b/gcc/cfg.cc
index da781ba2da8..bbd01ba21bb 100644
--- a/gcc/cfg.cc
+++ b/gcc/cfg.cc
@@ -787,7 +787,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags,
       NULL
 #undef DEF_BASIC_BLOCK_FLAG
     };
-  const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  const unsigned n_bitnames = ARRAY_SIZE (bb_bitnames);
   bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
diff --git a/gcc/common/config/aarch64/aarch64-common.cc b/gcc/common/config/aarch64/aarch64-common.cc
index dfda5b8372a..7fac90d313b 100644
--- a/gcc/common/config/aarch64/aarch64-common.cc
+++ b/gcc/common/config/aarch64/aarch64-common.cc
@@ -314,8 +314,7 @@ aarch64_option_init_struct (struct gcc_options *opts ATTRIBUTE_UNUSED)
        pop and attribute change (arm_neon headers, lto etc all cause this to
        happen quite frequently).  It is a trade-off between time and space and
        so time won.  */
-    int n_extensions
-      = sizeof (all_extensions) / sizeof (struct aarch64_option_extension);
+    int n_extensions = ARRAY_SIZE (all_extensions);
     qsort (&all_extensions_by_on, n_extensions,
 	   sizeof (struct aarch64_option_extension), opt_ext_cmp);
 }
diff --git a/gcc/config/aarch64/aarch64-builtins.cc b/gcc/config/aarch64/aarch64-builtins.cc
index c21476d7ae9..e0a741ac663 100644
--- a/gcc/config/aarch64/aarch64-builtins.cc
+++ b/gcc/config/aarch64/aarch64-builtins.cc
@@ -832,7 +832,7 @@ aarch64_lookup_simd_builtin_type (machine_mode mode,
 				  enum aarch64_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -869,7 +869,7 @@ static void
 aarch64_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
@@ -1434,7 +1434,7 @@ aarch64_init_builtin_rsqrt (void)
   };
 
   builtin_decls_data *bdd = bdda;
-  builtin_decls_data *bdd_end = bdd + (sizeof (bdda) / sizeof (builtin_decls_data));
+  builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda));
 
   for (; bdd < bdd_end; bdd++)
   {
diff --git a/gcc/config/aarch64/aarch64.cc b/gcc/config/aarch64/aarch64.cc
index f650abbc4ce..6f2f5d27ddc 100644
--- a/gcc/config/aarch64/aarch64.cc
+++ b/gcc/config/aarch64/aarch64.cc
@@ -20755,7 +20755,7 @@ is_madd_op (enum attr_type t1)
     TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
   };
 
-  for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
+  for (i = 0; i < ARRAY_SIZE (mlatypes); i++)
     {
       if (t1 == mlatypes[i])
 	return true;
diff --git a/gcc/config/arm/arm-builtins.cc b/gcc/config/arm/arm-builtins.cc
index 36a40a1dc80..d917137e5ee 100644
--- a/gcc/config/arm/arm-builtins.cc
+++ b/gcc/config/arm/arm-builtins.cc
@@ -1471,7 +1471,7 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 			      enum arm_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -1503,7 +1503,7 @@ static void
 arm_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
   tree tdecl;
 
   /* Poly types are a world of their own.  In order to maintain legacy
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.cc b/gcc/config/avr/gen-avr-mmcu-texi.cc
index d9c3a30877d..a44e18e4c35 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.cc
+++ b/gcc/config/avr/gen-avr-mmcu-texi.cc
@@ -23,10 +23,12 @@
 
 #define IN_GEN_AVR_MMCU_TEXI
 
+#define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
+
 #include "avr-devices.cc"
 
 static const avr_mcu_t*
-mcus[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
+mcus[ARRAY_SIZE (avr_mcu_types)];
 
 static int letter (char c)
 {
@@ -56,7 +58,7 @@ c_prefix (const char *str)
       "attiny", "atmega", "atxmega", "ata", "at90"
     };
 
-  int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
+  int i, n = (int) (ARRAY_SIZE (prefixes));
 
   for (i = 0; i < n; i++)
     if (str_prefix_p (str, prefixes[i]))
@@ -185,7 +187,7 @@ int main (void)
 	  print_mcus (n_mcus);
 	  n_mcus = 0;
 
-	  for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
+	  for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
 	    if (arch_id == avr_texinfo[i].arch_id)
 	      printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
 	}
diff --git a/gcc/config/c6x/c6x.cc b/gcc/config/c6x/c6x.cc
index 7fe18d69c7f..dc01a6e47c4 100644
--- a/gcc/config/c6x/c6x.cc
+++ b/gcc/config/c6x/c6x.cc
@@ -2580,7 +2580,7 @@ static unsigned reg_save_order[] =
   REG_B14, REG_A15
 };
 
-#define N_SAVE_ORDER (sizeof reg_save_order / sizeof *reg_save_order)
+#define N_SAVE_ORDER (ARRAY_SIZE (reg_save_order))
 
 /* Compute the layout of the stack frame and store it in FRAME.  */
 
diff --git a/gcc/config/darwin-c.cc b/gcc/config/darwin-c.cc
index 3770857aa42..9203c84d2c2 100644
--- a/gcc/config/darwin-c.cc
+++ b/gcc/config/darwin-c.cc
@@ -505,7 +505,7 @@ darwin_register_frameworks (const char *sysroot,
       size_t i;
 
       /* Setup default search path for frameworks.  */
-      for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
+      for (i = 0; i < ARRAY_SIZE (framework_defaults); ++i)
 	{
 	  char *str;
 	  if (sysroot)
diff --git a/gcc/config/gcn/mkoffload.cc b/gcc/config/gcn/mkoffload.cc
index 94ba7ffa5af..9db2124b129 100644
--- a/gcc/config/gcn/mkoffload.cc
+++ b/gcc/config/gcn/mkoffload.cc
@@ -723,7 +723,7 @@ process_obj (FILE *in, FILE *cfile)
 	   "  unsigned global_variable_count;\n"
 	   "} target_data = {\n"
 	   "  &gcn_image,\n"
-	   "  sizeof (gcn_kernels) / sizeof (gcn_kernels[0]),\n"
+	   "  ARRAY_SIZE (gcn_kernels),\n"
 	   "  gcn_kernels,\n"
 	   "  gcn_num_vars\n"
 	   "};\n\n");
diff --git a/gcc/config/i386/i386-builtins.cc b/gcc/config/i386/i386-builtins.cc
index 8c6d0fe9631..0ea0eee5624 100644
--- a/gcc/config/i386/i386-builtins.cc
+++ b/gcc/config/i386/i386-builtins.cc
@@ -1936,8 +1936,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
 
   enum feature_priority priority = P_NONE;
 
-  static unsigned int NUM_FEATURES
-    = sizeof (isa_names_table) / sizeof (_isa_names_table);
+  static unsigned int NUM_FEATURES = ARRAY_SIZE (isa_names_table);
 
   unsigned int i;
 
@@ -2290,8 +2289,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
       tree final;
 
       unsigned int field_val = 0;
-      unsigned int NUM_ISA_NAMES
-	= sizeof (isa_names_table) / sizeof (struct _isa_names_table);
+      unsigned int NUM_ISA_NAMES = ARRAY_SIZE (isa_names_table);
 
       for (i = 0; i < NUM_ISA_NAMES; i++)
 	if (strcmp (isa_names_table[i].name,
diff --git a/gcc/config/m32c/m32c.cc b/gcc/config/m32c/m32c.cc
index 11ca9a43a0b..5a19faa063c 100644
--- a/gcc/config/m32c/m32c.cc
+++ b/gcc/config/m32c/m32c.cc
@@ -1090,7 +1090,7 @@ static struct
   { FB_REGNO, 0x01, 2, 4 }
 };
 
-#define PUSHM_N (sizeof(pushm_info)/sizeof(pushm_info[0]))
+#define PUSHM_N (ARRAY_SIZE (pushm_info))
 
 /* Returns TRUE if we need to save/restore the given register.  We
    save everything for exception handlers, so that any register can be
diff --git a/gcc/config/nvptx/mkoffload.cc b/gcc/config/nvptx/mkoffload.cc
index b28c1a32292..fa3b4b76821 100644
--- a/gcc/config/nvptx/mkoffload.cc
+++ b/gcc/config/nvptx/mkoffload.cc
@@ -316,11 +316,11 @@ process (FILE *in, FILE *out)
 	   "  const struct nvptx_fn *fn_names;\n"
 	   "  unsigned fn_num;\n"
 	   "} target_data = {\n"
-	   "  ptx_objs, sizeof (ptx_objs) / sizeof (ptx_objs[0]),\n"
+	   "  ptx_objs, ARRAY_SIZE (ptx_objs),\n"
 	   "  var_mappings,"
-	   "  sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+	   "  ARRAY_SIZE (var_mappings),\n"
 	   "  func_mappings,"
-	   "  sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+	   "  ARRAY_SIZE (func_mappings)\n"
 	   "};\n\n");
 
   fprintf (out, "#ifdef __cplusplus\n"
diff --git a/gcc/config/rs6000/driver-rs6000.cc b/gcc/config/rs6000/driver-rs6000.cc
index ec890e0db3a..b871f0a36a8 100644
--- a/gcc/config/rs6000/driver-rs6000.cc
+++ b/gcc/config/rs6000/driver-rs6000.cc
@@ -599,7 +599,7 @@ host_detect_local_cpu (int argc, const char **argv)
 
   if (assembler)
     {
-      for (i = 0; i < sizeof (asm_names) / sizeof (asm_names[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (asm_names); i++)
 	{
 	  if (!asm_names[i].cpu || !strcmp (asm_names[i].cpu, cpu))
 	    return asm_names[i].asm_sw;
diff --git a/gcc/config/s390/s390.cc b/gcc/config/s390/s390.cc
index 7c3bd6cbe7f..90ca50515a7 100644
--- a/gcc/config/s390/s390.cc
+++ b/gcc/config/s390/s390.cc
@@ -8768,7 +8768,7 @@ static machine_mode constant_modes[] =
   QImode,
   V1QImode
 };
-#define NR_C_MODES (sizeof (constant_modes) / sizeof (constant_modes[0]))
+#define NR_C_MODES (ARRAY_SIZE (constant_modes))
 
 struct constant
 {
diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index c9649fb9c70..798766a723b 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -462,7 +462,7 @@ find_sequences (ExpressionTree &s, ExpressionTreeMap &best_solution)
   const Operator *const prev_op = s.m_exprs[num_vals - 1].m_op;
   const int prev_top_index = (prev_op != NULL) ? prev_op->m_top_index : -1;
 
-  for (size_t f = 0; f < sizeof ops / sizeof ops[0]; f++)
+  for (size_t f = 0; f < ARRAY_SIZE (ops); f++)
     {
       const Operator *const op = &ops[f];
 
@@ -564,7 +564,7 @@ create_insn_code_compression_table ()
   printf ("const enum insn_code %s_multiply_insn_seq_decode_opcode[] = {\n"
 	  "  CODE_FOR_nothing /* must be first */ ", ARCH);
 
-  for (size_t i = 0; i < sizeof ops / sizeof ops[0]; i++)
+  for (size_t i = 0; i < ARRAY_SIZE (ops); i++)
     {
       Operator *op = &ops[i];
       int index = -1;
diff --git a/gcc/config/vms/vms.cc b/gcc/config/vms/vms.cc
index 5d565e35fb4..d0d44bad2ce 100644
--- a/gcc/config/vms/vms.cc
+++ b/gcc/config/vms/vms.cc
@@ -99,7 +99,7 @@ static const struct vms_crtl_name vms_crtl_names[] =
 
 /* Number of entires in the above array.  */
 
-#define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
+#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names))
 
 /* List of aliased identifiers.  They must be persistent across gc.  */
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 18dabfcc9ac..f0f57b1c690 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2615,7 +2615,7 @@ depset::entity_kind_name () const
     {"decl", "specialization", "partial", "using",
      "namespace", "redirect", "binding"};
   entity_kind kind = get_entity_kind ();
-  gcc_checking_assert (kind < sizeof (names) / sizeof(names[0]));
+  gcc_checking_assert (kind < ARRAY_SIZE (names));
   return names[kind];
 }
 
diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc
index 7b0638d3166..05f29cebac2 100644
--- a/gcc/cp/name-lookup.cc
+++ b/gcc/cp/name-lookup.cc
@@ -6915,7 +6915,7 @@ get_std_name_hint (const char *name)
     /* <vector>.  */
     {"vector", "<vector>", cxx98},
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     {
       if (strcmp (name, hints[i].name) == 0)
diff --git a/gcc/cp/parser.cc b/gcc/cp/parser.cc
index b52cbe18b9a..3ff81a8a086 100644
--- a/gcc/cp/parser.cc
+++ b/gcc/cp/parser.cc
@@ -4200,7 +4200,7 @@ cp_parser_new (cp_lexer *lexer)
 {
   /* Initialize the binops_by_token so that we can get the tree
      directly from the token.  */
-  for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (binops); i++)
     binops_by_token[binops[i].token_type] = binops[i];
 
   cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index def371816e6..62594ebb4d7 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -62,7 +62,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
     {"byte-column", DIAGNOSTICS_COLUMN_UNIT_BYTE}
   };
   int the_column = INT_MIN;
-  for (int i = 0; i != sizeof column_fields / sizeof (*column_fields); ++i)
+  for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
     {
       context->column_unit = column_fields[i].unit;
       const int col = diagnostic_converted_column (context, exploc);
diff --git a/gcc/dwarf2out.cc b/gcc/dwarf2out.cc
index 5681b01749a..4ef644c5fae 100644
--- a/gcc/dwarf2out.cc
+++ b/gcc/dwarf2out.cc
@@ -13532,8 +13532,7 @@ static const dwarf_qual_info_t dwarf_qual_info[] =
   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
 };
-static const unsigned int dwarf_qual_info_size
-  = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
+static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
 
 /* If DIE is a qualified DIE of some base DIE with the same parent,
    return the base DIE, otherwise return NULL.  Set MASK to the
diff --git a/gcc/fortran/frontend-passes.cc b/gcc/fortran/frontend-passes.cc
index 5eba6345145..612c12d233d 100644
--- a/gcc/fortran/frontend-passes.cc
+++ b/gcc/fortran/frontend-passes.cc
@@ -5654,9 +5654,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 		  WALK_SUBEXPR (co->ext.omp_clauses->detach);
 		  for (idx = 0; idx < OMP_IF_LAST; idx++)
 		    WALK_SUBEXPR (co->ext.omp_clauses->if_exprs[idx]);
-		  for (idx = 0;
-		       idx < sizeof (list_types) / sizeof (list_types[0]);
-		       idx++)
+		  for (idx = 0; idx < ARRAY_SIZE (list_types); idx++)
 		    for (n = co->ext.omp_clauses->lists[list_types[idx]];
 			 n; n = n->next)
 		      WALK_SUBEXPR (n->expr);
diff --git a/gcc/fortran/openmp.cc b/gcc/fortran/openmp.cc
index 714148138c2..5b3d0bd0709 100644
--- a/gcc/fortran/openmp.cc
+++ b/gcc/fortran/openmp.cc
@@ -4902,8 +4902,7 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
       match m;
       const char *selector_sets[] = { "construct", "device",
 				      "implementation", "user" };
-      const int selector_set_count
-	= sizeof (selector_sets) / sizeof (*selector_sets);
+      const int selector_set_count = ARRAY_SIZE (selector_sets);
       int i;
       char buf[GFC_MAX_SYMBOL_LEN + 1];
 
diff --git a/gcc/fortran/trans-intrinsic.cc b/gcc/fortran/trans-intrinsic.cc
index 2249723540d..6884060fd6f 100644
--- a/gcc/fortran/trans-intrinsic.cc
+++ b/gcc/fortran/trans-intrinsic.cc
@@ -9784,7 +9784,7 @@ conv_intrinsic_ieee_builtin (gfc_se * se, gfc_expr * expr,
 			     enum built_in_function code, int nargs)
 {
   tree args[2];
-  gcc_assert ((unsigned) nargs <= sizeof(args)/sizeof(args[0]));
+  gcc_assert ((unsigned) nargs <= ARRAY_SIZE (args));
 
   conv_ieee_function_args (se, expr, args, nargs);
   se->expr = build_call_expr_loc_array (input_location,
diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index 3cdc529eb28..3742bf312cd 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -3420,7 +3420,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
     }
 
   rank = GFC_TYPE_ARRAY_RANK (type);
-  if (rank >= (int) (sizeof (info->dimen) / sizeof (info->dimen[0])))
+  if (rank >= (int) (ARRAY_SIZE (info->dimen)))
     return false;
 
   etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
diff --git a/gcc/genhooks.cc b/gcc/genhooks.cc
index 20ad607b158..6bae85d7b8d 100644
--- a/gcc/genhooks.cc
+++ b/gcc/genhooks.cc
@@ -128,7 +128,7 @@ emit_documentation (const char *in_fname)
     }
   fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
     {
       struct s_hook sh, *shp;
       void *p;
@@ -223,7 +223,7 @@ emit_documentation (const char *in_fname)
 	      /* POD-valued hooks sometimes come in groups with common
 		 documentation.*/
 	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
+		   j < (int) (ARRAY_SIZE (hook_array))
 		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
 		{
 		  char *namex = upstrdup (hook_array[j].name);
@@ -246,8 +246,7 @@ emit_documentation (const char *in_fname)
 		  printf ("\n@end %s", deftype);
 		}
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
+	  if (++i >= (int) (ARRAY_SIZE (hook_array)) || !hook_array[i].doc)
 	    break;
 	  free (name);
 	  sh.name = name = upstrdup (hook_array[i].name);
@@ -270,7 +269,7 @@ emit_init_macros (const char *docname)
 
   for (print_nest = 0; print_nest <= MAX_NEST; print_nest++)
     {
-      for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+      for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
 	{
 	  char *name = upstrdup (hook_array[i].name);
 
diff --git a/gcc/gimple-ssa-sprintf.cc b/gcc/gimple-ssa-sprintf.cc
index 9a84fffed1a..eb05be8c0ed 100644
--- a/gcc/gimple-ssa-sprintf.cc
+++ b/gcc/gimple-ssa-sprintf.cc
@@ -1953,7 +1953,7 @@ format_floating (const directive &dir, tree arg, pointer_query &)
       &res.range.min, &res.range.max
     };
 
-    for (int i = 0; i != sizeof minmax / sizeof *minmax; ++i)
+    for (int i = 0; i != ARRAY_SIZE (minmax); ++i)
       {
 	/* Convert the GCC real value representation with the precision
 	   of the real type to the mpfr_t format rounding down in the
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index 39aa8186de6..ec458b0c0d3 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2853,7 +2853,7 @@ memmodel_name (unsigned HOST_WIDE_INT val)
 {
   val = memmodel_base (val);
 
-  for (unsigned i = 0; i != sizeof memory_models / sizeof *memory_models; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (memory_models); ++i)
     {
       if (val == memory_models[i].modval)
 	return memory_models[i].modname;
diff --git a/gcc/godump.cc b/gcc/godump.cc
index 669168806f3..2ae0bcc9672 100644
--- a/gcc/godump.cc
+++ b/gcc/godump.cc
@@ -1326,7 +1326,7 @@ static void
 keyword_hash_init (class godump_container *container)
 {
   size_t i;
-  size_t count = sizeof (keywords) / sizeof (keywords[0]);
+  size_t count = ARRAY_SIZE (keywords);
   void **slot;
 
   for (i = 0; i < count; i++)
diff --git a/gcc/hash-table.cc b/gcc/hash-table.cc
index dad1d21f099..1015c1ee6e9 100644
--- a/gcc/hash-table.cc
+++ b/gcc/hash-table.cc
@@ -84,7 +84,7 @@ unsigned int
 hash_table_higher_prime_index (unsigned long n)
 {
   unsigned int low = 0;
-  unsigned int high = sizeof (prime_tab) / sizeof (prime_tab[0]);
+  unsigned int high = ARRAY_SIZE (prime_tab);
 
   while (low != high)
     {
diff --git a/gcc/input.cc b/gcc/input.cc
index b3970613d81..58beba05072 100644
--- a/gcc/input.cc
+++ b/gcc/input.cc
@@ -3724,8 +3724,7 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
     {
       /* ...and use each of the "interesting" location values as
 	 the starting location within line_table.  */
-      const int num_boundary_locations
-	= sizeof (boundary_locations) / sizeof (boundary_locations[0]);
+      const int num_boundary_locations = ARRAY_SIZE (boundary_locations);
       for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++)
 	{
 	  line_table_case c (default_range_bits, boundary_locations[loc_idx]);
diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index a742156858c..f99f7be1c58 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -1109,9 +1109,7 @@ free_lang_data (void)
   free_lang_data_in_cgraph (&fld);
 
   /* Create gimple variants for common types.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
diff --git a/gcc/ipa-inline.cc b/gcc/ipa-inline.cc
index f8bb072c422..22a009b7435 100644
--- a/gcc/ipa-inline.cc
+++ b/gcc/ipa-inline.cc
@@ -278,7 +278,7 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
       SANITIZE_POINTER_SUBTRACT
     };
 
-  for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (codes); i++)
     if (sanitize_flags_p (codes[i], caller)
 	!= sanitize_flags_p (codes[i], callee))
       return false;
diff --git a/gcc/jit/jit-builtins.cc b/gcc/jit/jit-builtins.cc
index b949b734332..fb86c77d0fe 100644
--- a/gcc/jit/jit-builtins.cc
+++ b/gcc/jit/jit-builtins.cc
@@ -109,9 +109,7 @@ find_builtin_by_name (const char *in_name,
 
      We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
      has a NULL name.  */
-  for (unsigned int i = 1;
-       i < sizeof (builtin_data) / sizeof (builtin_data[0]);
-       i++)
+  for (unsigned int i = 1; i < ARRAY_SIZE (builtin_data); i++)
     {
       const struct builtin_data& bd = builtin_data[i];
       if (matches_builtin (in_name, bd))
@@ -320,7 +318,7 @@ static const char * const type_names[] = {
 static const char *
 get_string_for_type_id (enum jit_builtin_type type_id)
 {
-  gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0]));
+  gcc_assert (type_id < ARRAY_SIZE (type_names));
   return type_names[type_id];
 }
 
diff --git a/gcc/jit/jit-recording.cc b/gcc/jit/jit-recording.cc
index a31720f043e..4305a961489 100644
--- a/gcc/jit/jit-recording.cc
+++ b/gcc/jit/jit-recording.cc
@@ -568,9 +568,7 @@ recording::context::context (context *parent_ctxt)
   if (parent_ctxt)
     {
       /* Inherit options from parent.  */
-      for (unsigned i = 0;
-	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
-	   i++)
+      for (unsigned i = 0; i < ARRAY_SIZE (m_str_options); i++)
 	{
 	  const char *parent_opt = parent_ctxt->m_str_options[i];
 	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
diff --git a/gcc/lto/lto-common.cc b/gcc/lto/lto-common.cc
index ca28586a1e8..d8d0404c54e 100644
--- a/gcc/lto/lto-common.cc
+++ b/gcc/lto/lto-common.cc
@@ -2104,8 +2104,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
       char r_str[27];
       enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
       unsigned int j;
-      unsigned int lto_resolution_str_len
-	= sizeof (lto_resolution_str) / sizeof (char *);
+      unsigned int lto_resolution_str_len = ARRAY_SIZE (lto_resolution_str);
       res_pair rp;
 
       t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE
diff --git a/gcc/lto/lto-lang.cc b/gcc/lto/lto-lang.cc
index 8d58d924dff..972a0336f75 100644
--- a/gcc/lto/lto-lang.cc
+++ b/gcc/lto/lto-lang.cc
@@ -1319,9 +1319,7 @@ lto_init (void)
      distinction should only be relevant to the front-end, so we
      always use the C definition here in lto1.
      Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     {
       gcc_assert (builtin_structptr_types[i].node
 		  == builtin_structptr_types[i].base);
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 9911bab6668..233d1fbb637 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1104,7 +1104,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 	print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 	print "      return false;"
 }
@@ -1152,7 +1152,7 @@ for (i = 0; i < n_target_val; i++) {
 	print "  hstate.add_hwi (ptr->" name");";
 }
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 }
 
@@ -1192,7 +1192,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 }
 
@@ -1235,7 +1235,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 }
 
@@ -1317,7 +1317,7 @@ for (i = 0; i < n_opt_val; i++) {
 	else
 		print "  hstate.add_hwi (ptr->" name");";
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 print "  return hstate.end ();";
 print "}";
@@ -1346,7 +1346,7 @@ for (i = 0; i < n_opt_val; i++) {
 		print "    return false;";
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 print "      return false;"
 print "  return true;";
@@ -1380,7 +1380,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 print "}";
 
@@ -1412,7 +1412,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 print "}";
 print "/* Free heap memory used by optimization options  */";
diff --git a/gcc/spellcheck.cc b/gcc/spellcheck.cc
index 3e58344f510..c7bb0122545 100644
--- a/gcc/spellcheck.cc
+++ b/gcc/spellcheck.cc
@@ -489,7 +489,7 @@ static const char * const test_data[] = {
 static void
 test_metric_conditions ()
 {
-  const int num_test_cases = sizeof (test_data) / sizeof (test_data[0]);
+  const int num_test_cases = ARRAY_SIZE (test_data);
 
   for (int i = 0; i < num_test_cases; i++)
     {
diff --git a/gcc/tree-vect-slp-patterns.cc b/gcc/tree-vect-slp-patterns.cc
index 879d17fd947..a6b0d106d5f 100644
--- a/gcc/tree-vect-slp-patterns.cc
+++ b/gcc/tree-vect-slp-patterns.cc
@@ -1637,4 +1637,4 @@ vect_pattern_decl_t slp_patterns[]
 #undef SLP_PATTERN
 
 /* Set the number of SLP pattern matchers available.  */
-size_t num__slp_patterns = sizeof(slp_patterns)/sizeof(vect_pattern_decl_t);
+size_t num__slp_patterns = ARRAY_SIZE (slp_patterns);
diff --git a/gcc/tree.cc b/gcc/tree.cc
index 5e8876d2b38..df441c6b223 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -9408,9 +9408,7 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE.
@ 2022-01-13 17:59 Martin Liska
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Liska @ 2022-01-13 17:59 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:81fe381150bb36e0bb013cdefe57b086f379cb5d

commit 81fe381150bb36e0bb013cdefe57b086f379cb5d
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 13 18:46:26 2022 +0100

    Use more ARRAY_SIZE.

Diff:
---
 gcc/ada/locales.c                          |  6 +++---
 gcc/analyzer/engine.cc                     |  2 +-
 gcc/analyzer/function-set.cc               |  2 +-
 gcc/analyzer/sm-file.cc                    |  3 +--
 gcc/analyzer/sm-malloc.cc                  |  3 +--
 gcc/analyzer/sm-signal.cc                  |  3 +--
 gcc/attribs.c                              |  4 ++--
 gcc/builtins.c                             |  2 +-
 gcc/c-family/c-attribs.c                   |  3 +--
 gcc/c-family/c-common.c                    |  7 ++-----
 gcc/c-family/c-format.c                    | 12 ++++++------
 gcc/c-family/c-pragma.c                    |  9 ++++-----
 gcc/c-family/c-warn.c                      |  2 +-
 gcc/c-family/known-headers.cc              |  5 ++---
 gcc/c/c-decl.c                             |  8 +++-----
 gcc/cfg.c                                  |  2 +-
 gcc/common/config/aarch64/aarch64-common.c |  3 +--
 gcc/config/aarch64/aarch64-builtins.c      |  6 +++---
 gcc/config/aarch64/aarch64.c               |  2 +-
 gcc/config/arm/arm-builtins.c              |  4 ++--
 gcc/config/avr/gen-avr-mmcu-texi.c         |  6 +++---
 gcc/config/c6x/c6x.c                       |  2 +-
 gcc/config/darwin-c.c                      |  2 +-
 gcc/config/gcn/mkoffload.c                 |  2 +-
 gcc/config/i386/i386-builtins.c            |  6 ++----
 gcc/config/m32c/m32c.c                     |  2 +-
 gcc/config/nvptx/mkoffload.c               |  6 +++---
 gcc/config/rs6000/driver-rs6000.c          |  2 +-
 gcc/config/rs6000/rs6000.c                 |  2 +-
 gcc/config/s390/s390.c                     |  2 +-
 gcc/config/tilepro/gen-mul-tables.cc       |  4 ++--
 gcc/config/vms/vms.c                       |  2 +-
 gcc/cp/module.cc                           |  2 +-
 gcc/cp/name-lookup.c                       |  2 +-
 gcc/cp/parser.c                            |  2 +-
 gcc/d/longdouble.h                         |  2 +-
 gcc/diagnostic-format-json.cc              |  2 +-
 gcc/dwarf2out.c                            |  3 +--
 gcc/fortran/frontend-passes.c              |  4 +---
 gcc/fortran/openmp.c                       |  3 +--
 gcc/fortran/trans-intrinsic.c              |  2 +-
 gcc/fortran/trans-types.c                  |  2 +-
 gcc/genautomata.c                          |  4 ++--
 gcc/genhooks.c                             |  9 ++++-----
 gcc/gimple-ssa-sprintf.c                   |  2 +-
 gcc/gimple-ssa-warn-access.cc              |  2 +-
 gcc/godump.c                               |  2 +-
 gcc/hash-table.c                           |  2 +-
 gcc/input.c                                |  3 +--
 gcc/ipa-free-lang-data.cc                  |  4 +---
 gcc/ipa-inline.c                           |  2 +-
 gcc/jit/jit-builtins.c                     |  6 ++----
 gcc/jit/jit-recording.c                    |  4 +---
 gcc/lto/lto-common.c                       |  3 +--
 gcc/lto/lto-lang.c                         |  4 +---
 gcc/optc-save-gen.awk                      | 16 ++++++++--------
 gcc/spellcheck.c                           |  2 +-
 gcc/sreal.c                                |  4 ++--
 gcc/tree-vect-slp-patterns.c               |  2 +-
 gcc/tree.c                                 |  4 +---
 60 files changed, 97 insertions(+), 128 deletions(-)

diff --git a/gcc/ada/locales.c b/gcc/ada/locales.c
index ee1385a6bdc..2aaa2121a50 100644
--- a/gcc/ada/locales.c
+++ b/gcc/ada/locales.c
@@ -649,7 +649,7 @@ str_get_last_byte (char *lc_all) {
 
 static char*
 iso_639_1_to_639_3(char* iso_639_1_code) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -673,7 +673,7 @@ iso_639_1_to_639_3(char* iso_639_1_code) {
 
 static char*
 language_name_to_639_3(char* name) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -695,7 +695,7 @@ language_name_to_639_3(char* name) {
 
 static char*
 country_name_to_3166 (char* name) {
-  int len = sizeof(iso_3166)/sizeof(iso_3166[0]);
+  int len = ARRAY_SIZE (iso_3166);
   char **p = iso_3166;
   int j;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 8b6f4c83f0f..80ce8a5c701 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1080,7 +1080,7 @@ exploded_node::get_dot_fillcolor () const
 	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
 	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
 	   "wheat", "seashell"};
-      const int num_colors = sizeof (colors) / sizeof (colors[0]);
+      const int num_colors = ARRAY_SIZE (colors);
       return colors[total_sm_state % num_colors];
     }
   else
diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc
index 8d9237deb63..be04186ed0d 100644
--- a/gcc/analyzer/function-set.cc
+++ b/gcc/analyzer/function-set.cc
@@ -166,7 +166,7 @@ test_stdio_example ()
     "getwc_unlocked",
     "putc_unlocked"
   };
-  const size_t count = sizeof(example) / sizeof (example[0]);
+  const size_t count = ARRAY_SIZE (example);
   function_set fs (example, count);
   fs.assert_sorted ();
   fs.assert_sane ();
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index 1c996f946f6..5940cb939e5 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -319,8 +319,7 @@ get_file_using_fns ()
     "ungetc",
     "vfprintf"
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
   return fs;
 }
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 47184969ffe..cc808a6bcf2 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -2006,8 +2006,7 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl)
     /* This array must be kept sorted.  */
     "strsep",
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
 
   if (fs.contains_decl_p (fndecl))
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 8d3e5ff07b1..3abfa7db605 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -305,8 +305,7 @@ get_async_signal_unsafe_fns ()
     "vsnprintf",
     "vsprintf"
   };
-  const size_t count
-    = sizeof(async_signal_unsafe_fns) / sizeof (async_signal_unsafe_fns[0]);
+  const size_t count = ARRAY_SIZE (async_signal_unsafe_fns);
   function_set fs (async_signal_unsafe_fns, count);
   return fs;
 }
diff --git a/gcc/attribs.c b/gcc/attribs.c
index 189f56a6e48..986e2be4027 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -499,7 +499,7 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
 
   /* Iterate over the mutually exclusive attribute names and verify
      that the symbol doesn't contain it.  */
-  for (unsigned i = 0; i != sizeof attrs / sizeof *attrs; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
     {
       if (!attrs[i])
 	continue;
@@ -2101,7 +2101,7 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
   };
 
   for (unsigned i = 0; i != 2; ++i)
-    for (unsigned j = 0; j != sizeof whitelist / sizeof *whitelist; ++j)
+    for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
       if (lookup_attribute (whitelist[j], tmpl_attrs[i])
 	  || lookup_attribute (whitelist[j], decl_attrs[i]))
 	return 0;
diff --git a/gcc/builtins.c b/gcc/builtins.c
index c780340ed32..f8869cf3808 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -610,7 +610,7 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize)
   if (eltsize != tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src)))))
     return NULL_TREE;
 
-  /* Set MAXELTS to sizeof (SRC) / sizeof (*SRC) - 1, the maximum possible
+  /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
      length of SRC.  Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
      in case the latter is less than the size of the array, such as when
      SRC refers to a short string literal used to initialize a large array.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index bdf72ce385c..1679820bbe9 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -4886,8 +4886,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags,
   int imode;
 
   {
-    const int nmodes =
-      sizeof attr_access::mode_names / sizeof *attr_access::mode_names;
+    const int nmodes = ARRAY_SIZE (attr_access::mode_names);
 
     for (imode = 0; imode != nmodes; ++imode)
       if (!strncmp (ps, attr_access::mode_names[imode],
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a34f32f51a4..594016c12d8 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -602,8 +602,7 @@ const struct c_common_resword c_common_reswords[] =
   { "null_resettable",	RID_NULL_RESETTABLE,	D_OBJC },
 };
 
-const unsigned int num_c_common_reswords =
-  sizeof c_common_reswords / sizeof (struct c_common_resword);
+const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
 
 /* Return identifier for address space AS.  */
 
@@ -4476,9 +4475,7 @@ c_common_nodes_and_builtins (void)
 
   /* Make fileptr_type_node a distinct void * type until
      FILE type is defined.  Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node
       = build_variant_type_copy (builtin_structptr_types[i].base);
 
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index afa77810a5c..52d0b7f6bc8 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -3195,7 +3195,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
   else
     {
       /* Diagnose some common misspellings.  */
-      for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
+      for (unsigned i = 0; i != ARRAY_SIZE (badwords); ++i)
 	{
 	  unsigned badwlen = strspn (badwords[i].name, " -");
 	  if (wlen >= badwlen
@@ -3390,14 +3390,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISPUNCT (format_chars[0]))
     {
-      size_t nelts = sizeof c_opers / sizeof *c_opers;
+      size_t nelts = ARRAY_SIZE (c_opers);
       if (const char *ret = check_tokens (c_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_opers / sizeof *cxx_opers : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_opers) : 0;
       if (const char *ret = check_tokens (cxx_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3407,14 +3407,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISALPHA (format_chars[0]))
     {
-      size_t nelts = sizeof c_keywords / sizeof *c_keywords;
+      size_t nelts = ARRAY_SIZE (c_keywords);
       if (const char *ret = check_tokens (c_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_keywords / sizeof *cxx_keywords : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_keywords) : 0;
       if (const char *ret = check_tokens (cxx_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3533,7 +3533,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 	  && ISALPHA (format_chars[1]))
 	{
 	  /* Diagnose a subset of contractions that are best avoided.  */
-	  for (unsigned i = 0; i != sizeof contrs / sizeof *contrs; ++i)
+	  for (unsigned i = 0; i != ARRAY_SIZE (contrs); ++i)
 	    {
 	      const char *apos = strchr (contrs[i].name, '\'');
 	      gcc_assert (apos != NULL);
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 8dde5b841b2..69eda9582a8 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -1400,8 +1400,8 @@ static const struct omp_pragma_def omp_pragmas_simd[] = {
 void
 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
 {
-  const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
-  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+  const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+  const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
   const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
 				 / sizeof (*omp_pragmas);
   int i;
@@ -1576,8 +1576,7 @@ init_pragma (void)
 {
   if (flag_openacc)
     {
-      const int n_oacc_pragmas
-	= sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
+      const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
       int i;
 
       for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1587,7 +1586,7 @@ init_pragma (void)
 
   if (flag_openmp)
     {
-      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+      const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
       int i;
 
       for (i = 0; i < n_omp_pragmas; ++i)
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 1ce2202c7ff..796912140e3 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -3712,7 +3712,7 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
    to an array and the divisor does not equal the size of the array element.
    For instance:
 
-     sizeof (ARR) / sizeof (OP)
+     ARRAY_SIZE (ARR)
 
    ARR is the array argument of the first sizeof, ARR_TYPE is its ARRAY_TYPE.
    OP1 is the whole second SIZEOF_EXPR, or its argument; TYPE1 is the type
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 8ad3eb3f466..01c86b27dc8 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -79,8 +79,7 @@ get_string_macro_hint (const char *name, enum stdlib lib)
   if ((lib == STDLIB_C && flag_isoc99)
       || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
     {
-      const size_t num_c99_cxx11_macros
-	= sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+      const size_t num_c99_cxx11_macros = ARRAY_SIZE (c99_cxx11_macros);
       for (size_t i = 0; i < num_c99_cxx11_macros; i++)
 	if (strcmp (name, c99_cxx11_macros[i]) == 0)
 	  return lib == STDLIB_C ? "<inttypes.h>" : "<cinttypes>";
@@ -204,7 +203,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
     {"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     if (strcmp (name, hints[i].name) == 0)
       return hints[i].header[lib];
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 29a79eba841..c681174c2d3 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -1658,7 +1658,7 @@ c_bind (location_t loc, tree decl, bool is_global)
    Used only by match_builtin_function_types.  */
 
 static const unsigned builtin_structptr_type_count
-  = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  = ARRAY_SIZE (builtin_structptr_types);
 
 static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
 
@@ -1705,10 +1705,8 @@ match_builtin_function_types (tree newtype, tree oldtype,
   tree newargs = TYPE_ARG_TYPES (newtype);
   tree tryargs = newargs;
 
-  const unsigned nlst
-    = sizeof last_structptr_types / sizeof last_structptr_types[0];
-  const unsigned nbst
-    = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  const unsigned nlst = ARRAY_SIZE (last_structptr_types);
+  const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
 
   gcc_checking_assert (nlst == nbst);
 
diff --git a/gcc/cfg.c b/gcc/cfg.c
index e4ce360bd87..59c48f3baee 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -783,7 +783,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags,
       NULL
 #undef DEF_BASIC_BLOCK_FLAG
     };
-  const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  const unsigned n_bitnames = ARRAY_SIZE (bb_bitnames);
   bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c
index 140e3e78d09..6d17b0e133d 100644
--- a/gcc/common/config/aarch64/aarch64-common.c
+++ b/gcc/common/config/aarch64/aarch64-common.c
@@ -314,8 +314,7 @@ aarch64_option_init_struct (struct gcc_options *opts ATTRIBUTE_UNUSED)
        pop and attribute change (arm_neon headers, lto etc all cause this to
        happen quite frequently).  It is a trade-off between time and space and
        so time won.  */
-    int n_extensions
-      = sizeof (all_extensions) / sizeof (struct aarch64_option_extension);
+    int n_extensions = ARRAY_SIZE (all_extensions);
     qsort (&all_extensions_by_on, n_extensions,
 	   sizeof (struct aarch64_option_extension), opt_ext_cmp);
 }
diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 58bcbd9875f..2d2798602cc 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -831,7 +831,7 @@ aarch64_lookup_simd_builtin_type (machine_mode mode,
 				  enum aarch64_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -868,7 +868,7 @@ static void
 aarch64_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
@@ -1411,7 +1411,7 @@ aarch64_init_builtin_rsqrt (void)
   };
 
   builtin_decls_data *bdd = bdda;
-  builtin_decls_data *bdd_end = bdd + (sizeof (bdda) / sizeof (builtin_decls_data));
+  builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda));
 
   for (; bdd < bdd_end; bdd++)
   {
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1bca2a31a1b..9c2259282f4 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -19782,7 +19782,7 @@ is_madd_op (enum attr_type t1)
     TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
   };
 
-  for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
+  for (i = 0; i < ARRAY_SIZE (mlatypes); i++)
     {
       if (t1 == mlatypes[i])
 	return true;
diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index e6bbda23e3e..05bd527e666 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -1445,7 +1445,7 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 			      enum arm_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -1477,7 +1477,7 @@ static void
 arm_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
   tree tdecl;
 
   /* Poly types are a world of their own.  In order to maintain legacy
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.c b/gcc/config/avr/gen-avr-mmcu-texi.c
index 05b81dd3cb5..34fb3943a62 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.c
+++ b/gcc/config/avr/gen-avr-mmcu-texi.c
@@ -26,7 +26,7 @@
 #include "avr-devices.c"
 
 static const avr_mcu_t*
-mcus[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
+mcus[ARRAY_SIZE (avr_mcu_types);
 
 static int letter (char c)
 {
@@ -56,7 +56,7 @@ c_prefix (const char *str)
       "attiny", "atmega", "atxmega", "ata", "at90"
     };
 
-  int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
+  int i, n = (int) (ARRAY_SIZE (prefixes));
 
   for (i = 0; i < n; i++)
     if (str_prefix_p (str, prefixes[i]))
@@ -185,7 +185,7 @@ int main (void)
 	  print_mcus (n_mcus);
 	  n_mcus = 0;
 
-	  for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
+	  for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
 	    if (arch_id == avr_texinfo[i].arch_id)
 	      printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
 	}
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index 7fe18d69c7f..dc01a6e47c4 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -2580,7 +2580,7 @@ static unsigned reg_save_order[] =
   REG_B14, REG_A15
 };
 
-#define N_SAVE_ORDER (sizeof reg_save_order / sizeof *reg_save_order)
+#define N_SAVE_ORDER (ARRAY_SIZE (reg_save_order))
 
 /* Compute the layout of the stack frame and store it in FRAME.  */
 
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 9f46924408a..58deb01405a 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -505,7 +505,7 @@ darwin_register_frameworks (const char *sysroot,
       size_t i;
 
       /* Setup default search path for frameworks.  */
-      for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
+      for (i = 0; i < ARRAY_SIZE (framework_defaults); ++i)
 	{
 	  char *str;
 	  if (sysroot)
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 92c46899786..0dfc3b2ba86 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -723,7 +723,7 @@ process_obj (FILE *in, FILE *cfile)
 	   "  unsigned global_variable_count;\n"
 	   "} target_data = {\n"
 	   "  &gcn_image,\n"
-	   "  sizeof (gcn_kernels) / sizeof (gcn_kernels[0]),\n"
+	   "  ARRAY_SIZE (gcn_kernels),\n"
 	   "  gcn_kernels,\n"
 	   "  gcn_num_vars\n"
 	   "};\n\n");
diff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
index 2570501ae7e..28bef5a84ea 100644
--- a/gcc/config/i386/i386-builtins.c
+++ b/gcc/config/i386/i386-builtins.c
@@ -1931,8 +1931,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
 
   enum feature_priority priority = P_NONE;
 
-  static unsigned int NUM_FEATURES
-    = sizeof (isa_names_table) / sizeof (_isa_names_table);
+  static unsigned int NUM_FEATURES = ARRAY_SIZE (isa_names_table);
 
   unsigned int i;
 
@@ -2285,8 +2284,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
       tree final;
 
       unsigned int field_val = 0;
-      unsigned int NUM_ISA_NAMES
-	= sizeof (isa_names_table) / sizeof (struct _isa_names_table);
+      unsigned int NUM_ISA_NAMES = ARRAY_SIZE (isa_names_table);
 
       for (i = 0; i < NUM_ISA_NAMES; i++)
 	if (strcmp (isa_names_table[i].name,
diff --git a/gcc/config/m32c/m32c.c b/gcc/config/m32c/m32c.c
index a004790d074..26727000fe1 100644
--- a/gcc/config/m32c/m32c.c
+++ b/gcc/config/m32c/m32c.c
@@ -1090,7 +1090,7 @@ static struct
   { FB_REGNO, 0x01, 2, 4 }
 };
 
-#define PUSHM_N (sizeof(pushm_info)/sizeof(pushm_info[0]))
+#define PUSHM_N (ARRAY_SIZE (pushm_info))
 
 /* Returns TRUE if we need to save/restore the given register.  We
    save everything for exception handlers, so that any register can be
diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c
index b28c1a32292..fa3b4b76821 100644
--- a/gcc/config/nvptx/mkoffload.c
+++ b/gcc/config/nvptx/mkoffload.c
@@ -316,11 +316,11 @@ process (FILE *in, FILE *out)
 	   "  const struct nvptx_fn *fn_names;\n"
 	   "  unsigned fn_num;\n"
 	   "} target_data = {\n"
-	   "  ptx_objs, sizeof (ptx_objs) / sizeof (ptx_objs[0]),\n"
+	   "  ptx_objs, ARRAY_SIZE (ptx_objs),\n"
 	   "  var_mappings,"
-	   "  sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+	   "  ARRAY_SIZE (var_mappings),\n"
 	   "  func_mappings,"
-	   "  sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+	   "  ARRAY_SIZE (func_mappings)\n"
 	   "};\n\n");
 
   fprintf (out, "#ifdef __cplusplus\n"
diff --git a/gcc/config/rs6000/driver-rs6000.c b/gcc/config/rs6000/driver-rs6000.c
index 631054dcfb1..e84eed88f2b 100644
--- a/gcc/config/rs6000/driver-rs6000.c
+++ b/gcc/config/rs6000/driver-rs6000.c
@@ -599,7 +599,7 @@ host_detect_local_cpu (int argc, const char **argv)
 
   if (assembler)
     {
-      for (i = 0; i < sizeof (asm_names) / sizeof (asm_names[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (asm_names); i++)
 	{
 	  if (!asm_names[i].cpu || !strcmp (asm_names[i].cpu, cpu))
 	    return asm_names[i].asm_sw;
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 7759f757908..fcfccc20dd0 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -17014,7 +17014,7 @@ rs6000_hash_constant (rtx k)
 	else
 	  {
 	    size_t i;
-	    for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++)
+	    for (i = 0; i < ARRAY_SIZE (HOST_WIDE_INT); i++)
 	      result = result * 613 + (unsigned) (XWINT (k, fidx)
 						  >> CHAR_BIT * i);
 	  }
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 056002e4a4a..760eb687d23 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -8774,7 +8774,7 @@ static machine_mode constant_modes[] =
   QImode,
   V1QImode
 };
-#define NR_C_MODES (sizeof (constant_modes) / sizeof (constant_modes[0]))
+#define NR_C_MODES (ARRAY_SIZE (constant_modes))
 
 struct constant
 {
diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index c9649fb9c70..798766a723b 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -462,7 +462,7 @@ find_sequences (ExpressionTree &s, ExpressionTreeMap &best_solution)
   const Operator *const prev_op = s.m_exprs[num_vals - 1].m_op;
   const int prev_top_index = (prev_op != NULL) ? prev_op->m_top_index : -1;
 
-  for (size_t f = 0; f < sizeof ops / sizeof ops[0]; f++)
+  for (size_t f = 0; f < ARRAY_SIZE (ops); f++)
     {
       const Operator *const op = &ops[f];
 
@@ -564,7 +564,7 @@ create_insn_code_compression_table ()
   printf ("const enum insn_code %s_multiply_insn_seq_decode_opcode[] = {\n"
 	  "  CODE_FOR_nothing /* must be first */ ", ARCH);
 
-  for (size_t i = 0; i < sizeof ops / sizeof ops[0]; i++)
+  for (size_t i = 0; i < ARRAY_SIZE (ops); i++)
     {
       Operator *op = &ops[i];
       int index = -1;
diff --git a/gcc/config/vms/vms.c b/gcc/config/vms/vms.c
index 5d565e35fb4..d0d44bad2ce 100644
--- a/gcc/config/vms/vms.c
+++ b/gcc/config/vms/vms.c
@@ -99,7 +99,7 @@ static const struct vms_crtl_name vms_crtl_names[] =
 
 /* Number of entires in the above array.  */
 
-#define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
+#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names))
 
 /* List of aliased identifiers.  They must be persistent across gc.  */
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 01341301811..125896a82e8 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2615,7 +2615,7 @@ depset::entity_kind_name () const
     {"decl", "specialization", "partial", "using",
      "namespace", "redirect", "binding"};
   entity_kind kind = get_entity_kind ();
-  gcc_checking_assert (kind < sizeof (names) / sizeof(names[0]));
+  gcc_checking_assert (kind < ARRAY_SIZE (names));
   return names[kind];
 }
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index caa23d3e6f8..cf68c70a0d7 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -6880,7 +6880,7 @@ get_std_name_hint (const char *name)
     /* <vector>.  */
     {"vector", "<vector>", cxx98},
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     {
       if (strcmp (name, hints[i].name) == 0)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f40e707d47c..9f1a69be4a0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4178,7 +4178,7 @@ cp_parser_new (cp_lexer *lexer)
 {
   /* Initialize the binops_by_token so that we can get the tree
      directly from the token.  */
-  for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (binops); i++)
     binops_by_token[binops[i].token_type] = binops[i];
 
   cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
diff --git a/gcc/d/longdouble.h b/gcc/d/longdouble.h
index 1e457ae04d6..2d9695a4309 100644
--- a/gcc/d/longdouble.h
+++ b/gcc/d/longdouble.h
@@ -117,7 +117,7 @@ public:
 private:
   /* Including gcc/real.h presents too many problems, so just
      statically allocate enough space for REAL_VALUE_TYPE.  */
-  long realvalue[(2 + (16 + sizeof (long)) / sizeof (long))];
+  long realvalue[(2 + (16 + ARRAY_SIZE (long))];
 };
 
 /* Declared, but "volatile" is not required.  */
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index def371816e6..62594ebb4d7 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -62,7 +62,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
     {"byte-column", DIAGNOSTICS_COLUMN_UNIT_BYTE}
   };
   int the_column = INT_MIN;
-  for (int i = 0; i != sizeof column_fields / sizeof (*column_fields); ++i)
+  for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
     {
       context->column_unit = column_fields[i].unit;
       const int col = diagnostic_converted_column (context, exploc);
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 094fd0acdb0..8031896ea3b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -13536,8 +13536,7 @@ static const dwarf_qual_info_t dwarf_qual_info[] =
   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
 };
-static const unsigned int dwarf_qual_info_size
-  = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
+static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
 
 /* If DIE is a qualified DIE of some base DIE with the same parent,
    return the base DIE, otherwise return NULL.  Set MASK to the
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 22f1bb56a2b..907d15cbfe4 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -5653,9 +5653,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 		  WALK_SUBEXPR (co->ext.omp_clauses->detach);
 		  for (idx = 0; idx < OMP_IF_LAST; idx++)
 		    WALK_SUBEXPR (co->ext.omp_clauses->if_exprs[idx]);
-		  for (idx = 0;
-		       idx < sizeof (list_types) / sizeof (list_types[0]);
-		       idx++)
+		  for (idx = 0; idx < ARRAY_SIZE (list_types); idx++)
 		    for (n = co->ext.omp_clauses->lists[list_types[idx]];
 			 n; n = n->next)
 		      WALK_SUBEXPR (n->expr);
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 86c412a4334..c2fe1d0d783 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -4864,8 +4864,7 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
       match m;
       const char *selector_sets[] = { "construct", "device",
 				      "implementation", "user" };
-      const int selector_set_count
-	= sizeof (selector_sets) / sizeof (*selector_sets);
+      const int selector_set_count = ARRAY_SIZE (selector_sets);
       int i;
       char buf[GFC_MAX_SYMBOL_LEN + 1];
 
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index dc72d994781..946853c5b37 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -9770,7 +9770,7 @@ conv_intrinsic_ieee_builtin (gfc_se * se, gfc_expr * expr,
 			     enum built_in_function code, int nargs)
 {
   tree args[2];
-  gcc_assert ((unsigned) nargs <= sizeof(args)/sizeof(args[0]));
+  gcc_assert ((unsigned) nargs <= ARRAY_SIZE (args));
 
   conv_ieee_function_args (se, expr, args, nargs);
   se->expr = build_call_expr_loc_array (input_location,
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 5de43bb2784..5dc6064e186 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3417,7 +3417,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
     }
 
   rank = GFC_TYPE_ARRAY_RANK (type);
-  if (rank >= (int) (sizeof (info->dimen) / sizeof (info->dimen[0])))
+  if (rank >= (int) (ARRAY_SIZE (info->dimen)))
     return false;
 
   etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
diff --git a/gcc/genautomata.c b/gcc/genautomata.c
index 5872aca88fa..1d5be8841c5 100644
--- a/gcc/genautomata.c
+++ b/gcc/genautomata.c
@@ -8623,8 +8623,8 @@ output_get_cpu_unit_code_func (void)
   fprintf (output_file, "    };\n\n");
   fprintf (output_file, "  /* The following is binary search: */\n");
   fprintf (output_file, "  %s = 0;\n", LOW_VARIABLE_NAME);
-  fprintf (output_file, "  %s = sizeof (%s) / sizeof (struct %s) - 1;\n",
-	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME, NAME_CODE_STRUCT_NAME);
+  fprintf (output_file, "  %s = ARRAY_SIZE (%s) - 1;\n",
+	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME);
   fprintf (output_file, "  while (%s <= %s)\n    {\n",
 	   LOW_VARIABLE_NAME, HIGH_VARIABLE_NAME);
   fprintf (output_file, "      %s = (%s + %s) / 2;\n",
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index 20ad607b158..6bae85d7b8d 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -128,7 +128,7 @@ emit_documentation (const char *in_fname)
     }
   fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
     {
       struct s_hook sh, *shp;
       void *p;
@@ -223,7 +223,7 @@ emit_documentation (const char *in_fname)
 	      /* POD-valued hooks sometimes come in groups with common
 		 documentation.*/
 	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
+		   j < (int) (ARRAY_SIZE (hook_array))
 		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
 		{
 		  char *namex = upstrdup (hook_array[j].name);
@@ -246,8 +246,7 @@ emit_documentation (const char *in_fname)
 		  printf ("\n@end %s", deftype);
 		}
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
+	  if (++i >= (int) (ARRAY_SIZE (hook_array)) || !hook_array[i].doc)
 	    break;
 	  free (name);
 	  sh.name = name = upstrdup (hook_array[i].name);
@@ -270,7 +269,7 @@ emit_init_macros (const char *docname)
 
   for (print_nest = 0; print_nest <= MAX_NEST; print_nest++)
     {
-      for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+      for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
 	{
 	  char *name = upstrdup (hook_array[i].name);
 
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 1f756b74ca9..21b2408bc3e 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -1953,7 +1953,7 @@ format_floating (const directive &dir, tree arg, range_query *)
       &res.range.min, &res.range.max
     };
 
-    for (int i = 0; i != sizeof minmax / sizeof *minmax; ++i)
+    for (int i = 0; i != ARRAY_SIZE (minmax); ++i)
       {
 	/* Convert the GCC real value representation with the precision
 	   of the real type to the mpfr_t format rounding down in the
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index e4c078a8e43..efaf19b800e 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2773,7 +2773,7 @@ memmodel_name (unsigned HOST_WIDE_INT val)
 {
   val = memmodel_base (val);
 
-  for (unsigned i = 0; i != sizeof memory_models / sizeof *memory_models; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (memory_models); ++i)
     {
       if (val == memory_models[i].modval)
 	return memory_models[i].modname;
diff --git a/gcc/godump.c b/gcc/godump.c
index 2092446b0cc..9af1f9d9cf4 100644
--- a/gcc/godump.c
+++ b/gcc/godump.c
@@ -1327,7 +1327,7 @@ static void
 keyword_hash_init (class godump_container *container)
 {
   size_t i;
-  size_t count = sizeof (keywords) / sizeof (keywords[0]);
+  size_t count = ARRAY_SIZE (keywords);
   void **slot;
 
   for (i = 0; i < count; i++)
diff --git a/gcc/hash-table.c b/gcc/hash-table.c
index dad1d21f099..1015c1ee6e9 100644
--- a/gcc/hash-table.c
+++ b/gcc/hash-table.c
@@ -84,7 +84,7 @@ unsigned int
 hash_table_higher_prime_index (unsigned long n)
 {
   unsigned int low = 0;
-  unsigned int high = sizeof (prime_tab) / sizeof (prime_tab[0]);
+  unsigned int high = ARRAY_SIZE (prime_tab);
 
   while (low != high)
     {
diff --git a/gcc/input.c b/gcc/input.c
index 82e79beab14..0db28462d62 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -3724,8 +3724,7 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
     {
       /* ...and use each of the "interesting" location values as
 	 the starting location within line_table.  */
-      const int num_boundary_locations
-	= sizeof (boundary_locations) / sizeof (boundary_locations[0]);
+      const int num_boundary_locations = ARRAY_SIZE (boundary_locations);
       for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++)
 	{
 	  line_table_case c (default_range_bits, boundary_locations[loc_idx]);
diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index 431ced4dd17..0520e16a0f2 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -1109,9 +1109,7 @@ free_lang_data (void)
   free_lang_data_in_cgraph (&fld);
 
   /* Create gimple variants for common types.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 9b70daf8976..2aae6ea0a0f 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -278,7 +278,7 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
       SANITIZE_POINTER_SUBTRACT
     };
 
-  for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (codes); i++)
     if (sanitize_flags_p (codes[i], caller)
 	!= sanitize_flags_p (codes[i], callee))
       return false;
diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
index 0b6210807be..a95f9213780 100644
--- a/gcc/jit/jit-builtins.c
+++ b/gcc/jit/jit-builtins.c
@@ -109,9 +109,7 @@ find_builtin_by_name (const char *in_name,
 
      We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
      has a NULL name.  */
-  for (unsigned int i = 1;
-       i < sizeof (builtin_data) / sizeof (builtin_data[0]);
-       i++)
+  for (unsigned int i = 1; i < ARRAY_SIZE (builtin_data); i++)
     {
       const struct builtin_data& bd = builtin_data[i];
       if (matches_builtin (in_name, bd))
@@ -320,7 +318,7 @@ static const char * const type_names[] = {
 static const char *
 get_string_for_type_id (enum jit_builtin_type type_id)
 {
-  gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0]));
+  gcc_assert (type_id < ARRAY_SIZE (type_names));
   return type_names[type_id];
 }
 
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index ee8934131d1..10ca636e60f 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -568,9 +568,7 @@ recording::context::context (context *parent_ctxt)
   if (parent_ctxt)
     {
       /* Inherit options from parent.  */
-      for (unsigned i = 0;
-	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
-	   i++)
+      for (unsigned i = 0; i < ARRAY_SIZE (m_str_options); i++)
 	{
 	  const char *parent_opt = parent_ctxt->m_str_options[i];
 	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index 853b3fbd856..8b0572b1283 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -2101,8 +2101,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
       char r_str[27];
       enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
       unsigned int j;
-      unsigned int lto_resolution_str_len
-	= sizeof (lto_resolution_str) / sizeof (char *);
+      unsigned int lto_resolution_str_len = ARRAY_SIZE (lto_resolution_str);
       res_pair rp;
 
       t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE
diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index a7f6f02c79c..4148bb96211 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -1319,9 +1319,7 @@ lto_init (void)
      distinction should only be relevant to the front-end, so we
      always use the C definition here in lto1.
      Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     {
       gcc_assert (builtin_structptr_types[i].node
 		  == builtin_structptr_types[i].base);
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 34261a7ef44..7e996783bff 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1104,7 +1104,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 	print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 	print "      return false;"
 }
@@ -1152,7 +1152,7 @@ for (i = 0; i < n_target_val; i++) {
 	print "  hstate.add_hwi (ptr->" name");";
 }
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 }
 
@@ -1192,7 +1192,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 }
 
@@ -1235,7 +1235,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 }
 
@@ -1317,7 +1317,7 @@ for (i = 0; i < n_opt_val; i++) {
 	else
 		print "  hstate.add_hwi (ptr->" name");";
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 print "  return hstate.end ();";
 print "}";
@@ -1346,7 +1346,7 @@ for (i = 0; i < n_opt_val; i++) {
 		print "    return false;";
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 print "      return false;"
 print "  return true;";
@@ -1380,7 +1380,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 print "}";
 
@@ -1412,7 +1412,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 print "}";
 print "/* Free heap memory used by optimization options  */";
diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index 6077bed7861..5875c10a96f 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -489,7 +489,7 @@ static const char * const test_data[] = {
 static void
 test_metric_conditions ()
 {
-  const int num_test_cases = sizeof (test_data) / sizeof (test_data[0]);
+  const int num_test_cases = ARRAY_SIZE (test_data);
 
   for (int i = 0; i < num_test_cases; i++)
     {
diff --git a/gcc/sreal.c b/gcc/sreal.c
index 960f0da6fd7..6dd23b27bb5 100644
--- a/gcc/sreal.c
+++ b/gcc/sreal.c
@@ -323,7 +323,7 @@ static void
 sreal_verify_arithmetics (void)
 {
   int values[] = {-14123413, -7777, -17, -10, -2, 0, 17, 139, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     for (unsigned j = 0; j < c; j++)
@@ -359,7 +359,7 @@ static void
 sreal_verify_shifting (void)
 {
   int values[] = {0, 17, 32, 139, 1024, 55555, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     verify_shifting (values[i]);
diff --git a/gcc/tree-vect-slp-patterns.c b/gcc/tree-vect-slp-patterns.c
index 63fe75606ab..86b22941d0f 100644
--- a/gcc/tree-vect-slp-patterns.c
+++ b/gcc/tree-vect-slp-patterns.c
@@ -1584,4 +1584,4 @@ vect_pattern_decl_t slp_patterns[]
 #undef SLP_PATTERN
 
 /* Set the number of SLP pattern matchers available.  */
-size_t num__slp_patterns = sizeof(slp_patterns)/sizeof(vect_pattern_decl_t);
+size_t num__slp_patterns = ARRAY_SIZE (slp_patterns);
diff --git a/gcc/tree.c b/gcc/tree.c
index d98b77db50b..8489f586381 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -9295,9 +9295,7 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE.
@ 2022-01-13 17:46 Martin Liska
  0 siblings, 0 replies; 5+ messages in thread
From: Martin Liska @ 2022-01-13 17:46 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:ac75543485331b81cbb55f2a2ffc53ca7979e389

commit ac75543485331b81cbb55f2a2ffc53ca7979e389
Author: Martin Liska <mliska@suse.cz>
Date:   Thu Jan 13 18:46:26 2022 +0100

    Use more ARRAY_SIZE.

Diff:
---
 gcc/ada/locales.c                          |  6 +++---
 gcc/analyzer/engine.cc                     |  2 +-
 gcc/analyzer/function-set.cc               |  2 +-
 gcc/analyzer/sm-file.cc                    |  3 +--
 gcc/analyzer/sm-malloc.cc                  |  3 +--
 gcc/analyzer/sm-signal.cc                  |  3 +--
 gcc/attribs.c                              |  4 ++--
 gcc/builtins.c                             |  2 +-
 gcc/c-family/c-attribs.c                   |  3 +--
 gcc/c-family/c-common.c                    |  7 ++-----
 gcc/c-family/c-format.c                    | 12 ++++++------
 gcc/c-family/c-pragma.c                    |  9 ++++-----
 gcc/c-family/c-warn.c                      |  2 +-
 gcc/c-family/known-headers.cc              |  5 ++---
 gcc/c/c-decl.c                             |  8 +++-----
 gcc/cfg.c                                  |  2 +-
 gcc/common/config/aarch64/aarch64-common.c |  3 +--
 gcc/config/aarch64/aarch64-builtins.c      |  6 +++---
 gcc/config/aarch64/aarch64.c               |  2 +-
 gcc/config/arm/arm-builtins.c              |  4 ++--
 gcc/config/avr/gen-avr-mmcu-texi.c         |  6 +++---
 gcc/config/c6x/c6x.c                       |  2 +-
 gcc/config/darwin-c.c                      |  2 +-
 gcc/config/gcn/mkoffload.c                 |  2 +-
 gcc/config/i386/i386-builtins.c            |  6 ++----
 gcc/config/m32c/m32c.c                     |  2 +-
 gcc/config/nvptx/mkoffload.c               |  6 +++---
 gcc/config/rs6000/driver-rs6000.c          |  2 +-
 gcc/config/rs6000/rs6000.c                 |  2 +-
 gcc/config/s390/s390.c                     |  2 +-
 gcc/config/tilepro/gen-mul-tables.cc       |  4 ++--
 gcc/config/vms/vms.c                       |  2 +-
 gcc/cp/module.cc                           |  2 +-
 gcc/cp/name-lookup.c                       |  2 +-
 gcc/cp/parser.c                            |  2 +-
 gcc/cp/typeck.c                            |  2 +-
 gcc/d/longdouble.h                         |  2 +-
 gcc/diagnostic-format-json.cc              |  2 +-
 gcc/dwarf2out.c                            |  3 +--
 gcc/fortran/frontend-passes.c              |  4 +---
 gcc/fortran/openmp.c                       |  3 +--
 gcc/fortran/trans-intrinsic.c              |  2 +-
 gcc/fortran/trans-types.c                  |  2 +-
 gcc/genautomata.c                          |  4 ++--
 gcc/genhooks.c                             |  9 ++++-----
 gcc/gimple-ssa-sprintf.c                   |  2 +-
 gcc/gimple-ssa-warn-access.cc              |  2 +-
 gcc/godump.c                               |  2 +-
 gcc/hash-table.c                           |  2 +-
 gcc/input.c                                |  3 +--
 gcc/ipa-free-lang-data.cc                  |  4 +---
 gcc/ipa-inline.c                           |  2 +-
 gcc/jit/jit-builtins.c                     |  6 ++----
 gcc/jit/jit-recording.c                    |  4 +---
 gcc/lto/lto-common.c                       |  3 +--
 gcc/lto/lto-lang.c                         |  4 +---
 gcc/optc-save-gen.awk                      | 16 ++++++++--------
 gcc/spellcheck.c                           |  2 +-
 gcc/sreal.c                                |  4 ++--
 gcc/tree-vect-slp-patterns.c               |  2 +-
 gcc/tree.c                                 |  4 +---
 61 files changed, 98 insertions(+), 129 deletions(-)

diff --git a/gcc/ada/locales.c b/gcc/ada/locales.c
index ee1385a6bdc..2aaa2121a50 100644
--- a/gcc/ada/locales.c
+++ b/gcc/ada/locales.c
@@ -649,7 +649,7 @@ str_get_last_byte (char *lc_all) {
 
 static char*
 iso_639_1_to_639_3(char* iso_639_1_code) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -673,7 +673,7 @@ iso_639_1_to_639_3(char* iso_639_1_code) {
 
 static char*
 language_name_to_639_3(char* name) {
-  int len = sizeof(iso_639)/sizeof(iso_639[0]);
+  int len = ARRAY_SIZE (iso_639);
   char **p = iso_639;
   int j;
 
@@ -695,7 +695,7 @@ language_name_to_639_3(char* name) {
 
 static char*
 country_name_to_3166 (char* name) {
-  int len = sizeof(iso_3166)/sizeof(iso_3166[0]);
+  int len = ARRAY_SIZE (iso_3166);
   char **p = iso_3166;
   int j;
 
diff --git a/gcc/analyzer/engine.cc b/gcc/analyzer/engine.cc
index 8b6f4c83f0f..80ce8a5c701 100644
--- a/gcc/analyzer/engine.cc
+++ b/gcc/analyzer/engine.cc
@@ -1080,7 +1080,7 @@ exploded_node::get_dot_fillcolor () const
 	= {"azure", "coral", "cornsilk", "lightblue", "yellow",
 	   "honeydew", "lightpink", "lightsalmon", "palegreen1",
 	   "wheat", "seashell"};
-      const int num_colors = sizeof (colors) / sizeof (colors[0]);
+      const int num_colors = ARRAY_SIZE (colors);
       return colors[total_sm_state % num_colors];
     }
   else
diff --git a/gcc/analyzer/function-set.cc b/gcc/analyzer/function-set.cc
index 8d9237deb63..be04186ed0d 100644
--- a/gcc/analyzer/function-set.cc
+++ b/gcc/analyzer/function-set.cc
@@ -166,7 +166,7 @@ test_stdio_example ()
     "getwc_unlocked",
     "putc_unlocked"
   };
-  const size_t count = sizeof(example) / sizeof (example[0]);
+  const size_t count = ARRAY_SIZE (example);
   function_set fs (example, count);
   fs.assert_sorted ();
   fs.assert_sane ();
diff --git a/gcc/analyzer/sm-file.cc b/gcc/analyzer/sm-file.cc
index 1c996f946f6..5940cb939e5 100644
--- a/gcc/analyzer/sm-file.cc
+++ b/gcc/analyzer/sm-file.cc
@@ -319,8 +319,7 @@ get_file_using_fns ()
     "ungetc",
     "vfprintf"
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
   return fs;
 }
diff --git a/gcc/analyzer/sm-malloc.cc b/gcc/analyzer/sm-malloc.cc
index 47184969ffe..cc808a6bcf2 100644
--- a/gcc/analyzer/sm-malloc.cc
+++ b/gcc/analyzer/sm-malloc.cc
@@ -2006,8 +2006,7 @@ malloc_state_machine::unaffected_by_call_p (tree fndecl)
     /* This array must be kept sorted.  */
     "strsep",
   };
-  const size_t count
-    = sizeof(funcnames) / sizeof (funcnames[0]);
+  const size_t count = ARRAY_SIZE (funcnames);
   function_set fs (funcnames, count);
 
   if (fs.contains_decl_p (fndecl))
diff --git a/gcc/analyzer/sm-signal.cc b/gcc/analyzer/sm-signal.cc
index 8d3e5ff07b1..3abfa7db605 100644
--- a/gcc/analyzer/sm-signal.cc
+++ b/gcc/analyzer/sm-signal.cc
@@ -305,8 +305,7 @@ get_async_signal_unsafe_fns ()
     "vsnprintf",
     "vsprintf"
   };
-  const size_t count
-    = sizeof(async_signal_unsafe_fns) / sizeof (async_signal_unsafe_fns[0]);
+  const size_t count = ARRAY_SIZE (async_signal_unsafe_fns);
   function_set fs (async_signal_unsafe_fns, count);
   return fs;
 }
diff --git a/gcc/attribs.c b/gcc/attribs.c
index 189f56a6e48..986e2be4027 100644
--- a/gcc/attribs.c
+++ b/gcc/attribs.c
@@ -499,7 +499,7 @@ diag_attr_exclusions (tree last_decl, tree node, tree attrname,
 
   /* Iterate over the mutually exclusive attribute names and verify
      that the symbol doesn't contain it.  */
-  for (unsigned i = 0; i != sizeof attrs / sizeof *attrs; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (attrs); ++i)
     {
       if (!attrs[i])
 	continue;
@@ -2101,7 +2101,7 @@ decls_mismatched_attributes (tree tmpl, tree decl, tree attrlist,
   };
 
   for (unsigned i = 0; i != 2; ++i)
-    for (unsigned j = 0; j != sizeof whitelist / sizeof *whitelist; ++j)
+    for (unsigned j = 0; j != ARRAY_SIZE (whitelist); ++j)
       if (lookup_attribute (whitelist[j], tmpl_attrs[i])
 	  || lookup_attribute (whitelist[j], decl_attrs[i]))
 	return 0;
diff --git a/gcc/builtins.c b/gcc/builtins.c
index c780340ed32..f8869cf3808 100644
--- a/gcc/builtins.c
+++ b/gcc/builtins.c
@@ -610,7 +610,7 @@ c_strlen (tree arg, int only_value, c_strlen_data *data, unsigned eltsize)
   if (eltsize != tree_to_uhwi (TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (src)))))
     return NULL_TREE;
 
-  /* Set MAXELTS to sizeof (SRC) / sizeof (*SRC) - 1, the maximum possible
+  /* Set MAXELTS to ARRAY_SIZE (SRC) - 1, the maximum possible
      length of SRC.  Prefer TYPE_SIZE() to TREE_STRING_LENGTH() if possible
      in case the latter is less than the size of the array, such as when
      SRC refers to a short string literal used to initialize a large array.
diff --git a/gcc/c-family/c-attribs.c b/gcc/c-family/c-attribs.c
index bdf72ce385c..1679820bbe9 100644
--- a/gcc/c-family/c-attribs.c
+++ b/gcc/c-family/c-attribs.c
@@ -4886,8 +4886,7 @@ handle_access_attribute (tree node[3], tree name, tree args, int flags,
   int imode;
 
   {
-    const int nmodes =
-      sizeof attr_access::mode_names / sizeof *attr_access::mode_names;
+    const int nmodes = ARRAY_SIZE (attr_access::mode_names);
 
     for (imode = 0; imode != nmodes; ++imode)
       if (!strncmp (ps, attr_access::mode_names[imode],
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index a34f32f51a4..594016c12d8 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -602,8 +602,7 @@ const struct c_common_resword c_common_reswords[] =
   { "null_resettable",	RID_NULL_RESETTABLE,	D_OBJC },
 };
 
-const unsigned int num_c_common_reswords =
-  sizeof c_common_reswords / sizeof (struct c_common_resword);
+const unsigned int num_c_common_reswords = ARRAY_SIZE (c_common_reswords);
 
 /* Return identifier for address space AS.  */
 
@@ -4476,9 +4475,7 @@ c_common_nodes_and_builtins (void)
 
   /* Make fileptr_type_node a distinct void * type until
      FILE type is defined.  Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node
       = build_variant_type_copy (builtin_structptr_types[i].base);
 
diff --git a/gcc/c-family/c-format.c b/gcc/c-family/c-format.c
index afa77810a5c..52d0b7f6bc8 100644
--- a/gcc/c-family/c-format.c
+++ b/gcc/c-family/c-format.c
@@ -3195,7 +3195,7 @@ check_tokens (const token_t *tokens, unsigned ntoks,
   else
     {
       /* Diagnose some common misspellings.  */
-      for (unsigned i = 0; i != sizeof badwords / sizeof *badwords; ++i)
+      for (unsigned i = 0; i != ARRAY_SIZE (badwords); ++i)
 	{
 	  unsigned badwlen = strspn (badwords[i].name, " -");
 	  if (wlen >= badwlen
@@ -3390,14 +3390,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISPUNCT (format_chars[0]))
     {
-      size_t nelts = sizeof c_opers / sizeof *c_opers;
+      size_t nelts = ARRAY_SIZE (c_opers);
       if (const char *ret = check_tokens (c_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_opers / sizeof *cxx_opers : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_opers) : 0;
       if (const char *ret = check_tokens (cxx_opers, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3407,14 +3407,14 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 
   if (ISALPHA (format_chars[0]))
     {
-      size_t nelts = sizeof c_keywords / sizeof *c_keywords;
+      size_t nelts = ARRAY_SIZE (c_keywords);
       if (const char *ret = check_tokens (c_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
 					  baltoks))
 	return ret;
 
-      nelts = c_dialect_cxx () ? sizeof cxx_keywords / sizeof *cxx_keywords : 0;
+      nelts = c_dialect_cxx () ? ARRAY_SIZE (cxx_keywords) : 0;
       if (const char *ret = check_tokens (cxx_keywords, nelts,
 					  format_string_loc, format_string_cst,
 					  orig_format_chars, format_chars,
@@ -3533,7 +3533,7 @@ check_plain (location_t format_string_loc, tree format_string_cst,
 	  && ISALPHA (format_chars[1]))
 	{
 	  /* Diagnose a subset of contractions that are best avoided.  */
-	  for (unsigned i = 0; i != sizeof contrs / sizeof *contrs; ++i)
+	  for (unsigned i = 0; i != ARRAY_SIZE (contrs); ++i)
 	    {
 	      const char *apos = strchr (contrs[i].name, '\'');
 	      gcc_assert (apos != NULL);
diff --git a/gcc/c-family/c-pragma.c b/gcc/c-family/c-pragma.c
index 8dde5b841b2..69eda9582a8 100644
--- a/gcc/c-family/c-pragma.c
+++ b/gcc/c-family/c-pragma.c
@@ -1400,8 +1400,8 @@ static const struct omp_pragma_def omp_pragmas_simd[] = {
 void
 c_pp_lookup_pragma (unsigned int id, const char **space, const char **name)
 {
-  const int n_oacc_pragmas = sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
-  const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+  const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
+  const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
   const int n_omp_pragmas_simd = sizeof (omp_pragmas_simd)
 				 / sizeof (*omp_pragmas);
   int i;
@@ -1576,8 +1576,7 @@ init_pragma (void)
 {
   if (flag_openacc)
     {
-      const int n_oacc_pragmas
-	= sizeof (oacc_pragmas) / sizeof (*oacc_pragmas);
+      const int n_oacc_pragmas = ARRAY_SIZE (oacc_pragmas);
       int i;
 
       for (i = 0; i < n_oacc_pragmas; ++i)
@@ -1587,7 +1586,7 @@ init_pragma (void)
 
   if (flag_openmp)
     {
-      const int n_omp_pragmas = sizeof (omp_pragmas) / sizeof (*omp_pragmas);
+      const int n_omp_pragmas = ARRAY_SIZE (omp_pragmas);
       int i;
 
       for (i = 0; i < n_omp_pragmas; ++i)
diff --git a/gcc/c-family/c-warn.c b/gcc/c-family/c-warn.c
index 1ce2202c7ff..796912140e3 100644
--- a/gcc/c-family/c-warn.c
+++ b/gcc/c-family/c-warn.c
@@ -3712,7 +3712,7 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms)
    to an array and the divisor does not equal the size of the array element.
    For instance:
 
-     sizeof (ARR) / sizeof (OP)
+     ARRAY_SIZE (ARR)
 
    ARR is the array argument of the first sizeof, ARR_TYPE is its ARRAY_TYPE.
    OP1 is the whole second SIZEOF_EXPR, or its argument; TYPE1 is the type
diff --git a/gcc/c-family/known-headers.cc b/gcc/c-family/known-headers.cc
index 8ad3eb3f466..01c86b27dc8 100644
--- a/gcc/c-family/known-headers.cc
+++ b/gcc/c-family/known-headers.cc
@@ -79,8 +79,7 @@ get_string_macro_hint (const char *name, enum stdlib lib)
   if ((lib == STDLIB_C && flag_isoc99)
       || (lib == STDLIB_CPLUSPLUS && cxx_dialect >= cxx11 ))
     {
-      const size_t num_c99_cxx11_macros
-	= sizeof (c99_cxx11_macros) / sizeof (c99_cxx11_macros[0]);
+      const size_t num_c99_cxx11_macros = ARRAY_SIZE (c99_cxx11_macros);
       for (size_t i = 0; i < num_c99_cxx11_macros; i++)
 	if (strcmp (name, c99_cxx11_macros[i]) == 0)
 	  return lib == STDLIB_C ? "<inttypes.h>" : "<cinttypes>";
@@ -204,7 +203,7 @@ get_stdlib_header_for_name (const char *name, enum stdlib lib)
     {"WCHAR_MAX", {"<wchar.h>", "<cwchar>"} },
     {"WCHAR_MIN", {"<wchar.h>", "<cwchar>"} }
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     if (strcmp (name, hints[i].name) == 0)
       return hints[i].header[lib];
diff --git a/gcc/c/c-decl.c b/gcc/c/c-decl.c
index 29a79eba841..c681174c2d3 100644
--- a/gcc/c/c-decl.c
+++ b/gcc/c/c-decl.c
@@ -1658,7 +1658,7 @@ c_bind (location_t loc, tree decl, bool is_global)
    Used only by match_builtin_function_types.  */
 
 static const unsigned builtin_structptr_type_count
-  = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  = ARRAY_SIZE (builtin_structptr_types);
 
 static GTY(()) tree last_structptr_types[builtin_structptr_type_count];
 
@@ -1705,10 +1705,8 @@ match_builtin_function_types (tree newtype, tree oldtype,
   tree newargs = TYPE_ARG_TYPES (newtype);
   tree tryargs = newargs;
 
-  const unsigned nlst
-    = sizeof last_structptr_types / sizeof last_structptr_types[0];
-  const unsigned nbst
-    = sizeof builtin_structptr_types / sizeof builtin_structptr_types[0];
+  const unsigned nlst = ARRAY_SIZE (last_structptr_types);
+  const unsigned nbst = ARRAY_SIZE (builtin_structptr_types);
 
   gcc_checking_assert (nlst == nbst);
 
diff --git a/gcc/cfg.c b/gcc/cfg.c
index e4ce360bd87..59c48f3baee 100644
--- a/gcc/cfg.c
+++ b/gcc/cfg.c
@@ -783,7 +783,7 @@ dump_bb_info (FILE *outf, basic_block bb, int indent, dump_flags_t flags,
       NULL
 #undef DEF_BASIC_BLOCK_FLAG
     };
-  const unsigned n_bitnames = sizeof (bb_bitnames) / sizeof (char *);
+  const unsigned n_bitnames = ARRAY_SIZE (bb_bitnames);
   bool first;
   char *s_indent = (char *) alloca ((size_t) indent + 1);
   memset ((void *) s_indent, ' ', (size_t) indent);
diff --git a/gcc/common/config/aarch64/aarch64-common.c b/gcc/common/config/aarch64/aarch64-common.c
index 140e3e78d09..6d17b0e133d 100644
--- a/gcc/common/config/aarch64/aarch64-common.c
+++ b/gcc/common/config/aarch64/aarch64-common.c
@@ -314,8 +314,7 @@ aarch64_option_init_struct (struct gcc_options *opts ATTRIBUTE_UNUSED)
        pop and attribute change (arm_neon headers, lto etc all cause this to
        happen quite frequently).  It is a trade-off between time and space and
        so time won.  */
-    int n_extensions
-      = sizeof (all_extensions) / sizeof (struct aarch64_option_extension);
+    int n_extensions = ARRAY_SIZE (all_extensions);
     qsort (&all_extensions_by_on, n_extensions,
 	   sizeof (struct aarch64_option_extension), opt_ext_cmp);
 }
diff --git a/gcc/config/aarch64/aarch64-builtins.c b/gcc/config/aarch64/aarch64-builtins.c
index 58bcbd9875f..2d2798602cc 100644
--- a/gcc/config/aarch64/aarch64-builtins.c
+++ b/gcc/config/aarch64/aarch64-builtins.c
@@ -831,7 +831,7 @@ aarch64_lookup_simd_builtin_type (machine_mode mode,
 				  enum aarch64_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -868,7 +868,7 @@ static void
 aarch64_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (aarch64_simd_types) / sizeof (aarch64_simd_types[0]);
+  int nelts = ARRAY_SIZE (aarch64_simd_types);
   tree tdecl;
 
   /* Init all the element types built by the front-end.  */
@@ -1411,7 +1411,7 @@ aarch64_init_builtin_rsqrt (void)
   };
 
   builtin_decls_data *bdd = bdda;
-  builtin_decls_data *bdd_end = bdd + (sizeof (bdda) / sizeof (builtin_decls_data));
+  builtin_decls_data *bdd_end = bdd + (ARRAY_SIZE (bdda));
 
   for (; bdd < bdd_end; bdd++)
   {
diff --git a/gcc/config/aarch64/aarch64.c b/gcc/config/aarch64/aarch64.c
index 1bca2a31a1b..9c2259282f4 100644
--- a/gcc/config/aarch64/aarch64.c
+++ b/gcc/config/aarch64/aarch64.c
@@ -19782,7 +19782,7 @@ is_madd_op (enum attr_type t1)
     TYPE_SMMLA, TYPE_UMLAL, TYPE_UMLALS,TYPE_SMLSD, TYPE_SMLSDX, TYPE_SMLSLD
   };
 
-  for (i = 0; i < sizeof (mlatypes) / sizeof (enum attr_type); i++)
+  for (i = 0; i < ARRAY_SIZE (mlatypes); i++)
     {
       if (t1 == mlatypes[i])
 	return true;
diff --git a/gcc/config/arm/arm-builtins.c b/gcc/config/arm/arm-builtins.c
index e6bbda23e3e..05bd527e666 100644
--- a/gcc/config/arm/arm-builtins.c
+++ b/gcc/config/arm/arm-builtins.c
@@ -1445,7 +1445,7 @@ arm_lookup_simd_builtin_type (machine_mode mode,
 			      enum arm_type_qualifiers q)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
 
   /* Non-poly scalar modes map to standard types not in the table.  */
   if (q != qualifier_poly && !VECTOR_MODE_P (mode))
@@ -1477,7 +1477,7 @@ static void
 arm_init_simd_builtin_types (void)
 {
   int i;
-  int nelts = sizeof (arm_simd_types) / sizeof (arm_simd_types[0]);
+  int nelts = ARRAY_SIZE (arm_simd_types);
   tree tdecl;
 
   /* Poly types are a world of their own.  In order to maintain legacy
diff --git a/gcc/config/avr/gen-avr-mmcu-texi.c b/gcc/config/avr/gen-avr-mmcu-texi.c
index 05b81dd3cb5..34fb3943a62 100644
--- a/gcc/config/avr/gen-avr-mmcu-texi.c
+++ b/gcc/config/avr/gen-avr-mmcu-texi.c
@@ -26,7 +26,7 @@
 #include "avr-devices.c"
 
 static const avr_mcu_t*
-mcus[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
+mcus[ARRAY_SIZE (avr_mcu_types);
 
 static int letter (char c)
 {
@@ -56,7 +56,7 @@ c_prefix (const char *str)
       "attiny", "atmega", "atxmega", "ata", "at90"
     };
 
-  int i, n = (int) (sizeof (prefixes) / sizeof (*prefixes));
+  int i, n = (int) (ARRAY_SIZE (prefixes));
 
   for (i = 0; i < n; i++)
     if (str_prefix_p (str, prefixes[i]))
@@ -185,7 +185,7 @@ int main (void)
 	  print_mcus (n_mcus);
 	  n_mcus = 0;
 
-	  for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
+	  for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
 	    if (arch_id == avr_texinfo[i].arch_id)
 	      printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
 	}
diff --git a/gcc/config/c6x/c6x.c b/gcc/config/c6x/c6x.c
index 7fe18d69c7f..dc01a6e47c4 100644
--- a/gcc/config/c6x/c6x.c
+++ b/gcc/config/c6x/c6x.c
@@ -2580,7 +2580,7 @@ static unsigned reg_save_order[] =
   REG_B14, REG_A15
 };
 
-#define N_SAVE_ORDER (sizeof reg_save_order / sizeof *reg_save_order)
+#define N_SAVE_ORDER (ARRAY_SIZE (reg_save_order))
 
 /* Compute the layout of the stack frame and store it in FRAME.  */
 
diff --git a/gcc/config/darwin-c.c b/gcc/config/darwin-c.c
index 9f46924408a..58deb01405a 100644
--- a/gcc/config/darwin-c.c
+++ b/gcc/config/darwin-c.c
@@ -505,7 +505,7 @@ darwin_register_frameworks (const char *sysroot,
       size_t i;
 
       /* Setup default search path for frameworks.  */
-      for (i=0; i<sizeof (framework_defaults)/sizeof(const char *); ++i)
+      for (i = 0; i < ARRAY_SIZE (framework_defaults); ++i)
 	{
 	  char *str;
 	  if (sysroot)
diff --git a/gcc/config/gcn/mkoffload.c b/gcc/config/gcn/mkoffload.c
index 92c46899786..0dfc3b2ba86 100644
--- a/gcc/config/gcn/mkoffload.c
+++ b/gcc/config/gcn/mkoffload.c
@@ -723,7 +723,7 @@ process_obj (FILE *in, FILE *cfile)
 	   "  unsigned global_variable_count;\n"
 	   "} target_data = {\n"
 	   "  &gcn_image,\n"
-	   "  sizeof (gcn_kernels) / sizeof (gcn_kernels[0]),\n"
+	   "  ARRAY_SIZE (gcn_kernels),\n"
 	   "  gcn_kernels,\n"
 	   "  gcn_num_vars\n"
 	   "};\n\n");
diff --git a/gcc/config/i386/i386-builtins.c b/gcc/config/i386/i386-builtins.c
index 2570501ae7e..28bef5a84ea 100644
--- a/gcc/config/i386/i386-builtins.c
+++ b/gcc/config/i386/i386-builtins.c
@@ -1931,8 +1931,7 @@ get_builtin_code_for_version (tree decl, tree *predicate_list)
 
   enum feature_priority priority = P_NONE;
 
-  static unsigned int NUM_FEATURES
-    = sizeof (isa_names_table) / sizeof (_isa_names_table);
+  static unsigned int NUM_FEATURES = ARRAY_SIZE (isa_names_table);
 
   unsigned int i;
 
@@ -2285,8 +2284,7 @@ fold_builtin_cpu (tree fndecl, tree *args)
       tree final;
 
       unsigned int field_val = 0;
-      unsigned int NUM_ISA_NAMES
-	= sizeof (isa_names_table) / sizeof (struct _isa_names_table);
+      unsigned int NUM_ISA_NAMES = ARRAY_SIZE (isa_names_table);
 
       for (i = 0; i < NUM_ISA_NAMES; i++)
 	if (strcmp (isa_names_table[i].name,
diff --git a/gcc/config/m32c/m32c.c b/gcc/config/m32c/m32c.c
index a004790d074..26727000fe1 100644
--- a/gcc/config/m32c/m32c.c
+++ b/gcc/config/m32c/m32c.c
@@ -1090,7 +1090,7 @@ static struct
   { FB_REGNO, 0x01, 2, 4 }
 };
 
-#define PUSHM_N (sizeof(pushm_info)/sizeof(pushm_info[0]))
+#define PUSHM_N (ARRAY_SIZE (pushm_info))
 
 /* Returns TRUE if we need to save/restore the given register.  We
    save everything for exception handlers, so that any register can be
diff --git a/gcc/config/nvptx/mkoffload.c b/gcc/config/nvptx/mkoffload.c
index b28c1a32292..fa3b4b76821 100644
--- a/gcc/config/nvptx/mkoffload.c
+++ b/gcc/config/nvptx/mkoffload.c
@@ -316,11 +316,11 @@ process (FILE *in, FILE *out)
 	   "  const struct nvptx_fn *fn_names;\n"
 	   "  unsigned fn_num;\n"
 	   "} target_data = {\n"
-	   "  ptx_objs, sizeof (ptx_objs) / sizeof (ptx_objs[0]),\n"
+	   "  ptx_objs, ARRAY_SIZE (ptx_objs),\n"
 	   "  var_mappings,"
-	   "  sizeof (var_mappings) / sizeof (var_mappings[0]),\n"
+	   "  ARRAY_SIZE (var_mappings),\n"
 	   "  func_mappings,"
-	   "  sizeof (func_mappings) / sizeof (func_mappings[0])\n"
+	   "  ARRAY_SIZE (func_mappings)\n"
 	   "};\n\n");
 
   fprintf (out, "#ifdef __cplusplus\n"
diff --git a/gcc/config/rs6000/driver-rs6000.c b/gcc/config/rs6000/driver-rs6000.c
index 631054dcfb1..e84eed88f2b 100644
--- a/gcc/config/rs6000/driver-rs6000.c
+++ b/gcc/config/rs6000/driver-rs6000.c
@@ -599,7 +599,7 @@ host_detect_local_cpu (int argc, const char **argv)
 
   if (assembler)
     {
-      for (i = 0; i < sizeof (asm_names) / sizeof (asm_names[0]); i++)
+      for (i = 0; i < ARRAY_SIZE (asm_names); i++)
 	{
 	  if (!asm_names[i].cpu || !strcmp (asm_names[i].cpu, cpu))
 	    return asm_names[i].asm_sw;
diff --git a/gcc/config/rs6000/rs6000.c b/gcc/config/rs6000/rs6000.c
index 7759f757908..fcfccc20dd0 100644
--- a/gcc/config/rs6000/rs6000.c
+++ b/gcc/config/rs6000/rs6000.c
@@ -17014,7 +17014,7 @@ rs6000_hash_constant (rtx k)
 	else
 	  {
 	    size_t i;
-	    for (i = 0; i < sizeof (HOST_WIDE_INT) / sizeof (unsigned); i++)
+	    for (i = 0; i < ARRAY_SIZE (HOST_WIDE_INT); i++)
 	      result = result * 613 + (unsigned) (XWINT (k, fidx)
 						  >> CHAR_BIT * i);
 	  }
diff --git a/gcc/config/s390/s390.c b/gcc/config/s390/s390.c
index 056002e4a4a..760eb687d23 100644
--- a/gcc/config/s390/s390.c
+++ b/gcc/config/s390/s390.c
@@ -8774,7 +8774,7 @@ static machine_mode constant_modes[] =
   QImode,
   V1QImode
 };
-#define NR_C_MODES (sizeof (constant_modes) / sizeof (constant_modes[0]))
+#define NR_C_MODES (ARRAY_SIZE (constant_modes))
 
 struct constant
 {
diff --git a/gcc/config/tilepro/gen-mul-tables.cc b/gcc/config/tilepro/gen-mul-tables.cc
index c9649fb9c70..798766a723b 100644
--- a/gcc/config/tilepro/gen-mul-tables.cc
+++ b/gcc/config/tilepro/gen-mul-tables.cc
@@ -462,7 +462,7 @@ find_sequences (ExpressionTree &s, ExpressionTreeMap &best_solution)
   const Operator *const prev_op = s.m_exprs[num_vals - 1].m_op;
   const int prev_top_index = (prev_op != NULL) ? prev_op->m_top_index : -1;
 
-  for (size_t f = 0; f < sizeof ops / sizeof ops[0]; f++)
+  for (size_t f = 0; f < ARRAY_SIZE (ops); f++)
     {
       const Operator *const op = &ops[f];
 
@@ -564,7 +564,7 @@ create_insn_code_compression_table ()
   printf ("const enum insn_code %s_multiply_insn_seq_decode_opcode[] = {\n"
 	  "  CODE_FOR_nothing /* must be first */ ", ARCH);
 
-  for (size_t i = 0; i < sizeof ops / sizeof ops[0]; i++)
+  for (size_t i = 0; i < ARRAY_SIZE (ops); i++)
     {
       Operator *op = &ops[i];
       int index = -1;
diff --git a/gcc/config/vms/vms.c b/gcc/config/vms/vms.c
index 5d565e35fb4..d0d44bad2ce 100644
--- a/gcc/config/vms/vms.c
+++ b/gcc/config/vms/vms.c
@@ -99,7 +99,7 @@ static const struct vms_crtl_name vms_crtl_names[] =
 
 /* Number of entires in the above array.  */
 
-#define NBR_CRTL_NAMES (sizeof (vms_crtl_names) / sizeof (*vms_crtl_names))
+#define NBR_CRTL_NAMES (ARRAY_SIZE (vms_crtl_names))
 
 /* List of aliased identifiers.  They must be persistent across gc.  */
 
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc
index 01341301811..125896a82e8 100644
--- a/gcc/cp/module.cc
+++ b/gcc/cp/module.cc
@@ -2615,7 +2615,7 @@ depset::entity_kind_name () const
     {"decl", "specialization", "partial", "using",
      "namespace", "redirect", "binding"};
   entity_kind kind = get_entity_kind ();
-  gcc_checking_assert (kind < sizeof (names) / sizeof(names[0]));
+  gcc_checking_assert (kind < ARRAY_SIZE (names));
   return names[kind];
 }
 
diff --git a/gcc/cp/name-lookup.c b/gcc/cp/name-lookup.c
index caa23d3e6f8..cf68c70a0d7 100644
--- a/gcc/cp/name-lookup.c
+++ b/gcc/cp/name-lookup.c
@@ -6880,7 +6880,7 @@ get_std_name_hint (const char *name)
     /* <vector>.  */
     {"vector", "<vector>", cxx98},
   };
-  const size_t num_hints = sizeof (hints) / sizeof (hints[0]);
+  const size_t num_hints = ARRAY_SIZE (hints);
   for (size_t i = 0; i < num_hints; i++)
     {
       if (strcmp (name, hints[i].name) == 0)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index f40e707d47c..9f1a69be4a0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -4178,7 +4178,7 @@ cp_parser_new (cp_lexer *lexer)
 {
   /* Initialize the binops_by_token so that we can get the tree
      directly from the token.  */
-  for (unsigned i = 0; i < sizeof (binops) / sizeof (binops[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (binops); i++)
     binops_by_token[binops[i].token_type] = binops[i];
 
   cp_parser *parser = ggc_cleared_alloc<cp_parser> ();
diff --git a/gcc/cp/typeck.c b/gcc/cp/typeck.c
index 8029b2bf2fb..f36030fa2b0 100644
--- a/gcc/cp/typeck.c
+++ b/gcc/cp/typeck.c
@@ -5164,7 +5164,7 @@ cp_build_binary_op (const op_location_t &location,
 		{
 		  auto_diagnostic_group d;
 		  if (warning_at (location, OPT_Wsizeof_pointer_div,
-				  "division %<sizeof (%T) / sizeof (%T)%> does "
+				  "division %<ARRAY_SIZE (%T)%> does "
 				  "not compute the number of array elements",
 				  type0, type1))
 		    if (DECL_P (first_arg))
diff --git a/gcc/d/longdouble.h b/gcc/d/longdouble.h
index 1e457ae04d6..2d9695a4309 100644
--- a/gcc/d/longdouble.h
+++ b/gcc/d/longdouble.h
@@ -117,7 +117,7 @@ public:
 private:
   /* Including gcc/real.h presents too many problems, so just
      statically allocate enough space for REAL_VALUE_TYPE.  */
-  long realvalue[(2 + (16 + sizeof (long)) / sizeof (long))];
+  long realvalue[(2 + (16 + ARRAY_SIZE (long))];
 };
 
 /* Declared, but "volatile" is not required.  */
diff --git a/gcc/diagnostic-format-json.cc b/gcc/diagnostic-format-json.cc
index def371816e6..62594ebb4d7 100644
--- a/gcc/diagnostic-format-json.cc
+++ b/gcc/diagnostic-format-json.cc
@@ -62,7 +62,7 @@ json_from_expanded_location (diagnostic_context *context, location_t loc)
     {"byte-column", DIAGNOSTICS_COLUMN_UNIT_BYTE}
   };
   int the_column = INT_MIN;
-  for (int i = 0; i != sizeof column_fields / sizeof (*column_fields); ++i)
+  for (int i = 0; i != ARRAY_SIZE (column_fields); ++i)
     {
       context->column_unit = column_fields[i].unit;
       const int col = diagnostic_converted_column (context, exploc);
diff --git a/gcc/dwarf2out.c b/gcc/dwarf2out.c
index 094fd0acdb0..8031896ea3b 100644
--- a/gcc/dwarf2out.c
+++ b/gcc/dwarf2out.c
@@ -13536,8 +13536,7 @@ static const dwarf_qual_info_t dwarf_qual_info[] =
   { TYPE_QUAL_RESTRICT, DW_TAG_restrict_type },
   { TYPE_QUAL_ATOMIC, DW_TAG_atomic_type }
 };
-static const unsigned int dwarf_qual_info_size
-  = sizeof (dwarf_qual_info) / sizeof (dwarf_qual_info[0]);
+static const unsigned int dwarf_qual_info_size = ARRAY_SIZE (dwarf_qual_info);
 
 /* If DIE is a qualified DIE of some base DIE with the same parent,
    return the base DIE, otherwise return NULL.  Set MASK to the
diff --git a/gcc/fortran/frontend-passes.c b/gcc/fortran/frontend-passes.c
index 22f1bb56a2b..907d15cbfe4 100644
--- a/gcc/fortran/frontend-passes.c
+++ b/gcc/fortran/frontend-passes.c
@@ -5653,9 +5653,7 @@ gfc_code_walker (gfc_code **c, walk_code_fn_t codefn, walk_expr_fn_t exprfn,
 		  WALK_SUBEXPR (co->ext.omp_clauses->detach);
 		  for (idx = 0; idx < OMP_IF_LAST; idx++)
 		    WALK_SUBEXPR (co->ext.omp_clauses->if_exprs[idx]);
-		  for (idx = 0;
-		       idx < sizeof (list_types) / sizeof (list_types[0]);
-		       idx++)
+		  for (idx = 0; idx < ARRAY_SIZE (list_types); idx++)
 		    for (n = co->ext.omp_clauses->lists[list_types[idx]];
 			 n; n = n->next)
 		      WALK_SUBEXPR (n->expr);
diff --git a/gcc/fortran/openmp.c b/gcc/fortran/openmp.c
index 86c412a4334..c2fe1d0d783 100644
--- a/gcc/fortran/openmp.c
+++ b/gcc/fortran/openmp.c
@@ -4864,8 +4864,7 @@ gfc_match_omp_context_selector_specification (gfc_omp_declare_variant *odv)
       match m;
       const char *selector_sets[] = { "construct", "device",
 				      "implementation", "user" };
-      const int selector_set_count
-	= sizeof (selector_sets) / sizeof (*selector_sets);
+      const int selector_set_count = ARRAY_SIZE (selector_sets);
       int i;
       char buf[GFC_MAX_SYMBOL_LEN + 1];
 
diff --git a/gcc/fortran/trans-intrinsic.c b/gcc/fortran/trans-intrinsic.c
index dc72d994781..946853c5b37 100644
--- a/gcc/fortran/trans-intrinsic.c
+++ b/gcc/fortran/trans-intrinsic.c
@@ -9770,7 +9770,7 @@ conv_intrinsic_ieee_builtin (gfc_se * se, gfc_expr * expr,
 			     enum built_in_function code, int nargs)
 {
   tree args[2];
-  gcc_assert ((unsigned) nargs <= sizeof(args)/sizeof(args[0]));
+  gcc_assert ((unsigned) nargs <= ARRAY_SIZE (args));
 
   conv_ieee_function_args (se, expr, args, nargs);
   se->expr = build_call_expr_loc_array (input_location,
diff --git a/gcc/fortran/trans-types.c b/gcc/fortran/trans-types.c
index 5de43bb2784..5dc6064e186 100644
--- a/gcc/fortran/trans-types.c
+++ b/gcc/fortran/trans-types.c
@@ -3417,7 +3417,7 @@ gfc_get_array_descr_info (const_tree type, struct array_descr_info *info)
     }
 
   rank = GFC_TYPE_ARRAY_RANK (type);
-  if (rank >= (int) (sizeof (info->dimen) / sizeof (info->dimen[0])))
+  if (rank >= (int) (ARRAY_SIZE (info->dimen)))
     return false;
 
   etype = GFC_TYPE_ARRAY_DATAPTR_TYPE (type);
diff --git a/gcc/genautomata.c b/gcc/genautomata.c
index 5872aca88fa..1d5be8841c5 100644
--- a/gcc/genautomata.c
+++ b/gcc/genautomata.c
@@ -8623,8 +8623,8 @@ output_get_cpu_unit_code_func (void)
   fprintf (output_file, "    };\n\n");
   fprintf (output_file, "  /* The following is binary search: */\n");
   fprintf (output_file, "  %s = 0;\n", LOW_VARIABLE_NAME);
-  fprintf (output_file, "  %s = sizeof (%s) / sizeof (struct %s) - 1;\n",
-	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME, NAME_CODE_STRUCT_NAME);
+  fprintf (output_file, "  %s = ARRAY_SIZE (%s) - 1;\n",
+	   HIGH_VARIABLE_NAME, NAME_CODE_TABLE_NAME);
   fprintf (output_file, "  while (%s <= %s)\n    {\n",
 	   LOW_VARIABLE_NAME, HIGH_VARIABLE_NAME);
   fprintf (output_file, "      %s = (%s + %s) / 2;\n",
diff --git a/gcc/genhooks.c b/gcc/genhooks.c
index 20ad607b158..6bae85d7b8d 100644
--- a/gcc/genhooks.c
+++ b/gcc/genhooks.c
@@ -128,7 +128,7 @@ emit_documentation (const char *in_fname)
     }
   fclose (f);
   /* For each hook in hook_array, if it is a start hook, store its position.  */
-  for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+  for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
     {
       struct s_hook sh, *shp;
       void *p;
@@ -223,7 +223,7 @@ emit_documentation (const char *in_fname)
 	      /* POD-valued hooks sometimes come in groups with common
 		 documentation.*/
 	      for (j = i + 1;
-		   j < (int) (sizeof hook_array / sizeof hook_array[0])
+		   j < (int) (ARRAY_SIZE (hook_array))
 		   && hook_array[j].doc == 0 && hook_array[j].type; j++)
 		{
 		  char *namex = upstrdup (hook_array[j].name);
@@ -246,8 +246,7 @@ emit_documentation (const char *in_fname)
 		  printf ("\n@end %s", deftype);
 		}
 	    }
-	  if (++i >= (int) (sizeof hook_array / sizeof hook_array[0])
-	      || !hook_array[i].doc)
+	  if (++i >= (int) (ARRAY_SIZE (hook_array)) || !hook_array[i].doc)
 	    break;
 	  free (name);
 	  sh.name = name = upstrdup (hook_array[i].name);
@@ -270,7 +269,7 @@ emit_init_macros (const char *docname)
 
   for (print_nest = 0; print_nest <= MAX_NEST; print_nest++)
     {
-      for (i = 0; i < (int) (sizeof hook_array / sizeof hook_array[0]); i++)
+      for (i = 0; i < (int) (ARRAY_SIZE (hook_array)); i++)
 	{
 	  char *name = upstrdup (hook_array[i].name);
 
diff --git a/gcc/gimple-ssa-sprintf.c b/gcc/gimple-ssa-sprintf.c
index 1f756b74ca9..21b2408bc3e 100644
--- a/gcc/gimple-ssa-sprintf.c
+++ b/gcc/gimple-ssa-sprintf.c
@@ -1953,7 +1953,7 @@ format_floating (const directive &dir, tree arg, range_query *)
       &res.range.min, &res.range.max
     };
 
-    for (int i = 0; i != sizeof minmax / sizeof *minmax; ++i)
+    for (int i = 0; i != ARRAY_SIZE (minmax); ++i)
       {
 	/* Convert the GCC real value representation with the precision
 	   of the real type to the mpfr_t format rounding down in the
diff --git a/gcc/gimple-ssa-warn-access.cc b/gcc/gimple-ssa-warn-access.cc
index e4c078a8e43..efaf19b800e 100644
--- a/gcc/gimple-ssa-warn-access.cc
+++ b/gcc/gimple-ssa-warn-access.cc
@@ -2773,7 +2773,7 @@ memmodel_name (unsigned HOST_WIDE_INT val)
 {
   val = memmodel_base (val);
 
-  for (unsigned i = 0; i != sizeof memory_models / sizeof *memory_models; ++i)
+  for (unsigned i = 0; i != ARRAY_SIZE (memory_models); ++i)
     {
       if (val == memory_models[i].modval)
 	return memory_models[i].modname;
diff --git a/gcc/godump.c b/gcc/godump.c
index 2092446b0cc..9af1f9d9cf4 100644
--- a/gcc/godump.c
+++ b/gcc/godump.c
@@ -1327,7 +1327,7 @@ static void
 keyword_hash_init (class godump_container *container)
 {
   size_t i;
-  size_t count = sizeof (keywords) / sizeof (keywords[0]);
+  size_t count = ARRAY_SIZE (keywords);
   void **slot;
 
   for (i = 0; i < count; i++)
diff --git a/gcc/hash-table.c b/gcc/hash-table.c
index dad1d21f099..1015c1ee6e9 100644
--- a/gcc/hash-table.c
+++ b/gcc/hash-table.c
@@ -84,7 +84,7 @@ unsigned int
 hash_table_higher_prime_index (unsigned long n)
 {
   unsigned int low = 0;
-  unsigned int high = sizeof (prime_tab) / sizeof (prime_tab[0]);
+  unsigned int high = ARRAY_SIZE (prime_tab);
 
   while (low != high)
     {
diff --git a/gcc/input.c b/gcc/input.c
index 82e79beab14..0db28462d62 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -3724,8 +3724,7 @@ for_each_line_table_case (void (*testcase) (const line_table_case &))
     {
       /* ...and use each of the "interesting" location values as
 	 the starting location within line_table.  */
-      const int num_boundary_locations
-	= sizeof (boundary_locations) / sizeof (boundary_locations[0]);
+      const int num_boundary_locations = ARRAY_SIZE (boundary_locations);
       for (int loc_idx = 0; loc_idx < num_boundary_locations; loc_idx++)
 	{
 	  line_table_case c (default_range_bits, boundary_locations[loc_idx]);
diff --git a/gcc/ipa-free-lang-data.cc b/gcc/ipa-free-lang-data.cc
index 431ced4dd17..0520e16a0f2 100644
--- a/gcc/ipa-free-lang-data.cc
+++ b/gcc/ipa-free-lang-data.cc
@@ -1109,9 +1109,7 @@ free_lang_data (void)
   free_lang_data_in_cgraph (&fld);
 
   /* Create gimple variants for common types.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   /* Reset some langhooks.  Do not reset types_compatible_p, it may
diff --git a/gcc/ipa-inline.c b/gcc/ipa-inline.c
index 9b70daf8976..2aae6ea0a0f 100644
--- a/gcc/ipa-inline.c
+++ b/gcc/ipa-inline.c
@@ -278,7 +278,7 @@ sanitize_attrs_match_for_inline_p (const_tree caller, const_tree callee)
       SANITIZE_POINTER_SUBTRACT
     };
 
-  for (unsigned i = 0; i < sizeof (codes) / sizeof (codes[0]); i++)
+  for (unsigned i = 0; i < ARRAY_SIZE (codes); i++)
     if (sanitize_flags_p (codes[i], caller)
 	!= sanitize_flags_p (codes[i], callee))
       return false;
diff --git a/gcc/jit/jit-builtins.c b/gcc/jit/jit-builtins.c
index 0b6210807be..a95f9213780 100644
--- a/gcc/jit/jit-builtins.c
+++ b/gcc/jit/jit-builtins.c
@@ -109,9 +109,7 @@ find_builtin_by_name (const char *in_name,
 
      We start at index 1 to skip the initial entry (BUILT_IN_NONE), which
      has a NULL name.  */
-  for (unsigned int i = 1;
-       i < sizeof (builtin_data) / sizeof (builtin_data[0]);
-       i++)
+  for (unsigned int i = 1; i < ARRAY_SIZE (builtin_data); i++)
     {
       const struct builtin_data& bd = builtin_data[i];
       if (matches_builtin (in_name, bd))
@@ -320,7 +318,7 @@ static const char * const type_names[] = {
 static const char *
 get_string_for_type_id (enum jit_builtin_type type_id)
 {
-  gcc_assert (type_id < sizeof (type_names)/sizeof(type_names[0]));
+  gcc_assert (type_id < ARRAY_SIZE (type_names));
   return type_names[type_id];
 }
 
diff --git a/gcc/jit/jit-recording.c b/gcc/jit/jit-recording.c
index ee8934131d1..10ca636e60f 100644
--- a/gcc/jit/jit-recording.c
+++ b/gcc/jit/jit-recording.c
@@ -568,9 +568,7 @@ recording::context::context (context *parent_ctxt)
   if (parent_ctxt)
     {
       /* Inherit options from parent.  */
-      for (unsigned i = 0;
-	   i < sizeof (m_str_options) / sizeof (m_str_options[0]);
-	   i++)
+      for (unsigned i = 0; i < ARRAY_SIZE (m_str_options); i++)
 	{
 	  const char *parent_opt = parent_ctxt->m_str_options[i];
 	  m_str_options[i] = parent_opt ? xstrdup (parent_opt) : NULL;
diff --git a/gcc/lto/lto-common.c b/gcc/lto/lto-common.c
index 853b3fbd856..8b0572b1283 100644
--- a/gcc/lto/lto-common.c
+++ b/gcc/lto/lto-common.c
@@ -2101,8 +2101,7 @@ lto_resolution_read (splay_tree file_ids, FILE *resolution, lto_file *file)
       char r_str[27];
       enum ld_plugin_symbol_resolution r = (enum ld_plugin_symbol_resolution) 0;
       unsigned int j;
-      unsigned int lto_resolution_str_len
-	= sizeof (lto_resolution_str) / sizeof (char *);
+      unsigned int lto_resolution_str_len = ARRAY_SIZE (lto_resolution_str);
       res_pair rp;
 
       t = fscanf (resolution, "%u " HOST_WIDE_INT_PRINT_HEX_PURE
diff --git a/gcc/lto/lto-lang.c b/gcc/lto/lto-lang.c
index a7f6f02c79c..4148bb96211 100644
--- a/gcc/lto/lto-lang.c
+++ b/gcc/lto/lto-lang.c
@@ -1319,9 +1319,7 @@ lto_init (void)
      distinction should only be relevant to the front-end, so we
      always use the C definition here in lto1.
      Likewise for const struct tm*.  */
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     {
       gcc_assert (builtin_structptr_types[i].node
 		  == builtin_structptr_types[i].base);
diff --git a/gcc/optc-save-gen.awk b/gcc/optc-save-gen.awk
index 34261a7ef44..7e996783bff 100644
--- a/gcc/optc-save-gen.awk
+++ b/gcc/optc-save-gen.awk
@@ -1104,7 +1104,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 	print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 	print "      return false;"
 }
@@ -1152,7 +1152,7 @@ for (i = 0; i < n_target_val; i++) {
 	print "  hstate.add_hwi (ptr->" name");";
 }
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 }
 
@@ -1192,7 +1192,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 }
 
@@ -1235,7 +1235,7 @@ for (i = 0; i < n_target_val; i++) {
 }
 
 if (has_target_explicit_mask) {
-	print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+	print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 	print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 }
 
@@ -1317,7 +1317,7 @@ for (i = 0; i < n_opt_val; i++) {
 	else
 		print "  hstate.add_hwi (ptr->" name");";
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    hstate.add_hwi (ptr->explicit_mask[i]);";
 print "  return hstate.end ();";
 print "}";
@@ -1346,7 +1346,7 @@ for (i = 0; i < n_opt_val; i++) {
 		print "    return false;";
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr1->explicit_mask) / sizeof (ptr1->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr1->explicit_mask); i++)";
 print "    if (ptr1->explicit_mask[i] != ptr2->explicit_mask[i])";
 print "      return false;"
 print "  return true;";
@@ -1380,7 +1380,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    bp_pack_value (bp, ptr->explicit_mask[i], 64);";
 print "}";
 
@@ -1412,7 +1412,7 @@ for (i = 0; i < n_opt_val; i++) {
 		}
 	}
 }
-print "  for (size_t i = 0; i < sizeof (ptr->explicit_mask) / sizeof (ptr->explicit_mask[0]); i++)";
+print "  for (size_t i = 0; i < ARRAY_SIZE (ptr->explicit_mask); i++)";
 print "    ptr->explicit_mask[i] = bp_unpack_value (bp, 64);";
 print "}";
 print "/* Free heap memory used by optimization options  */";
diff --git a/gcc/spellcheck.c b/gcc/spellcheck.c
index 6077bed7861..5875c10a96f 100644
--- a/gcc/spellcheck.c
+++ b/gcc/spellcheck.c
@@ -489,7 +489,7 @@ static const char * const test_data[] = {
 static void
 test_metric_conditions ()
 {
-  const int num_test_cases = sizeof (test_data) / sizeof (test_data[0]);
+  const int num_test_cases = ARRAY_SIZE (test_data);
 
   for (int i = 0; i < num_test_cases; i++)
     {
diff --git a/gcc/sreal.c b/gcc/sreal.c
index 960f0da6fd7..6dd23b27bb5 100644
--- a/gcc/sreal.c
+++ b/gcc/sreal.c
@@ -323,7 +323,7 @@ static void
 sreal_verify_arithmetics (void)
 {
   int values[] = {-14123413, -7777, -17, -10, -2, 0, 17, 139, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     for (unsigned j = 0; j < c; j++)
@@ -359,7 +359,7 @@ static void
 sreal_verify_shifting (void)
 {
   int values[] = {0, 17, 32, 139, 1024, 55555, 1234123};
-  unsigned c = sizeof (values) / sizeof (int);
+  unsigned c = ARRAY_SIZE (values);
 
   for (unsigned i = 0; i < c; i++)
     verify_shifting (values[i]);
diff --git a/gcc/tree-vect-slp-patterns.c b/gcc/tree-vect-slp-patterns.c
index 63fe75606ab..86b22941d0f 100644
--- a/gcc/tree-vect-slp-patterns.c
+++ b/gcc/tree-vect-slp-patterns.c
@@ -1584,4 +1584,4 @@ vect_pattern_decl_t slp_patterns[]
 #undef SLP_PATTERN
 
 /* Set the number of SLP pattern matchers available.  */
-size_t num__slp_patterns = sizeof(slp_patterns)/sizeof(vect_pattern_decl_t);
+size_t num__slp_patterns = ARRAY_SIZE (slp_patterns);
diff --git a/gcc/tree.c b/gcc/tree.c
index d98b77db50b..8489f586381 100644
--- a/gcc/tree.c
+++ b/gcc/tree.c
@@ -9295,9 +9295,7 @@ build_common_tree_nodes (bool signed_char)
   ptr_type_node = build_pointer_type (void_type_node);
   const_ptr_type_node
     = build_pointer_type (build_type_variant (void_type_node, 1, 0));
-  for (unsigned i = 0;
-       i < sizeof (builtin_structptr_types) / sizeof (builtin_structptr_type);
-       ++i)
+  for (unsigned i = 0; i < ARRAY_SIZE (builtin_structptr_types); ++i)
     builtin_structptr_types[i].node = builtin_structptr_types[i].base;
 
   pointer_sized_int_node = build_nonstandard_integer_type (POINTER_SIZE, 1);


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-09 10:54 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-04 12:31 [gcc(refs/users/marxin/heads/use-ARRAY_SIZE)] Use more ARRAY_SIZE Martin Liska
  -- strict thread matches above, loose matches on Subject: below --
2022-05-09 10:54 Martin Liska
2022-05-05 13:41 Martin Liska
2022-01-13 17:59 Martin Liska
2022-01-13 17:46 Martin Liska

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).