public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization.
@ 2021-10-12  2:23 crazylht at gmail dot com
  2021-10-12  7:14 ` [Bug middle-end/102697] " crazylht at gmail dot com
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2021-10-12  2:23 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

            Bug ID: 102697
           Summary: [Diagnostics] overflow warning missing after O2
                    vectorization.
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: crazylht at gmail dot com
                CC: msebor at gcc dot gnu.org
  Target Milestone: ---
              Host: x86_64-pc-linux-gnu

testcase is from Wstringop-overflow-76.c

It looks to me the testcase is not well written since variable i here could be
negative value, and d[6] may not overflow.

#define MAX(p, q) ((p) > (q) ? (p) : (q))
struct B4_B6
{
  char b4[4];
  char b6[6];       // { dg-message "at offset 6 into destination object 'b6'
of size 6" "note" }
};

void max_B6_B4 (int i, struct B4_B6 *pb4_b6)
{
char *p = pb4_b6->b6 + i;
char *q = pb4_b6->b4 + i;
  char *d = MAX (p, q);

  d[3] = 0;
  d[4] = 0;
  d[5] = 0;
  d[6] = 0;         // { dg-warning "writing 1 byte into a region of size 0 " }
}

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [Diagnostics] overflow warning missing after O2 vectorization.
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
@ 2021-10-12  7:14 ` crazylht at gmail dot com
  2021-10-12 15:44 ` [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization msebor at gcc dot gnu.org
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: crazylht at gmail dot com @ 2021-10-12  7:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

--- Comment #1 from Hongtao.liu <crazylht at gmail dot com> ---
Change i to 0, still missing warning after vectorization

before vectorization

void max_B6_B4 (int i, struct B4_B6 * pb4_b6)
{
  char * d;
  char * q;
  char * p;

  <bb 2> [local count: 1073741824]:
  [../test4.c:10:7] p_2 = [../test4.c:10:11] &[../test4.c:10:17]
pb4_b6_1(D)->b6;
  [../test4.c:11:7] q_3 = [../test4.c:11:11] &[../test4.c:11:17]
pb4_b6_1(D)->b4;
  [../test4.c:12:9] d_4 = MAX_EXPR <p_2, q_3>;
  [../test4.c:14:8] MEM <unsigned int> [(char *)d_4 + 3B] = 0;
  [../test4.c:18:1] return;

after vectorization:

;; Function max_B6_B4 (max_B6_B4, funcdef_no=0, decl_uid=4060, cgraph_uid=1,
symbol_order=0)

void max_B6_B4 (int i, struct B4_B6 * pb4_b6)
{
  char * d;
  char * q;
  char * p;

  <bb 2> [local count: 1073741824]:
  [test4.c:10:7] p_2 = [test4.c:10:11] &[test4.c:10:17] pb4_b6_1(D)->b6;
  [test4.c:11:7] q_3 = [test4.c:11:11] &[test4.c:11:17] pb4_b6_1(D)->b4;
  [test4.c:12:9] d_4 = MAX_EXPR <p_2, q_3>;
  [test4.c:14:8] MEM <vector(4) char> [(char *)d_4 + 3B] = { 0, 0, 0, 0 };
  [test4.c:18:1] return;

}
It looks like a false negative for -Wstringop-overflow=

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
  2021-10-12  7:14 ` [Bug middle-end/102697] " crazylht at gmail dot com
@ 2021-10-12 15:44 ` msebor at gcc dot gnu.org
  2021-10-12 19:14 ` pinskia at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-10-12 15:44 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[Diagnostics] overflow      |[12 Regression] overflow
                   |warning missing after O2    |warning missing after -O2
                   |vectorization.              |vectorization
   Last reconfirmed|                            |2021-10-12
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW

--- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed as a false negative and a GCC 12 regression.

The expected warning is based on the assumption that an unknown offset to a
subobject is non-negative.  This assumption is supported by the constraint that
pointer arithmetic must be confined to the [sub]object the pointer points to. 
I.e., it's not valid to form a pointer to one subobject by adding an offset to
a pointer to another [sub]object (even within the same object).  The same
constraint is enforced by -Warray-bounds.  The missing -Wstringop-overflow is
due to the hack mentioned in the following discussion:
  https://gcc.gnu.org/pipermail/gcc-patches/2021-September/580172.html

The warning is issued from the strlen pass which runs at -O2 and above.  It's
still issued when -fno-tree-vectorized is specified but should be issued even
with vectorization, and ideally at all optimization levels, including -O0.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
  2021-10-12  7:14 ` [Bug middle-end/102697] " crazylht at gmail dot com
  2021-10-12 15:44 ` [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization msebor at gcc dot gnu.org
@ 2021-10-12 19:14 ` pinskia at gcc dot gnu.org
  2021-10-20  2:13 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-10-12 19:14 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |12.0

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
                   ` (2 preceding siblings ...)
  2021-10-12 19:14 ` pinskia at gcc dot gnu.org
@ 2021-10-20  2:13 ` cvs-commit at gcc dot gnu.org
  2021-12-16 20:00 ` msebor at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-10-20  2:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

https://gcc.gnu.org/g:3c8d8c0be95e99dc0cba7f6fad2429243582119f

commit r12-4523-g3c8d8c0be95e99dc0cba7f6fad2429243582119f
Author: liuhongt <hongtao.liu@intel.com>
Date:   Thu Oct 14 09:31:03 2021 +0800

    Adjust testcase for O2 vectorization.

    As discussed in [1], this patch add xfail/target selector to those
    testcases, also make a copy of them so that they can be tested w/o
    vectorization.

    Newly added xfail/target selectors are used to check the vectorization
    capability of continuous byte/double bytes storage, these scenarios
    are exactly the part of the testcases that regressed after O2
    vectorization.

    [1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581456.html.

    2021-10-19  Hongtao Liu  <hongtao.liu@intel.com>
                Kewen Lin  <linkw@linux.ibm.com>

    gcc/ChangeLog

            * doc/sourcebuild.texi (Effective-Target Keywords): Document
            vect_slp_v2qi_store, vect_slp_v4qi_store, vect_slp_v8qi_store,
            vect_slp_v16qi_store, vect_slp_v2hi_store,
            vect_slp_v4hi_store, vect_slp_v2si_store, vect_slp_v4si_store.

    gcc/testsuite/ChangeLog

            PR middle-end/102722
            PR middle-end/102697
            PR middle-end/102462
            PR middle-end/102706
            PR middle-end/102744
            * c-c++-common/Wstringop-overflow-2.c: Adjust testcase with new
            xfail/target selector.
            * gcc.dg/Warray-bounds-51.c: Ditto.
            * gcc.dg/Warray-parameter-3.c: Ditto.
            * gcc.dg/Wstringop-overflow-14.c: Ditto.
            * gcc.dg/Wstringop-overflow-21.c: Ditto.
            * gcc.dg/Wstringop-overflow-68.c: Ditto.
            * gcc.dg/Wstringop-overflow-76.c: Ditto.
            * gcc.dg/Warray-bounds-48.c: Ditto.
            * gcc.dg/Wzero-length-array-bounds-2.c: Ditto.
            * lib/target-supports.exp (check_vect_slp_aligned_store_usage):
            New function.
            (check_effective_target_vect_slp_v2qi_store): Ditto.
            (check_effective_target_vect_slp_v4qi_store): Ditto.
            (check_effective_target_vect_slp_v8qi_store): Ditto.
            (check_effective_target_vect_slp_v16qi_store): Ditto.
            (check_effective_target_vect_slp_v2hi_store): Ditto.
            (check_effective_target_vect_slp_v4hi_store): Ditto.
            (check_effective_target_vect_slp_v2si_store): Ditto.
            (check_effective_target_vect_slp_v4si_store): Ditto.
            * c-c++-common/Wstringop-overflow-2-novec.c: New test.
            * gcc.dg/Warray-bounds-51-novec.c: New test.
            * gcc.dg/Warray-bounds-48-novec.c: New test.
            * gcc.dg/Warray-parameter-3-novec.c: New test.
            * gcc.dg/Wstringop-overflow-14-novec.c: New test.
            * gcc.dg/Wstringop-overflow-21-novec.c: New test.
            * gcc.dg/Wstringop-overflow-76-novec.c: New test.
            * gcc.dg/Wzero-length-array-bounds-2-novec.c: New test.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
                   ` (3 preceding siblings ...)
  2021-10-20  2:13 ` cvs-commit at gcc dot gnu.org
@ 2021-12-16 20:00 ` msebor at gcc dot gnu.org
  2022-05-06  8:31 ` [Bug middle-end/102697] [12/13 " jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: msebor at gcc dot gnu.org @ 2021-12-16 20:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

--- Comment #4 from Martin Sebor <msebor at gcc dot gnu.org> ---
The warning for the test in comment #0 fails to trigger because of the hack
below in pointer-query.cc:

/* A helper of compute_objsize_r() to determine the size from MEM_REF
   MREF.  Return true on success and false on failure.  */

static bool
handle_mem_ref (tree mref, gimple *stmt, int ostype, access_ref *pref,
                ssa_name_limit_t &snlim, pointer_query *qry)
{
  gcc_assert (TREE_CODE (mref) == MEM_REF);

  tree mreftype = TYPE_MAIN_VARIANT (TREE_TYPE (mref));
  if (VECTOR_TYPE_P (mreftype))
      {
      /* Hack: Handle MEM_REFs of vector types as those to complete
         objects; those may be synthesized from multiple assignments
         to consecutive data members (see PR 93200 and 96963).
         FIXME: Vectorized assignments should only be present after
         vectorization so this hack is only necessary after it has
         run and could be avoided in calls from prior passes (e.g.,
         tree-ssa-strlen.c).
         FIXME: Deal with this more generally, e.g., by marking up
         such MEM_REFs at the time they're created.  */
      ostype = 0;
    }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12/13 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
                   ` (4 preceding siblings ...)
  2021-12-16 20:00 ` msebor at gcc dot gnu.org
@ 2022-05-06  8:31 ` jakub at gcc dot gnu.org
  2022-07-26 13:24 ` rguenth at gcc dot gnu.org
  2023-05-08 12:22 ` [Bug middle-end/102697] [12/13/14 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-05-06  8:31 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.0                        |12.2

--- Comment #5 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 12.1 is being released, retargeting bugs to GCC 12.2.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12/13 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
                   ` (5 preceding siblings ...)
  2022-05-06  8:31 ` [Bug middle-end/102697] [12/13 " jakub at gcc dot gnu.org
@ 2022-07-26 13:24 ` rguenth at gcc dot gnu.org
  2023-05-08 12:22 ` [Bug middle-end/102697] [12/13/14 " rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-26 13:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [Bug middle-end/102697] [12/13/14 Regression] overflow warning missing after -O2 vectorization
  2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
                   ` (6 preceding siblings ...)
  2022-07-26 13:24 ` rguenth at gcc dot gnu.org
@ 2023-05-08 12:22 ` rguenth at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-05-08 12:22 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102697

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|12.3                        |12.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 12.3 is being released, retargeting bugs to GCC 12.4.

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2023-05-08 12:22 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-12  2:23 [Bug middle-end/102697] New: [Diagnostics] overflow warning missing after O2 vectorization crazylht at gmail dot com
2021-10-12  7:14 ` [Bug middle-end/102697] " crazylht at gmail dot com
2021-10-12 15:44 ` [Bug middle-end/102697] [12 Regression] overflow warning missing after -O2 vectorization msebor at gcc dot gnu.org
2021-10-12 19:14 ` pinskia at gcc dot gnu.org
2021-10-20  2:13 ` cvs-commit at gcc dot gnu.org
2021-12-16 20:00 ` msebor at gcc dot gnu.org
2022-05-06  8:31 ` [Bug middle-end/102697] [12/13 " jakub at gcc dot gnu.org
2022-07-26 13:24 ` rguenth at gcc dot gnu.org
2023-05-08 12:22 ` [Bug middle-end/102697] [12/13/14 " rguenth at gcc dot gnu.org

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).