diff --git a/locale/programs/ld-ctype.c b/locale/programs/ld-ctype.c
index 0fd141c..b43a640 100644
--- a/locale/programs/ld-ctype.c
+++ b/locale/programs/ld-ctype.c
@@ -41,6 +41,7 @@
 #include "locfile.h"
 
 #include <assert.h>
+#include <libc-internal.h>
 
 
 /* The bit used for representing a special class.  */
@@ -2535,8 +2536,16 @@ with character code range values one must use the absolute ellipsis `...'"));
 	      size_t cnt;
 
 	      for (cnt = 2; cnt < ctype->map_collection_nr; ++cnt)
-		if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0)
-		  break;
+		{
+		  /* GCC 5.1 emits a "array subscript is above array bounds"
+		     warning if compiled with -O3. It does not occur with -O2.
+		     Older or newer GCCs does not emit this warning.  */
+		  DIAG_PUSH_NEEDS_COMMENT;
+		  DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
+		  if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0)
+		    break;
+		  DIAG_POP_NEEDS_COMMENT;
+		}
 
 	      if (cnt < ctype->map_collection_nr)
 		free (now->val.str.startmb);
@@ -2808,8 +2817,16 @@ previous definition was here")));
 	  /* This could mean one of several things.  First test whether
 	     it's a character class name.  */
 	  for (cnt = 0; cnt < ctype->nr_charclass; ++cnt)
-	    if (strcmp (now->val.str.startmb, ctype->classnames[cnt]) == 0)
-	      break;
+	    {
+	      /* GCC 5.1 emits a "array subscript is above array bounds"
+		 warning if compiled with -O3. It does not occur with -O2.
+		 Older or newer GCCs does not emit this warning.  */
+	      DIAG_PUSH_NEEDS_COMMENT;
+	      DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
+	      if (strcmp (now->val.str.startmb, ctype->classnames[cnt]) == 0)
+		break;
+	      DIAG_POP_NEEDS_COMMENT;
+	    }
 	  if (cnt < ctype->nr_charclass)
 	    {
 	      class_bit = _ISwbit (cnt);
@@ -2818,8 +2835,16 @@ previous definition was here")));
 	      goto read_charclass;
 	    }
 	  for (cnt = 0; cnt < ctype->map_collection_nr; ++cnt)
-	    if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0)
-	      break;
+	    {
+	      /* GCC 5.1 emits a "array subscript is above array bounds"
+		 warning if compiled with -O3. It does not occur with -O2.
+		 Older or newer GCCs does not emit this warning.  */
+	      DIAG_PUSH_NEEDS_COMMENT;
+	      DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
+	      if (strcmp (now->val.str.startmb, ctype->mapnames[cnt]) == 0)
+		break;
+	      DIAG_POP_NEEDS_COMMENT;
+	    }
 	  if (cnt < ctype->map_collection_nr)
 	    {
 	      mapidx = cnt;
diff --git a/posix/bug-regex11.c b/posix/bug-regex11.c
index d3abe73..6497064 100644
--- a/posix/bug-regex11.c
+++ b/posix/bug-regex11.c
@@ -22,6 +22,9 @@
 #include <regex.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <assert.h>
+
+#define RM_MAX 5
 
 /* Tests supposed to match.  */
 struct
@@ -29,7 +32,7 @@ struct
   const char *pattern;
   const char *string;
   int flags, nmatch;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
 } tests[] = {
   /* Test for newline handling in regex.  */
   { "[^~]*~", "\nx~y", 0, 2, { { 0, 3 }, { -1, -1 } } },
@@ -93,7 +96,7 @@ int
 main (void)
 {
   regex_t re;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
   size_t i;
   int n, ret = 0;
 
@@ -120,16 +123,19 @@ main (void)
 	}
 
       for (n = 0; n < tests[i].nmatch; ++n)
-	if (rm[n].rm_so != tests[i].rm[n].rm_so
-              || rm[n].rm_eo != tests[i].rm[n].rm_eo)
-	  {
-	    if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+	{
+	  assert (n < RM_MAX);
+	  if (rm[n].rm_so != tests[i].rm[n].rm_so
+	      || rm[n].rm_eo != tests[i].rm[n].rm_eo)
+	    {
+	      if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+		break;
+	      printf ("%s: regexec %zd match failure rm[%d] %d..%d\n",
+		      tests[i].pattern, i, n, rm[n].rm_so, rm[n].rm_eo);
+	      ret = 1;
 	      break;
-	    printf ("%s: regexec %zd match failure rm[%d] %d..%d\n",
-		    tests[i].pattern, i, n, rm[n].rm_so, rm[n].rm_eo);
-	    ret = 1;
-	    break;
-	  }
+	    }
+	}
 
       regfree (&re);
     }
diff --git a/posix/bug-regex17.c b/posix/bug-regex17.c
index 8b9edfb..0168103 100644
--- a/posix/bug-regex17.c
+++ b/posix/bug-regex17.c
@@ -23,6 +23,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <locale.h>
+#include <assert.h>
+
+#define RM_MAX 5
 
 /* Tests supposed to match.  */
 struct
@@ -30,7 +33,7 @@ struct
   const char *pattern;
   const char *string;
   int flags, nmatch;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
 } tests[] = {
   /* U+00C4	\xc3\x84	LATIN CAPITAL LETTER A WITH DIAERESIS
      U+00D6	\xc3\x96	LATIN CAPITAL LETTER O WITH DIAERESIS
@@ -62,7 +65,7 @@ static int
 do_test (void)
 {
   regex_t re;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
   size_t i;
   int n, ret = 0;
 
@@ -88,16 +91,19 @@ do_test (void)
 	}
 
       for (n = 0; n < tests[i].nmatch; ++n)
-	if (rm[n].rm_so != tests[i].rm[n].rm_so
-              || rm[n].rm_eo != tests[i].rm[n].rm_eo)
-	  {
-	    if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+	{
+	  assert (n < RM_MAX);
+	  if (rm[n].rm_so != tests[i].rm[n].rm_so
+	      || rm[n].rm_eo != tests[i].rm[n].rm_eo)
+	    {
+	      if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+		break;
+	      printf ("regexec match failure rm[%d] %d..%d\n",
+		      n, rm[n].rm_so, rm[n].rm_eo);
+	      ret = 1;
 	      break;
-	    printf ("regexec match failure rm[%d] %d..%d\n",
-		    n, rm[n].rm_so, rm[n].rm_eo);
-	    ret = 1;
-	    break;
-	  }
+	    }
+	}
 
       regfree (&re);
     }
diff --git a/posix/bug-regex18.c b/posix/bug-regex18.c
index 6902f52..1a9c91b 100644
--- a/posix/bug-regex18.c
+++ b/posix/bug-regex18.c
@@ -23,6 +23,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <locale.h>
+#include <assert.h>
+
+#define RM_MAX 5
 
 /* Tests supposed to match.  */
 struct
@@ -30,7 +33,7 @@ struct
   const char *pattern;
   const char *string;
   int flags, nmatch;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
 } tests[] = {
   /* \xc4\xb0		LATIN CAPITAL LETTER I WITH DOT ABOVE
      \xc4\xb1		LATIN SMALL LETTER DOTLESS I
@@ -55,7 +58,7 @@ int
 main (void)
 {
   regex_t re;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
   size_t i;
   int n, ret = 0;
 
@@ -81,16 +84,19 @@ main (void)
 	}
 
       for (n = 0; n < tests[i].nmatch; ++n)
-	if (rm[n].rm_so != tests[i].rm[n].rm_so
-              || rm[n].rm_eo != tests[i].rm[n].rm_eo)
-	  {
-	    if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+	{
+	  assert (n < RM_MAX);
+	  if (rm[n].rm_so != tests[i].rm[n].rm_so
+	      || rm[n].rm_eo != tests[i].rm[n].rm_eo)
+	    {
+	      if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+		break;
+	      printf ("regexec match failure rm[%d] %d..%d\n",
+		      n, rm[n].rm_so, rm[n].rm_eo);
+	      ret = 1;
 	      break;
-	    printf ("regexec match failure rm[%d] %d..%d\n",
-		    n, rm[n].rm_so, rm[n].rm_eo);
-	    ret = 1;
-	    break;
-	  }
+	    }
+	}
 
       regfree (&re);
     }
diff --git a/posix/bug-regex30.c b/posix/bug-regex30.c
index e1ddf08..18362e0 100644
--- a/posix/bug-regex30.c
+++ b/posix/bug-regex30.c
@@ -23,6 +23,9 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <locale.h>
+#include <assert.h>
+
+#define RM_MAX 5
 
 /* Tests supposed to match.  */
 struct
@@ -30,7 +33,7 @@ struct
   const char *pattern;
   const char *string;
   int flags, nmatch;
-  regmatch_t rm[5];
+  regmatch_t rm[RM_MAX];
 } tests[] = {
   /* U+0413	\xd0\x93	CYRILLIC CAPITAL LETTER GHE
      U+0420	\xd0\xa0        CYRILLIC CAPITAL LETTER ER
@@ -61,7 +64,7 @@ do_test (void)
   for (size_t i = 0; i < sizeof (tests) / sizeof (tests[0]); ++i)
     {
       regex_t re;
-      regmatch_t rm[5];
+      regmatch_t rm[RM_MAX];
       int n = regcomp (&re, tests[i].pattern, tests[i].flags);
       if (n != 0)
 	{
@@ -81,16 +84,19 @@ do_test (void)
 	}
 
       for (n = 0; n < tests[i].nmatch; ++n)
-	if (rm[n].rm_so != tests[i].rm[n].rm_so
+	{
+	  assert (n < RM_MAX);
+	  if (rm[n].rm_so != tests[i].rm[n].rm_so
 	      || rm[n].rm_eo != tests[i].rm[n].rm_eo)
-	  {
-	    if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+	    {
+	      if (tests[i].rm[n].rm_so == -1 && tests[i].rm[n].rm_eo == -1)
+		break;
+	      printf ("regexec match failure rm[%d] %d..%d\n",
+		      n, rm[n].rm_so, rm[n].rm_eo);
+	      ret = 1;
 	      break;
-	    printf ("regexec match failure rm[%d] %d..%d\n",
-		    n, rm[n].rm_so, rm[n].rm_eo);
-	    ret = 1;
-	    break;
-	  }
+	    }
+	}
 
       regfree (&re);
     }
diff --git a/resolv/gethnamaddr.c b/resolv/gethnamaddr.c
index 3a8e9b1..502c883 100644
--- a/resolv/gethnamaddr.c
+++ b/resolv/gethnamaddr.c
@@ -71,6 +71,7 @@ static char sccsid[] = "@(#)gethostnamadr.c	8.1 (Berkeley) 6/4/93";
 #include <ctype.h>
 #include <errno.h>
 #include <syslog.h>
+#include <libc-internal.h>
 
 #define RESOLVSORT
 
@@ -965,9 +966,17 @@ addrsort (char **ap, int num)
 	p = ap;
 	for (i = 0; i < num; i++, p++) {
 	    for (j = 0 ; (unsigned)j < _res.nsort; j++)
+	      {
+		/* GCC 5.1 emits a "array subscript is above array bounds"
+		   warning if compiled with -O3. It does not occur with -O2.
+		   Older or newer GCCs does not emit this warning.  */
+		DIAG_PUSH_NEEDS_COMMENT;
+		DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
 		if (_res.sort_list[j].addr.s_addr ==
 		    (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
 			break;
+		DIAG_POP_NEEDS_COMMENT;
+	      }
 	    aval[i] = j;
 	    if (needsort == 0 && i > 0 && j < aval[i-1])
 		needsort = i;
diff --git a/resolv/nss_dns/dns-host.c b/resolv/nss_dns/dns-host.c
index a255d5e..a27e776 100644
--- a/resolv/nss_dns/dns-host.c
+++ b/resolv/nss_dns/dns-host.c
@@ -86,6 +86,8 @@
 #include <resolv/mapv4v6addr.h>
 #include <resolv/mapv4v6hostent.h>
 
+#include <libc-internal.h>
+
 #define RESOLVSORT
 
 #if PACKETSZ > 65536
@@ -562,9 +564,17 @@ addrsort (char **ap, int num)
   for (i = 0; i < num; i++, p++)
     {
       for (j = 0 ; (unsigned)j < _res.nsort; j++)
-	if (_res.sort_list[j].addr.s_addr ==
-	    (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
-	  break;
+	{
+	  /* GCC 5.1 emits a "array subscript is above array bounds"
+	     warning if compiled with -O3. It does not occur with -O2.
+	     Older or newer GCCs does not emit this warning.  */
+	  DIAG_PUSH_NEEDS_COMMENT;
+	  DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
+	  if (_res.sort_list[j].addr.s_addr ==
+	      (((struct in_addr *)(*p))->s_addr & _res.sort_list[j].mask))
+	    break;
+	  DIAG_POP_NEEDS_COMMENT;
+	}
       aval[i] = j;
       if (needsort == 0 && i > 0 && j < aval[i-1])
 	needsort = i;
diff --git a/resolv/res_hconf.c b/resolv/res_hconf.c
index 5cd1289..1d95dba 100644
--- a/resolv/res_hconf.c
+++ b/resolv/res_hconf.c
@@ -46,6 +46,7 @@
 #include "res_hconf.h"
 #include <wchar.h>
 #include <atomic.h>
+#include <libc-internal.h>
 
 #if IS_IN (libc)
 # define fgets_unlocked __fgets_unlocked
@@ -577,7 +578,13 @@ _res_hconf_trim_domain (char *hostname)
 
   for (i = 0; i < _res_hconf.num_trimdomains; ++i)
     {
+      /* GCC 5.1 emits a "array subscript is above array bounds" warning
+	 if compiled with -O3. It does not occur with -O2.
+	 Older or newer GCCs does not emit this warning.  */
+      DIAG_PUSH_NEEDS_COMMENT;
+      DIAG_IGNORE_NEEDS_COMMENT (5.1, "-Warray-bounds");
       const char *trim = _res_hconf.trimdomain[i];
+      DIAG_POP_NEEDS_COMMENT;
 
       trim_len = strlen (trim);
       if (hostname_len > trim_len
diff --git a/string/test-string.h b/string/test-string.h
index 728a7c2..9e35aaf 100644
--- a/string/test-string.h
+++ b/string/test-string.h
@@ -51,6 +51,7 @@ extern impl_t __start_impls[], __stop_impls[];
 #include <errno.h>
 #include <time.h>
 #include <ifunc-impl-list.h>
+#include <assert.h>
 #define GL(x) _##x
 #define GLRO(x) _##x
 
@@ -106,7 +107,8 @@ size_t iterations = 100000;
 
 #ifdef TEST_NAME
 /* Increase size of FUNC_LIST if assert is triggered at run-time.  */
-static struct libc_ifunc_impl func_list[32];
+# define FUNC_LIST_MAX 32
+static struct libc_ifunc_impl func_list[FUNC_LIST_MAX];
 static int func_count;
 static int impl_count = -1;
 static impl_t *impl_array;
@@ -132,13 +134,16 @@ static impl_t *impl_array;
 	    if (impl != skip)						\
 	      *a++ = *impl;						\
 	  for (f = 0; f < func_count; f++)				\
-	    if (func_list[f].usable)					\
-	      {								\
-		a->name = func_list[f].name;				\
-		a->fn = func_list[f].fn;				\
-		a->test = 1;						\
-		a++;							\
-	      }								\
+	    {								\
+	      assert (f < FUNC_LIST_MAX);				\
+	      if (func_list[f].usable)					\
+		{							\
+		  a->name = func_list[f].name;				\
+		  a->fn = func_list[f].fn;				\
+		  a->test = 1;						\
+		  a++;							\
+		}							\
+	    }								\
 	  impl_count = a - impl_array;					\
 	}								\
       else								\
