On 9/28/21 1:20 AM, Richard Biener wrote:
On Mon, 27 Sep 2021, sunil.k.pandey wrote:

On Linux/x86_64,

d06dc8a2c73735e9496f434787ba4c93ceee5eea is the first bad commit
commit d06dc8a2c73735e9496f434787ba4c93ceee5eea
Author: Richard Biener <rguent...@suse.de>
Date:   Mon Sep 27 13:36:12 2021 +0200

     middle-end/102450 - avoid type_for_size for non-existing modes

caused

FAIL: gcc.dg/out-of-bounds-1.c  (test for warnings, line 12)
FAIL: gcc.dg/pr78408-1.c scan-tree-dump-times fab1 "after previous" 17
FAIL: gcc.dg/strlenopt-13.c scan-tree-dump-times strlen1 "memcpy \\(" 7

After the change the new memcpy inlining limit using MOVE_MAX * MOVE_RATIO
comes into play and ends up using an OImode move which previously was
disregarded as there's no __int256 standard type in the frontend
(but now we build such type anyway after verifying the mode exists and
it has move support).

For example gcc.dg/out-of-bounds-1.c which looks like

void ProjectOverlay(const float localTextureAxis[2], char *lump)
{
    const void *d = &localTextureAxis;
    int size = sizeof(float)*8 ;
    __builtin_memcpy( &lump[ 0 ], d, size );  /* { dg-warning "reading" }
*/
}

gets turned into

         movq    %rdi, -8(%rsp)
         vmovdqu64       -8(%rsp), %ymm31
         vmovdqu64       %ymm31, (%rsi)

which I guess is good but then the diagnostic is no longer emitted
because -Wstringop-overread only applies to the builtin.  Usually
we avoid the folding in such a case but

               /* Detect out-of-bounds accesses without issuing warnings.
                  Avoid folding out-of-bounds copies but to avoid false
                  positives for unreachable code defer warning until after
                  DCE has worked its magic.
                  -Wrestrict is still diagnosed.  */
               if (int warning = check_bounds_or_overlap (as_a <gcall
*>(stmt),
                                                          dest, src, len,
len,
                                                          false, false))
                 if (warning != OPT_Wrestrict)
                   return false;

The check_bounds_or_overlap() call only implements -Wrestrict and
a small subset of -Warray-bounds (the subset issued for forming
out-of-bounds pointers by built-ins).  It's a limitation/bug in
the gimple-ssa-warn-restrict.c code that it doesn't detect
the problem (it's confused by taking the address of a pointer).

To let the test pass I suggest either bumping up the size or making
it an odd number (or anything else that's not a power of 2).


does not seem to trigger here.  Changing the testcase to

void ProjectOverlay(const float localTextureAxis[2], char *lump)
{
    const void *d = &localTextureAxis;
    int size = sizeof(float)*4 ;
    __builtin_memcpy( &lump[ 0 ], d, size );  /* { dg-warning "reading" }
*/
}

also fails to warn.

The very late -Wstringop-{overflow,overread} warnings that run just
before expansion have historically only worked for built-in calls.
Now that they are in a GIMPLE pass of their own as opposed to
working with trees in builtins.c, it will be easy to handle plain
stores as well.  It's on my list of things to do.

Martin


Richard.


Reply via email to