public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Jeff Law <law@redhat.com>,
	Rainer Orth <ro@cebitec.uni-bielefeld.de>,
	       Mike Stump <mikestump@comcast.net>,
	Martin Sebor <msebor@gmail.com>
Cc: Siddhesh Poyarekar <siddhesh@gotplt.org>,
	       Gcc Patch List <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] correct -Wrestrict handling of arrays of arrays (PR 84095)
Date: Fri, 23 Feb 2018 16:49:00 -0000	[thread overview]
Message-ID: <20180223162530.GB5867@tucnak> (raw)
In-Reply-To: <ed293e7f-a4b7-1dc0-0f16-b3f5599dd98d@gmail.com>

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  <jakub@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

      parent reply	other threads:[~2018-02-23 16:49 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-30 23:37 Martin Sebor
2018-02-01 23:45 ` Martin Sebor
2018-02-09  2:46   ` Martin Sebor
2018-02-14  6:14   ` Jeff Law
2018-02-15 17:48     ` Martin Sebor
2018-02-16 23:39       ` Jeff Law
2018-02-23  3:17   ` Siddhesh Poyarekar
2018-02-23 15:52     ` Martin Sebor
2018-02-23 16:19       ` Siddhesh Poyarekar
2018-02-23 16:49       ` Jakub Jelinek [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180223162530.GB5867@tucnak \
    --to=jakub@redhat.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=law@redhat.com \
    --cc=mikestump@comcast.net \
    --cc=msebor@gmail.com \
    --cc=ro@cebitec.uni-bielefeld.de \
    --cc=siddhesh@gotplt.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).