public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Richard Biener <richard.guenther@gmail.com>
To: Ilya Enkovich <enkovich.gnu@gmail.com>
Cc: Bernd Schmidt <bschmidt@redhat.com>,
	GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH, PR68337] Don't fold memcpy/memmove we want to instrument
Date: Mon, 23 Nov 2015 15:35:00 -0000	[thread overview]
Message-ID: <CAFiYyc2MQ7gyBmOR5STKyPWjtOUwOmeMV7SUzd3HoGDCe7CDYw@mail.gmail.com> (raw)
In-Reply-To: <20151123134505.GC11184@msticlxl57.ims.intel.com>

On Mon, Nov 23, 2015 at 2:45 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
> On 23 Nov 14:29, Richard Biener wrote:
>> On Mon, Nov 23, 2015 at 12:33 PM, Ilya Enkovich <enkovich.gnu@gmail.com> wrote:
>> >
>> > I see.  But it should still be OK to check type in case of strict aliasing, right?
>>
>> No, memcpy is always "no-strict-aliasing"
>>
>
> Thanks a lot for help!  Here is a variant with a size check only as
> you originally suggested.  Is it OK for trunk and gcc-5-branch if
> no regressions?

Ok.

Thanks,
Richard.

> Thanks,
> Ilya
> --
> gcc/
>
> 2015-11-23  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
>         * gimple-fold.c: Include ipa-chkp.h.
>         (gimple_fold_builtin_memory_op): Don't fold call if we
>         are going to instrument it and it may copy pointers.
>
> gcc/testsuite/
>
> 2015-11-23  Ilya Enkovich  <enkovich.gnu@gmail.com>
>
>         * gcc.target/i386/mpx/pr68337-1.c: New test.
>         * gcc.target/i386/mpx/pr68337-2.c: New test.
>
>
> diff --git a/gcc/gimple-fold.c b/gcc/gimple-fold.c
> index 1ab20d1..6ff5e26 100644
> --- a/gcc/gimple-fold.c
> +++ b/gcc/gimple-fold.c
> @@ -53,6 +53,7 @@ along with GCC; see the file COPYING3.  If not see
>  #include "gomp-constants.h"
>  #include "optabs-query.h"
>  #include "omp-low.h"
> +#include "ipa-chkp.h"
>
>
>  /* Return true when DECL can be referenced from current unit.
> @@ -664,6 +665,18 @@ gimple_fold_builtin_memory_op (gimple_stmt_iterator *gsi,
>        unsigned int src_align, dest_align;
>        tree off0;
>
> +      /* Inlining of memcpy/memmove may cause bounds lost (if we copy
> +        pointers as wide integer) and also may result in huge function
> +        size because of inlined bounds copy.  Thus don't inline for
> +        functions we want to instrument.  */
> +      if (flag_check_pointer_bounds
> +         && chkp_instrumentable_p (cfun->decl)
> +         /* Even if data may contain pointers we can inline if copy
> +            less than a pointer size.  */
> +         && (!tree_fits_uhwi_p (len)
> +             || compare_tree_int (len, POINTER_SIZE_UNITS) >= 0))
> +       return false;
> +
>        /* Build accesses at offset zero with a ref-all character type.  */
>        off0 = build_int_cst (build_pointer_type_for_mode (char_type_node,
>                                                          ptr_mode, true), 0);
> diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c b/gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c
> new file mode 100644
> index 0000000..3f8d79d
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/mpx/pr68337-1.c
> @@ -0,0 +1,32 @@
> +/* { dg-do run } */
> +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
> +
> +#include "mpx-check.h"
> +
> +#define N 2
> +
> +extern void abort ();
> +
> +static int
> +mpx_test (int argc, const char **argv)
> +{
> +  char ** src = (char **)malloc (sizeof (char *) * N);
> +  char ** dst = (char **)malloc (sizeof (char *) * N);
> +  int i;
> +
> +  for (i = 0; i < N; i++)
> +    src[i] = __bnd_set_ptr_bounds (argv[0] + i, i + 1);
> +
> +  __builtin_memcpy(dst, src, sizeof (char *) * N);
> +
> +  for (i = 0; i < N; i++)
> +    {
> +      char *p = dst[i];
> +      if (p != argv[0] + i
> +         || __bnd_get_ptr_lbound (p) != p
> +         || __bnd_get_ptr_ubound (p) != p + i)
> +       abort ();
> +    }
> +
> +  return 0;
> +}
> diff --git a/gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c b/gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c
> new file mode 100644
> index 0000000..8845cca
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/mpx/pr68337-2.c
> @@ -0,0 +1,9 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fcheck-pointer-bounds -mmpx" } */
> +/* { dg-final { scan-assembler-not "memcpy" } } */
> +
> +void
> +test (void *dst, void *src)
> +{
> +  __builtin_memcpy (dst, src, sizeof (char *) / 2);
> +}

      reply	other threads:[~2015-11-23 15:33 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-19 16:31 Ilya Enkovich
2015-11-19 17:12 ` Bernd Schmidt
2015-11-19 17:19   ` Richard Biener
2015-11-20 13:08     ` Ilya Enkovich
2015-11-20 13:54       ` Richard Biener
2015-11-20 14:30         ` Ilya Enkovich
2015-11-23  9:40           ` Richard Biener
2015-11-23 10:12             ` Ilya Enkovich
2015-11-23 10:55               ` Richard Biener
2015-11-23 11:41                 ` Ilya Enkovich
2015-11-23 13:31                   ` Richard Biener
2015-11-23 13:47                     ` Ilya Enkovich
2015-11-23 15:35                       ` Richard Biener [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=CAFiYyc2MQ7gyBmOR5STKyPWjtOUwOmeMV7SUzd3HoGDCe7CDYw@mail.gmail.com \
    --to=richard.guenther@gmail.com \
    --cc=bschmidt@redhat.com \
    --cc=enkovich.gnu@gmail.com \
    --cc=gcc-patches@gcc.gnu.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).