[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-09-03 Thread mwd at md5i dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

--- Comment #8 from Michael Duggan  ---
Created attachment 53533
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53533&action=edit
Reduced bug exemplar

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-09-03 Thread mwd at md5i dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Michael Duggan  changed:

   What|Removed |Added

 CC||mwd at md5i dot com

--- Comment #7 from Michael Duggan  ---
I am working with some code that exhibits a similar problem.  I've run creduce
on the preprocessed code to create an exemplar, which I have attached as
bug-mwd.cpp.  Here's the relevant warnings from g++ 12.2.0 using '-std=c++14
-Wall -O2':

In member function ‘void i<  >::m(k*) [with ab = s]’,
inlined from ‘void i<  >::m(k*) [with ab = I]’ at
bug.cpp:25:26,
inlined from ‘i<  >::i(n) [with n = I*; ab = I]’ at
bug.cpp:23:39,
inlined from ‘am I::u()’ at bug.cpp:48:3:
bug.cpp:27:5: warning: array subscript ‘i::k {aka s}[0]’ is partly outside
array bounds of ‘unsigned char [40]’ [-Warray-bounds]
   27 | e(p->aa);
  | ^~~~
bug.cpp: In member function ‘am I::u()’:
bug.cpp:48:9: note: object of size 40 allocated by ‘operator new’
   48 |   o(new I);
  | ^

The example is convoluted, I am afraid.  One very strange bit is that if I
change the 'o's in 'class I' to, say, 'p', I get a completely different error.

If you think this is unrelated, let me know, and I will submit a new bug
report.

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-08-19 Thread glisse at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Marc Glisse  changed:

   What|Removed |Added

 Status|WAITING |NEW

--- Comment #6 from Marc Glisse  ---
(In reply to Andrew Pinski from comment #2)
> the warning is correct in the sense the load is there in IR, though it looks
> like it is dead (but only because b and a are unused):

#include 
Eigen::Array a;
Eigen::Array b;
void f(){
b.col(0).tail(2) = a.col(1);
}

still warns about some 256 bit code which is still very dead (we later optimize
the whole function to just
  _64 = MEM  [(char * {ref-all})&a + 16B];
  MEM  [(char * {ref-all})&b + 8B] = _64;
)
so the fact that a and b are unused in the original testcase is not important.

I assume there were good reasons to put the warning this early (VRP1), but it
means that some dead code that will be removed later is still around.

(@Daniel: it can be easier to track things with separate issues, if you have a
different testcase to provide)

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-08-19 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed|2022-07-10 00:00:00 |2022-08-19
 Ever confirmed|0   |1
 CC||msebor at gcc dot gnu.org

--- Comment #5 from Martin Sebor  ---
This instance of -Warray-bounds (with the text "partly outside the bounds") is
often issued for aliasing violations where an object of one type is being
access by an lvalue of a larger struct.  The ultimate access may be to a member
of the larger struct whose offset is within the bounds of the smaller object,
but the access is (or could be) wrong nonetheless (due to the aliasing rules)
and hence the warning.

Here's an example:

$ cat a.c && gcc -O2 -S -Wall a.c
struct A { int i; };
struct B { struct A a; int j; };

void* f (void)
{
  struct A *p = __builtin_malloc (sizeof *p);
  ((struct B*)p)->a.i = 0;
  return p;
}
a.c: In function ‘f’:
a.c:7:17: warning: array subscript ‘struct B[0]’ is partly outside array bounds
of ‘unsigned char[4]’ [-Warray-bounds]
7 |   ((struct B*)p)->a.i = 0;
  | ^~
a.c:6:17: note: object of size 4 allocated by ‘__builtin_malloc’
6 |   struct A *p = __builtin_malloc (sizeof *p);
  | ^~~~

If your case is comparable this should be resolved as invalid; otherwise, if
it's substantially different please post a reproducible test case.

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-08-01 Thread skunk at iskunk dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Daniel Richard G.  changed:

   What|Removed |Added

 CC||skunk at iskunk dot org

--- Comment #4 from Daniel Richard G.  ---
I am seeing what may be the same issue in a different context.

This is occurring in a proprietary C source codebase newly being compiled with
12.1.0, and unfortunately the problem goes away if I attempt to cut it down to
a minimal test case. Nevertheless, the actual issue is quite simple, and IMO
clear-cut.

(some names edited to protect the guilty)

In file included from /usr/include/string.h:375,
 from foo.c:7:
In function 'function3',
inlined from 'function2' at foo.c:1206:5,
inlined from 'function1' at foo.c:2840:7:
foo.c:415:3: error: array subscript 'union [1]' is partly outside
array bounds of 'unsigned char[5]' [-Werror=array-bounds]
  415 |   memset(constraints,0,sizeof(char)*NB_CONSTRAINTS);
  |   ^~
foo.c: In function 'function1':
foo.c:380:17: note: at offset 4 into object 'constraints' of size 5
  380 |   unsigned char constraints[NB_CONSTRAINTS];
  | ^~~~
cc1: all warnings being treated as errors


Curiously enough, I only see this issue in an i686 build. I don't get it on
x86-64. (Dropping -march=i686 does not help.)

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Andrew Pinski  changed:

   What|Removed |Added

 Ever confirmed|1   |0
 Status|WAITING |UNCONFIRMED

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread fchelnokov at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Fedor Chelnokov  changed:

   What|Removed |Added

 CC||fchelnokov at gmail dot com

--- Comment #3 from Fedor Chelnokov  ---
Created attachment 53284
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=53284&action=edit
Preprocessed source

Preprocessed source is attached.

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

--- Comment #2 from Andrew Pinski  ---
the warning is correct in the sense the load is there in IR, though it looks
like it is dead (but only because b and a are unused):
  array.7_137 = (long unsigned int) &MEM  [(void *)&b + 8B];
  _139 = array.7_137 >> 3;
  _140 = -_139;
  _141 = _140 & 3;
  first_142 = (long int) _141;
  _143 = MIN_EXPR ;
  _145 = 2 - _143;
  alignedEnd_148 = _143;
  goto ; [100.00%]

   [local count: 8655976563]:
  index.12_166 = (long unsigned int) index_165;
  _167 = index.12_166 * 8;
  _168 = &MEM  [(void *)&a + 16B] + _167;
  _171 = &MEM  [(void *)&b + 8B] + _167;
  _172 = *_168;
  MEM[(double &)_171] = _172;
  index_173 = index_165 + 1;

   [local count: 9725816346]:
  # index_165 = PHI <0(2), index_173(3)>
  if (_143 > index_165)
goto ; [89.00%]
  else
goto ; [11.00%]

   [local count: 8655976563]:
  index.10_152 = (long unsigned int) index_151;
  _153 = index.10_152 * 8;
  _154 = &MEM  [(void *)&a + 16B] + _153;
  _155 = MEM[(__m256d_u * {ref-all})_154];
  _158 = &MEM  [(void *)&b + 8B] + _153;
  MEM[(__m256d * {ref-all})_158] = _155;
  index_159 = index_151 + 4;

   [local count: 9725816346]:
  # index_151 = PHI <_143(4), index_159(5)>
  if (alignedEnd_148 > index_151)
goto ; [89.00%]
  else
goto ; [11.00%]

[Bug tree-optimization/106247] GCC12 warning in Eigen: array subscript is partly outside array bounds

2022-07-10 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106247

Andrew Pinski  changed:

   What|Removed |Added

 Target||x86_64-linux-gnu
 Ever confirmed|0   |1
 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2022-07-10
   Keywords||diagnostic
  Component|c++ |tree-optimization

--- Comment #1 from Andrew Pinski  ---
Can you attach the preprocessed source?