public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
@ 2022-07-27 18:43 qinzhao at gcc dot gnu.org
  2022-07-28  8:07 ` [Bug tree-optimization/106457] " rguenth at gcc dot gnu.org
                   ` (8 more replies)
  0 siblings, 9 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-07-27 18:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 106457
           Summary: array_at_struct_end_p returns TRUE for a two-dimension
                    array which is not inside any structure
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: qinzhao at gcc dot gnu.org
  Target Milestone: ---

During my work on updating array_at_struct_end_p with the new
-fstrict-flex-array control, I noticed the following issue in the routine
"array_at_struct_end_p" for the following small testing case:
gcc/testsuite/g++.dg/debug/debug5.C

// { dg-do compile }
// { dg-require-effective-target alloca }

int foo()
{
  int a = 1;
  int b = 1;
  int e[a][b];
  e[0][0] = 0;
  return e[a-1][b-1];
}


when compiled with -O1 with the latest trunk gcc, when I used the gdb to debug
it as:

(gdb) break array_at_struct_end_p
Breakpoint 1 at 0x1d4cdf8: file ../../latest_gcc/gcc/tree.cc, line 12690.
(gdb) run
Starting program: /home/opc/Work/GCC/build/gcc/cc1plus -quiet -iprefix
/home/opc/Work/GCC/build/gcc/../lib/gcc/aarch64-unknown-linux-gnu/13.0.0/
-isystem /home/opc/Work/GCC/build/gcc/testsuite/g++/../../include -isystem
/home/opc/Work/GCC/build/gcc/testsuite/g++/../../include-fixed -D_GNU_SOURCE
t.C -quiet -dumpbase debug5.C -dumpbase-ext .C -mlittle-endian -mabi=lp64 -O1
-o debug5.s
...

Breakpoint 1, array_at_struct_end_p (ref=0xfffff57a2b88) at
../../latest_gcc/gcc/tree.cc:12690
12690     if (TREE_CODE (ref) == ARRAY_REF
...
(gdb) break 12784
Breakpoint 2 at 0x1d4d50c: file ../../latest_gcc/gcc/tree.cc, line 12784.
(gdb) c
Continuing.

Breakpoint 2, array_at_struct_end_p (ref=0xfffff5771a70) at
../../latest_gcc/gcc/tree.cc:12784
12784         if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
(gdb) n
12786             || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) !=
INTEGER_CST)
(gdb) n
12784         if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
(gdb) n
12787           return true;
(gdb) n
12803   }

it's obvious that the array reference " e[0][0]" is NOT an array at the end of
a structure. 

the utility routine "array_at_struct_end_p" should NOT result true for such
array reference.

We should fix this issue in this routine.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
@ 2022-07-28  8:07 ` rguenth at gcc dot gnu.org
  2022-07-28 12:35 ` cvs-commit at gcc dot gnu.org
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-28  8:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2022-07-28
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
e[0][0] should be handled here:

  tree ref_to_array = ref;
  while (handled_component_p (ref))
    {
...
      /* If we have a multi-dimensional array we do not consider
         a non-innermost dimension as flex array if the whole
         multi-dimensional array is at struct end.
         Same for an array of aggregates with a trailing array
         member.  */
      else if (TREE_CODE (ref) == ARRAY_REF)
        return false;

maybe you are refering to e[0]?

In that case the issue is that we fail to consider the case when there is
no known padding.  One would be if DECL_P (TREE_OPERAND (ref_to_array, 0)),
if the whole object is the array itself.  Thus

diff --git a/gcc/tree.cc b/gcc/tree.cc
index 84000dd8b69..aaac7610f9c 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -12778,6 +12778,10 @@ array_at_struct_end_p (tree ref)
       && DECL_SIZE_UNIT (ref)
       && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
     {
+      /* If the object itself is the array it is not at struct end.  */
+      if (DECL_P (TREE_OPERAND (ref_to_array, 0)))
+       return false;
+
       /* Check whether the array domain covers all of the available
          padding.  */
       poly_int64 offset;

we might be able to play tricks with alignment as well, if the alignment
of the object is the same or less as that of the array element alignment
(not sure if we can trust the alignment of the array element type here),
there's no room for padding.  But maybe that breaks in strange cases.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
  2022-07-28  8:07 ` [Bug tree-optimization/106457] " rguenth at gcc dot gnu.org
@ 2022-07-28 12:35 ` cvs-commit at gcc dot gnu.org
  2022-07-28 12:36 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-07-28 12:35 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:ff26f0ba68fe6e870f315d0601b596f889b89680

commit r13-1875-gff26f0ba68fe6e870f315d0601b596f889b89680
Author: Richard Biener <rguenther@suse.de>
Date:   Thu Jul 28 10:07:32 2022 +0200

    middle-end/106457 - improve array_at_struct_end_p for array objects

    Array references to array objects are never at struct end.

            PR middle-end/106457
            * tree.cc (array_at_struct_end_p): Handle array objects
            specially.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
  2022-07-28  8:07 ` [Bug tree-optimization/106457] " rguenth at gcc dot gnu.org
  2022-07-28 12:35 ` cvs-commit at gcc dot gnu.org
@ 2022-07-28 12:36 ` rguenth at gcc dot gnu.org
  2022-08-01 21:11 ` qinzhao at gcc dot gnu.org
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-07-28 12:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Should be fixed.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2022-07-28 12:36 ` rguenth at gcc dot gnu.org
@ 2022-08-01 21:11 ` qinzhao at gcc dot gnu.org
  2022-08-01 21:13 ` qinzhao at gcc dot gnu.org
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-01 21:11 UTC (permalink / raw)
  To: gcc-bugs

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

qinzhao at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|FIXED                       |---
             Status|RESOLVED                    |REOPENED

--- Comment #4 from qinzhao at gcc dot gnu.org ---
(In reply to Richard Biener from comment #3)
> Should be fixed.

Just checked this in gdb, still not fixed.

Breakpoint 1, array_at_struct_end_p (ref=0xfffff57a2bc0) at
../../latest_gcc/gcc/tree.cc:12690
12690     if (TREE_CODE (ref) == ARRAY_REF
(gdb) call debug_tree(ref)
 <array_ref 0xfffff57a2bc0
    type <array_type 0xfffff59f7818
        type <integer_type 0xfffff57f05e8 int sizes-gimplified public type_6 SI
            size <integer_cst 0xfffff56c1248 constant 32>
            unit-size <integer_cst 0xfffff56c1260 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set 1 canonical-type
0xfffff57f05e8 precision:32 min <integer_cst 0xfffff56c1200 -2147483648> max
<integer_cst 0xfffff56c1218 2147483647>
            pointer_to_this <pointer_type 0xfffff57f1a40>>
        sizes-gimplified type_6 BLK
        size <var_decl 0xfffff5771200 D.4037 type <integer_type 0xfffff57f00a8
bitsizetype>
            used unsigned ignored TI t.C:8:7
            size <integer_cst 0xfffff56c1050 constant 128>
            unit-size <integer_cst 0xfffff56c1068 constant 16>
            align:128 warn_if_not_align:0 context <function_decl 0xfffff5a84c00
foo>>
        unit-size <var_decl 0xfffff5771290 D.4038 type <integer_type
0xfffff57f0000 sizetype>
            used unsigned ignored DI t.C:8:7
            size <integer_cst 0xfffff56c1008 constant 64>
            unit-size <integer_cst 0xfffff56c1020 constant 8>
            align:64 warn_if_not_align:0 context <function_decl 0xfffff5a84c00
foo>>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality
        domain <integer_type 0xfffff59f7620 type <integer_type 0xfffff57f0000
sizetype>
            sizes-gimplified type_6 DI size <integer_cst 0xfffff56c1008 64>
unit-size <integer_cst 0xfffff56c1020 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality precision:64 min <integer_cst 0xfffff56c1038 0> max
<var_decl 0xfffff5771170 D.4036>>>

    arg:0 <mem_ref 0xfffff5a7ccb0
        type <array_type 0xfffff59f7b60 type <array_type 0xfffff59f7818>
            sizes-gimplified type_6 BLK size <var_decl 0xfffff5771440 D.4041>
unit-size <var_decl 0xfffff57714d0 D.4042>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality domain <integer_type 0xfffff59f7a10>
            pointer_to_this <pointer_type 0xfffff59f7c08>>
        nothrow
        arg:0 <addr_expr 0xfffff5a23980 type <pointer_type 0xfffff59f8d18>
            arg:0 <var_decl 0xfffff5771a70 e.4>>
        arg:1 <integer_cst 0xfffff56c7878 constant 0>
        t.C:9:9 start: t.C:9:3 finish: t.C:9:9>
    arg:1 <integer_cst 0xfffff56c1398 type <integer_type 0xfffff57f05e8 int>
constant 0>
    arg:3 <integer_cst 0xfffff56c1110 type <integer_type 0xfffff57f0000
sizetype> constant 1>
    t.C:9:6 start: t.C:9:3 finish: t.C:9:6>
(gdb) break 12782
Breakpoint 2 at 0x1d519d8: file ../../latest_gcc/gcc/tree.cc, line 12782.
(gdb) c
Continuing.

Breakpoint 2, array_at_struct_end_p (ref=0xfffff5771a70) at
../../latest_gcc/gcc/tree.cc:12782
12782         if (DECL_P (ref_to_array))
(gdb) call debug_tree(ref)
 <var_decl 0xfffff5771a70 e.4
    type <array_type 0xfffff59f80a0
        type <integer_type 0xfffff59f7f50 public unsigned QI
            size <integer_cst 0xfffff56c10f8 constant 8>
            unit-size <integer_cst 0xfffff56c1110 constant 1>
            align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff59f7f50 precision:8 min <integer_cst 0xfffff56c78c0 0> max <integer_cst
0xfffff56c56b8 255>>
        SI
        size <integer_cst 0xfffff56c1248 constant 32>
        unit-size <integer_cst 0xfffff56c1260 constant 4>
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff59f80a0
        domain <integer_type 0xfffff59f7ff8 type <integer_type 0xfffff57f0000
sizetype>
            DI
            size <integer_cst 0xfffff56c1008 constant 64>
            unit-size <integer_cst 0xfffff56c1020 constant 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff59f7ff8 precision:64 min <integer_cst 0xfffff56c1038 0> max <integer_cst
0xfffff56c78f0 3>>
        pointer_to_this <pointer_type 0xfffff59f8d18>>
    addressable used ignored SI t.C:8:7 size <integer_cst 0xfffff56c1248 32>
unit-size <integer_cst 0xfffff56c1260 4>
    align:32 warn_if_not_align:0 context <function_decl 0xfffff5a84c00 foo>>
(gdb) call debug_tree(ref_to_array)
 <mem_ref 0xfffff5a7ccb0
    type <array_type 0xfffff59f7b60
        type <array_type 0xfffff59f7818 type <integer_type 0xfffff57f05e8 int>
            sizes-gimplified type_6 BLK size <var_decl 0xfffff5771200 D.4037>
unit-size <var_decl 0xfffff5771290 D.4038>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality domain <integer_type 0xfffff59f7620>>
        sizes-gimplified type_6 BLK
        size <var_decl 0xfffff5771440 D.4041 type <integer_type 0xfffff57f00a8
bitsizetype>
            used unsigned ignored TI t.C:8:7
            size <integer_cst 0xfffff56c1050 constant 128>
            unit-size <integer_cst 0xfffff56c1068 constant 16>
            align:128 warn_if_not_align:0 context <function_decl 0xfffff5a84c00
foo>>
        unit-size <var_decl 0xfffff57714d0 D.4042 type <integer_type
0xfffff57f0000 sizetype>
            used unsigned ignored DI t.C:8:7
            size <integer_cst 0xfffff56c1008 constant 64>
            unit-size <integer_cst 0xfffff56c1020 constant 8>
            align:64 warn_if_not_align:0 context <function_decl 0xfffff5a84c00
foo>>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 structural-equality
        domain <integer_type 0xfffff59f7a10 type <integer_type 0xfffff57f0000
sizetype>
            sizes-gimplified type_6 DI size <integer_cst 0xfffff56c1008 64>
unit-size <integer_cst 0xfffff56c1020 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1
structural-equality precision:64 min <integer_cst 0xfffff56c1038 0> max
<var_decl 0xfffff57713b0 D.4040>>
        pointer_to_this <pointer_type 0xfffff59f7c08>>
    nothrow
    arg:0 <addr_expr 0xfffff5a23980
        type <pointer_type 0xfffff59f8d18 type <array_type 0xfffff59f80a0>
            unsigned DI size <integer_cst 0xfffff56c1008 64> unit-size
<integer_cst 0xfffff56c1020 8>
            align:64 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff59f8d18>

        arg:0 <var_decl 0xfffff5771a70 e.4 type <array_type 0xfffff59f80a0>
            addressable used ignored SI t.C:8:7
            size <integer_cst 0xfffff56c1248 constant 32>
            unit-size <integer_cst 0xfffff56c1260 constant 4>
            align:32 warn_if_not_align:0 context <function_decl 0xfffff5a84c00
foo>>>
    arg:1 <integer_cst 0xfffff56c7878 type <pointer_type 0xfffff59f7c08>
constant 0>
    t.C:9:9 start: t.C:9:3 finish: t.C:9:9>
(gdb) n
12787         poly_int64 offset;
(gdb) n
12788         if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
(gdb) n
12790             || TREE_CODE (TYPE_MIN_VALUE (TYPE_DOMAIN (atype))) !=
INTEGER_CST)
(gdb) n
12788         if (TREE_CODE (TYPE_SIZE_UNIT (TREE_TYPE (atype))) != INTEGER_CST
(gdb) n
12791           return true;
(gdb) n

So, it still return TRUE for this array access.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2022-08-01 21:11 ` qinzhao at gcc dot gnu.org
@ 2022-08-01 21:13 ` qinzhao at gcc dot gnu.org
  2022-08-04 17:59 ` qinzhao at gcc dot gnu.org
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-01 21:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from qinzhao at gcc dot gnu.org ---
I am wondering whether the following:

12781       /* If the object itself is the array it is not at struct end.  */
12782       if (DECL_P (ref_to_array))
12783         return false;

should be:

12781       /* If the object itself is the array it is not at struct end.  */
12782       if (DECL_P (ref))
12783         return false;

??

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2022-08-01 21:13 ` qinzhao at gcc dot gnu.org
@ 2022-08-04 17:59 ` qinzhao at gcc dot gnu.org
  2022-08-08 15:13 ` qinzhao at gcc dot gnu.org
                   ` (2 subsequent siblings)
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-04 17:59 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from qinzhao at gcc dot gnu.org ---
the following patch fixed the issue:

[opc@qinzhao-aarch64-ol8 gcc]$ git diff tree.cc
diff --git a/gcc/tree.cc b/gcc/tree.cc
index fed1434d141d..d04ac121765a 100644
--- a/gcc/tree.cc
+++ b/gcc/tree.cc
@@ -12779,7 +12779,7 @@ array_at_struct_end_p (tree ref)
       && TREE_CODE (DECL_SIZE_UNIT (ref)) == INTEGER_CST)
     {
       /* If the object itself is the array it is not at struct end.  */
-      if (DECL_P (ref_to_array))
+      if (TREE_CODE (TREE_TYPE (ref)) == ARRAY_TYPE)
        return false;

       /* Check whether the array domain covers all of the available

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2022-08-04 17:59 ` qinzhao at gcc dot gnu.org
@ 2022-08-08 15:13 ` qinzhao at gcc dot gnu.org
  2022-08-09 14:11 ` qinzhao at gcc dot gnu.org
  2022-08-09 14:16 ` qinzhao at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-08 15:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from qinzhao at gcc dot gnu.org ---
another testing case failed with the current "array_at_struct_end_p":
gcc/testsuite/gcc.target/aarch64/vadd_reduc-2.c
  1 /* { dg-do compile } */
  2 /* { dg-additional-options "-O3 -std=c99" } */
  3 /* { dg-final { check-function-bodies "**" "" "" } } */
  4 
  5 #include <stdint.h>
  6 
  7 #pragma GCC target "+nosve"
  8 
  9 /*
 10 **test:
 11 **      ...
 12 **      addv    s0, v0.4s
 13 **      fmov    w0, s0
 14 **      and     w1, w0, 65535
 15 **      add     w0, w1, w0, lsr 16
 16 **      lsr     w0, w0, 1
 17 **      ret
 18 */
 19 int test (uint8_t *p, uint32_t t[1][1], int n) {
 20 
 21   int sum = 0;
 22   uint32_t a0;
 23   for (int i = 0; i < 4; i++, p++)
 24     t[i][0] = p[0];
 25 
 26   for (int i = 0; i < 4; i++) {
 27     {
 28       int t0 = t[0][i] + t[0][i];
 29       a0 = t0;
 30     };
 31     sum += a0;
 32   }
 33   return (((uint16_t)sum) + ((uint32_t)sum >> 16)) >> 1;
 34 }

in the above, at line 24, the array_ref t[i][0] was identified as "true" by the
current array_at_struct_end_p:
Breakpoint 1, array_at_struct_end_p (ref=0xfffff57a2990) at
../../latest_gcc/gcc/tree.cc:12690
12690     if (TREE_CODE (ref) == ARRAY_REF
(gdb) call debug_tree(ref)
 <array_ref 0xfffff57a2990
    type <integer_type 0xfffff599e310 uint32_t sizes-gimplified public unsigned
SI
        size <integer_cst 0xfffff56c1050 constant 32>
        unit-size <integer_cst 0xfffff56c1068 constant 4>
        align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff57d0690 precision:32 min <integer_cst 0xfffff56c1080 0> max <integer_cst
0xfffff56c1038 4294967295> context <translation_unit_decl 0xfffff5a00ca8 t.c>>

    arg:0 <mem_ref 0xfffff59f8390
        type <array_type 0xfffff5a70dc8 type <integer_type 0xfffff599e310
uint32_t>
            SI size <integer_cst 0xfffff56c1050 32> unit-size <integer_cst
0xfffff56c1068 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff5a70e70 domain <integer_type 0xfffff5a70d20>
            pointer_to_this <pointer_type 0xfffff5a71110>>

        arg:0 <ssa_name 0xfffff5761908 type <pointer_type 0xfffff5a71110>
            visited
            def_stmt _4 = t_27(D) + _3;
            version:4
            ptr-info 0xfffff56c84c0>
        arg:1 <integer_cst 0xfffff56c8328 constant 0>
        t.c:24:6 start: t.c:24:5 finish: t.c:24:8>
    arg:1 <integer_cst 0xfffff56c11a0 type <integer_type 0xfffff57d05e8 int>
constant 0>
    t.c:24:9 start: t.c:24:5 finish: t.c:24:11>
...(gdb) n
12774     if (ref
(gdb) n
12806     return true;
(gdb) 

Looks like that the current array_at_struct_end_p cannot handle multi-dimension
array reference correctly.

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-08-08 15:13 ` qinzhao at gcc dot gnu.org
@ 2022-08-09 14:11 ` qinzhao at gcc dot gnu.org
  2022-08-09 14:16 ` qinzhao at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-09 14:11 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from qinzhao at gcc dot gnu.org ---
another testing case failed with the current array_at_struct_end_p is:
gcc/testsuite/gcc.dg/torture/pr50067-1.c:
  1 /* { dg-do run } */
  2 
  3 /* Make sure data-dependence analysis does not compute a bogus
  4    distance vector for the different sized accesses.  */
  5 
  6 extern int memcmp(const void *, const void *, __SIZE_TYPE__);
  7 extern void abort (void);
  8 short a[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21    , 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
  9 short b[32] = { 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, };
 10 int main()
 11 {
 12 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 13   int i;
 14   if (sizeof (short) == 2)
 15     {
 16       for (i = 0; i < 32; ++i)
 17         (*((unsigned short(*)[32])&a[0]))[i] =
(*((char(*)[32])&a[0]))[i+8];
 18       if (memcmp (&a, &b, sizeof (a)) != 0)
 19         abort ();
 20     }
 21 #endif
 22   return 0;
 23 }

In the above, the array ref at line 17: (*((char(*)[32])&a[0]))[i+8] was
identified as TRUE by the current array_at_struct_end_p:
12690     if (TREE_CODE (ref) == ARRAY_REF
(gdb) call debug_tree(ref)
 <array_ref 0xfffff57a2b50
    type <integer_type 0xfffff57d03f0 char public unsigned QI
        size <integer_cst 0xfffff56c0f00 constant 8>
        unit-size <integer_cst 0xfffff56c0f18 constant 1>
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff57d03f0 precision:8 min <integer_cst 0xfffff56c0f60 0> max <integer_cst
0xfffff56c0f48 255>
        pointer_to_this <pointer_type 0xfffff57d40f8>>

    arg:0 <mem_ref 0xfffff59fe3d0
        type <array_type 0xfffff5994d70 type <integer_type 0xfffff57d03f0 char>
            BLK
            size <integer_cst 0xfffff56c1170 constant 256>
            unit-size <integer_cst 0xfffff56c1260 constant 32>
            align:8 warn_if_not_align:0 symtab:0 alias-set 0 canonical-type
0xfffff5994d70 domain <integer_type 0xfffff5994b78>
            pointer_to_this <pointer_type 0xfffff5994e18>>

        arg:0 <addr_expr 0xfffff56dbbe0 type <pointer_type 0xfffff5994ec0>
            constant arg:0 <var_decl 0xfffff5770ea0 a>>
        arg:1 <integer_cst 0xfffff56c7c08 constant 0>
       
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:42
start:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:41
finish:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:63>
    arg:1 <ssa_name 0xfffff57612d8
        type <integer_type 0xfffff57d05e8 int sizes-gimplified public SI
            size <integer_cst 0xfffff56c1050 constant 32>
            unit-size <integer_cst 0xfffff56c1068 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff57d05e8 precision:32 min <integer_cst 0xfffff56c1008 -2147483648> max
<integer_cst 0xfffff56c1020 2147483647>
            pointer_to_this <pointer_type 0xfffff57d1a40>>
        visited
        def_stmt _1 = i_13 + 8;
        version:1
        ptr-info 0xfffff59fee20>
   
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:64
start:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:41
finish:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-1.c:17:68>
....(gdb) n
12801           return true;
(gdb)

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

* [Bug tree-optimization/106457] array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure
  2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-08-09 14:11 ` qinzhao at gcc dot gnu.org
@ 2022-08-09 14:16 ` qinzhao at gcc dot gnu.org
  8 siblings, 0 replies; 10+ messages in thread
From: qinzhao at gcc dot gnu.org @ 2022-08-09 14:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from qinzhao at gcc dot gnu.org ---
one more testing case failed with the current array_at_struct_end_p
is:gcc/testsuite/gcc.dg/torture/pr50067-2.c:
  1 /* { dg-do run } */
  2 
  3 /* Make sure data-dependence analysis does not compute a bogus
  4   distance vector for the different sized accesses.  */
  5 
  6 extern int memcmp(const void *, const void *, __SIZE_TYPE__);
  7 extern void abort (void);
  8 short a[32] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16,
17, 18, 19, 20, 21    , 22, 23, 24, 25, 26, 27, 28, 29, 30, 31 };
  9 short b[32] = { 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, };
 10 int main()
 11 {
 12 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
 13   int i;
 14   if (sizeof (short) == 2)
 15     {
 16       for (i = 0; i < 32; ++i)
 17         {
 18           a[i] = (*((char(*)[32])&a[0]))[i+8];
 19         }
 20       if (memcmp (&a, &b, sizeof (a)) != 0)
 21         abort ();
 22     }
 23 #endif
 24   return 0;
 25 }

In the above, at line 18: (*((char(*)[32])&a[0]))[i+8] was identified as TRUE:
Breakpoint 1, array_at_struct_end_p (ref=0xfffff57a2b18) at
../../latest_gcc/gcc/tree.cc:12690
12690     if (TREE_CODE (ref) == ARRAY_REF
(gdb) call debug_tree(ref)
 <array_ref 0xfffff57a2b18
    type <integer_type 0xfffff57d03f0 char public unsigned QI
        size <integer_cst 0xfffff56c0f00 constant 8>
        unit-size <integer_cst 0xfffff56c0f18 constant 1>
        align:8 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff57d03f0 precision:8 min <integer_cst 0xfffff56c0f60 0> max <integer_cst
0xfffff56c0f48 255>
        pointer_to_this <pointer_type 0xfffff57d40f8>>

    arg:0 <mem_ref 0xfffff59fe3d0
        type <array_type 0xfffff59950b8 type <integer_type 0xfffff57d03f0 char>
            BLK
            size <integer_cst 0xfffff56c1170 constant 256>
            unit-size <integer_cst 0xfffff56c1260 constant 32>
            align:8 warn_if_not_align:0 symtab:0 alias-set 0 canonical-type
0xfffff59950b8 domain <integer_type 0xfffff5994b78>
            pointer_to_this <pointer_type 0xfffff5995160>>

        arg:0 <addr_expr 0xfffff56dbb80 type <pointer_type 0xfffff5995208>
            constant arg:0 <var_decl 0xfffff5770ea0 a>>
        arg:1 <integer_cst 0xfffff56c7c20 constant 0>
       
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:12
start:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:11
finish:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:33>
    arg:1 <ssa_name 0xfffff5761320
        type <integer_type 0xfffff57d05e8 int sizes-gimplified public SI
            size <integer_cst 0xfffff56c1050 constant 32>
            unit-size <integer_cst 0xfffff56c1068 constant 4>
            align:32 warn_if_not_align:0 symtab:0 alias-set -1 canonical-type
0xfffff57d05e8 precision:32 min <integer_cst 0xfffff56c1008 -2147483648> max
<integer_cst 0xfffff56c1020 2147483647>
            pointer_to_this <pointer_type 0xfffff57d1a40>>
        visited
        def_stmt _1 = i_5 + 8;
        version:1>
   
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:34
start:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:11
finish:
/home/opc/Work/GCC/latest_gcc/gcc/testsuite/gcc.dg/torture/pr50067-2.c:18:38>
...
(gdb) n
12801           return true;

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

end of thread, other threads:[~2022-08-09 14:16 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-27 18:43 [Bug tree-optimization/106457] New: array_at_struct_end_p returns TRUE for a two-dimension array which is not inside any structure qinzhao at gcc dot gnu.org
2022-07-28  8:07 ` [Bug tree-optimization/106457] " rguenth at gcc dot gnu.org
2022-07-28 12:35 ` cvs-commit at gcc dot gnu.org
2022-07-28 12:36 ` rguenth at gcc dot gnu.org
2022-08-01 21:11 ` qinzhao at gcc dot gnu.org
2022-08-01 21:13 ` qinzhao at gcc dot gnu.org
2022-08-04 17:59 ` qinzhao at gcc dot gnu.org
2022-08-08 15:13 ` qinzhao at gcc dot gnu.org
2022-08-09 14:11 ` qinzhao at gcc dot gnu.org
2022-08-09 14:16 ` qinzhao 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).