On Fri, Feb 23, 2018 at 08:52:19AM -0700, Martin Sebor wrote:
> There are a large number of failures in these reports in many
> tests that were reported previously (before r257910), suggesting
> something else is wrong.  They all seem to use -fpic.
> 
> If you referring to some other report or your own result please
> post a link or say what target/configuration, etc..

The testcase clearly relies on inlining all the wrap_* functions,
but as they are void wrap_* with -fpic/-fPIC obviously they can't be
inlined at -O2, the executable or some other shared library might define
some other implementation of those and interpose it.
Some targets default to -fpic even.

The following patch just adds static inline to them, so that it works
even with -fpic, as tested with:
make check-gcc check-g++ RUNTESTFLAGS='--target_board=unix\{,-fpic,-fpie\} 
dg.exp=Warray-bounds*'

Ok for trunk?

2018-02-23  Jakub Jelinek  <ja...@redhat.com>

        * c-c++-common/Warray-bounds-2.c (wrap_memcpy_src_xsize,
        wrap_memcpy_src_diff_max, wrap_memcpy_dst_xsize,
        wrap_memcpy_dst_diff_max, wrap_strcat_src_xsize,
        wrap_strcat_dst_xsize, wrap_strcpy_src_xsize,
        wrap_strcpy_dst_xsize, wrap_strncpy_src_xsize,
        wrap_strncpy_src_diff_max, wrap_strncpy_dst_xsize,
        wrap_strncpy_dst_diff_max, wrap_strncpy_dstarray_diff_neg): Add
        static inline.

--- gcc/testsuite/c-c++-common/Warray-bounds-2.c.jj     2017-12-18 
14:57:15.601127538 +0100
+++ gcc/testsuite/c-c++-common/Warray-bounds-2.c        2018-02-23 
17:12:47.114113757 +0100
@@ -1,4 +1,4 @@
-/* Test to exercise that -Warray-bounds warnings for memory and sring
+/* Test to exercise that -Warray-bounds warnings for memory and string
    functions are issued even when they are declared in system headers
    (i.e., not just when they are explicitly declared in the source
    file.)
@@ -24,7 +24,7 @@ struct __attribute__ ((packed)) Array
 
 /* Exercise memcpy out-of-bounds offsets with an array of known size.  */
 
-void wrap_memcpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_memcpy_src_xsize (char *d, const char *s, ptrdiff_t i, 
size_t n)
 {
   memcpy (d, s + i, n);   /* { dg-warning "offset 46 is out of the bounds 
\\\[0, 45] of object .ar. with type .(struct )?Array." "memcpy" } */
 }
@@ -39,7 +39,7 @@ void call_memcpy_src_xsize (char *d, siz
 
 /* Exercise memcpy out-of-bounds offsets with an array of unknown size.  */
 
-void wrap_memcpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_memcpy_src_diff_max (char *d, const char *s, ptrdiff_t 
i, size_t n)
 {
   memcpy (d, s + i, n);   /* { dg-warning "pointer overflow between offset 
\[0-9\]+ and size 3" "memcpy" } */
 }
@@ -49,7 +49,7 @@ void call_memcpy_src_diff_max (char *d,
   wrap_memcpy_src_diff_max (d, s, MAX, 3);
 }
 
-void wrap_memcpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_memcpy_dst_xsize (char *d, const char *s, ptrdiff_t i, 
size_t n)
 {
   memcpy (d + i, s, n);   /* { dg-warning "offset 47 is out of the bounds 
\\\[0, 45] of object .ar1. with type .(struct )?Array." "memcpy" } */
 }
@@ -62,7 +62,7 @@ void call_memcpy_dst_xsize (const char *
   sink (&ar1);
 }
 
-void wrap_memcpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_memcpy_dst_diff_max (char *d, const char *s, ptrdiff_t 
i, size_t n)
 {
   memcpy (d + i, s, n);   /* { dg-warning "offset -?\[0-9\]+ is out of the 
bounds \\\[0, 45] of object .ar2. with type .(struct )?Array." "memcpy" } */
 }
@@ -76,7 +76,7 @@ void call_memcpy_dst_diff_max (const cha
 }
 
 
-void wrap_strcat_src_xsize (char *d, const char *s, ptrdiff_t i)
+static inline void wrap_strcat_src_xsize (char *d, const char *s, ptrdiff_t i)
 {
   strcat (d, s + i);   /* { dg-warning "offset 46 is out of the bounds \\\[0, 
45] of object .ar3. with type .(struct )?Array." "strcat" } */
 }
@@ -89,7 +89,7 @@ void call_strcat_src_xsize (char *d)
   sink (&ar3);
 }
 
-void wrap_strcat_dst_xsize (char *d, const char *s, ptrdiff_t i)
+static inline void wrap_strcat_dst_xsize (char *d, const char *s, ptrdiff_t i)
 {
   strcat (d + i, s);   /* { dg-warning "offset 47 is out of the bounds \\\[0, 
45] of object .ar4. with type .(struct )?Array." "strcat" } */
 }
@@ -103,7 +103,7 @@ void call_strcat_dst_xsize (const char *
 }
 
 
-void wrap_strcpy_src_xsize (char *d, const char *s, ptrdiff_t i)
+static inline void wrap_strcpy_src_xsize (char *d, const char *s, ptrdiff_t i)
 {
   strcpy (d, s + i);   /* { dg-warning "offset 48 is out of the bounds \\\[0, 
45] of object .ar5. with type .(struct )?Array." "strcpy" } */
 }
@@ -116,7 +116,7 @@ void call_strcpy_src_xsize (char *d)
   sink (&ar5);
 }
 
-void wrap_strcpy_dst_xsize (char *d, const char *s, ptrdiff_t i)
+static inline void wrap_strcpy_dst_xsize (char *d, const char *s, ptrdiff_t i)
 {
   strcpy (d + i, s);   /* { dg-warning "offset 49 is out of the bounds \\\[0, 
45] of object .ar6. with type .(struct )?Array." "strcpy" } */
 }
@@ -132,7 +132,7 @@ void call_strcpy_dst_xsize (const char *
 
 /* Exercise strncpy out-of-bounds offsets with an array of known size.  */
 
-void wrap_strncpy_src_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_strncpy_src_xsize (char *d, const char *s, ptrdiff_t 
i, size_t n)
 {
   strncpy (d, s + i, n);   /* { dg-warning "offset 46 is out of the bounds 
\\\[0, 45] of object .ar7. with type '(struct )?Array." "strncpy" } */
 }
@@ -147,7 +147,7 @@ void call_strncpy_src_xsize (char *d, si
 
 /* Exercise strncpy out-of-bounds offsets with an array of unknown size.  */
 
-void wrap_strncpy_src_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_strncpy_src_diff_max (char *d, const char *s, 
ptrdiff_t i, size_t n)
 {
   /* Unlike in the similar call to memcpy(), there is no pointer
      overflow here because the size N is not added to the source
@@ -160,7 +160,7 @@ void call_strncpy_src_diff_max (char *d,
   wrap_strncpy_src_diff_max (d, s, MAX, 3);
 }
 
-void wrap_strncpy_dst_xsize (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_strncpy_dst_xsize (char *d, const char *s, ptrdiff_t 
i, size_t n)
 {
   strncpy (d + i, s, n);   /* { dg-warning "offset 47 is out of the bounds 
\\\[0, 45] of object .ar8. with type .(struct )?Array." "strncpy" } */
 }
@@ -173,7 +173,7 @@ void call_strncpy_dst_xsize (const char
   sink (&ar8);
 }
 
-void wrap_strncpy_dst_diff_max (char *d, const char *s, ptrdiff_t i, size_t n)
+static inline void wrap_strncpy_dst_diff_max (char *d, const char *s, 
ptrdiff_t i, size_t n)
 {
   strncpy (d + i, s, n);   /* { dg-warning "offset -\[0-9\]+ is out of the 
bounds \\\[0, 45] of object .ar9. with type .(struct )?Array." "strncpy" } */
 }
@@ -186,8 +186,7 @@ void call_strncpy_dst_diff_max (const ch
   sink (&ar9);
 }
 
-void wrap_strncpy_dstarray_diff_neg (char *d, const char *s, ptrdiff_t i,
-                                    size_t n)
+static inline void wrap_strncpy_dstarray_diff_neg (char *d, const char *s, 
ptrdiff_t i, size_t n)
 {
   strncpy (d + i, s, n);   /* { dg-warning "offset -\[0-9\]+ is out of the 
bounds \\\[0, 90] of object .ar10. with type .(struct )?Array ?\\\[2]." 
"strncpy" } */
 }


        Jakub

Reply via email to