[Bug ipa/105438] [11/12/13/14 Regression] Incorrect array-bounds warning with array size carried over from a previous template instantiation since r11-4987-g602c6cfc79ce4ae6

2023-07-20 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

Bernie Innocenti  changed:

   What|Removed |Added

Version|11.3.0  |13.1.1
   Target Milestone|11.5|13.2

--- Comment #13 from Bernie Innocenti  ---
Still present on g++ 13.1.1

I discovered that -O2 is required to trigger this bug. These compile without
warnings:

 g++ -O1 -Warray-bounds repro.cc
 g++ -O3 -Warray-bounds repro.cc
 g++ -Ofast -Warray-bounds repro.cc

[Bug ipa/105438] [11/12/13 Regression] Incorrect array-bounds warning with array size carried over from a previous template instantiation since r11-4987-g602c6cfc79ce4ae6

2023-01-21 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

--- Comment #10 from Bernie Innocenti  ---
Still present on GCC 12.2.

Could someone look into it please, or point me at the point in ipa-icf.cc where
the array-bounds analysis information should have been updated after merging
the template instantiations?

[Bug c++/105438] Incorrect array-bounds warning with array size carried over from a previous template instantiation

2022-05-02 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

--- Comment #4 from Bernie Innocenti  ---
Furthermore, after the inline pass main() has a reference to the shorter array
with an annotation of int[7], which is clearly wrong:

   [local count: 939524097]:
  _5 = MEM[(const int[7] &)][i_4];
  out[i_4] = _5;
  i_6 = i_4 + 1;

[Bug c++/105438] Incorrect array-bounds warning with array size carried over from a previous template instantiation

2022-05-02 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

--- Comment #3 from Bernie Innocenti  ---
Not sure if this is helpful, but the IPA dump also shows two calls to
configure() with N=7 and none with N=2:

IPA function summary for int main()/3 inlinable
  global time: 26.00
  self size:   9
  global size: 9
  min size:   6
  self stack:  0
  global stack:0
size:0.00, time:0.00
size:3.00, time:2.00,  executed if:(not inlined)
  calls:
void configure(const int (&)[N], int) [with int N = 7]/6 function not
considered for inlining
  freq:1.00 loop depth: 0 size: 3 time: 12 callee size: 5 stack: 0
   op0 is compile time invariant
   op1 is compile time invariant
void configure(const int (&)[N], int) [with int N = 7]/6 function not
considered for inlining
  freq:1.00 loop depth: 0 size: 3 time: 12 callee size: 5 stack: 0
   op0 is compile time invariant
   op1 is compile time invariant

[Bug c++/105438] Incorrect array-bounds warning with array size carried over from a previous template instantiation

2022-05-02 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

--- Comment #2 from Bernie Innocenti  ---
GCC 12.0.1 20220413 (Red Hat 12.0.1-0) gives a more helpful diagnostic with
inlining backtrace:

In function ‘void configure(const int (&)[N], int) [with int N = 7]’,
inlined from ‘void configure(const int (&)[N], int) [with int N = 2]’ at
testcase.cc:8:6,
inlined from ‘int main()’ at gcc-array-bounds-bug-testcase.cc:22:12:
testcase.cc:14:24: warning: array subscript ‘const int [7][0]’ is partly
outside array bounds of ‘int [2]’ [-Warray-bounds]
   14 | out[i] = in[i];
  |  ~~^


Note how configure() was inlined into configure().

[Bug c++/105438] Incorrect array-bounds warning with array size carried over from a previous template instantiation

2022-04-30 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

--- Comment #1 from Bernie Innocenti  ---
Reproducible in Godbolt with any 11.x release as well as trunk:
https://godbolt.org/z/zWb55P8G7

[Bug c++/105438] New: Incorrect array-bounds warning with array size carried over from a previous template instantiation

2022-04-30 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105438

Bug ID: 105438
   Summary: Incorrect array-bounds warning with array size carried
over from a previous template instantiation
   Product: gcc
   Version: 11.3.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c++
  Assignee: unassigned at gcc dot gnu.org
  Reporter: bernie at codewiz dot org
  Target Milestone: ---

Minified testcase (almost every line is necessary to reproduce):

```
/* g++ -Warray-bounds -O2 repro.cc */

int longer[7] = {};
int shorter[2] = {};
int out[10] = {};

template 
void configure(const int()[N], const int nrows = N)
{
if (nrows <= 10)
{
for (int i = 0; i < nrows; i++)
{
out[i] = in[i];
}
}
}

int main()
{
  configure(longer);
  configure(shorter);
}
```

Output:

```
$ g++ -Warray-bounds -O2 repro.cc
repro.cc: In function 'int main()':
repro.cc:13:24: warning: array subscript 'const int [7][0]' is partly outside
array bounds of 'int [2]' [-Warray-bounds]
   13 | out[i] = in[i];
  |  ~~^
repro.cc:3:5: note: while referencing 'shorter'
3 | int shorter[2] = {};
  | ^~~
repro.cc:13:24: warning: array subscript 'const int [7][0]' is partly outside
array bounds of 'int [2]' [-Warray-bounds]
   13 | out[i] = in[i];
  |  ~~^
repro.cc:3:5: note: while referencing 'shorter'
3 | int shorter[2] = {};
  | ^~~
```

Static analysis appears to be using the length of the longer array for the call
using the shorter array.

The warning disappears by:
 * commenting out the first call to configure() suppresses the warning
 * swapping the two calls to configure()
 * commenting out if statement also eliminates the warning
 * making longer and shorter the same size
 * using N as loop counter instead of nrows

[Bug c++/98824] [C++-20] function template non-type-class-arg deduction fails with a reason that looks bogus

2022-01-17 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98824

--- Comment #4 from Bernie Innocenti  ---
Are there any known workarounds?

[Bug c++/98824] [C++-20] function template non-type-class-arg deduction fails with a reason that looks bogus

2022-01-17 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98824

Bernie Innocenti  changed:

   What|Removed |Added

 CC||bernie at codewiz dot org

--- Comment #3 from Bernie Innocenti  ---
Assuming this is the same bug, it's still present in g++ 12 as well as trunk:
https://godbolt.org/z/6r3bc3j15

[Bug c++/79001] spurious "defined but not used" warning with explicit instantiation

2021-11-05 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79001

--- Comment #5 from Bernie Innocenti  ---
clang with -Wunused-function also does not issue a warning for this testcase.

[Bug c++/79001] spurious "defined but not used" warning with explicit instantiation

2021-11-05 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79001

--- Comment #4 from Bernie Innocenti  ---
GCC 5.1 does not issue a warning.

[Bug c++/79001] spurious "defined but not used" warning with explicit instantiation

2021-11-05 Thread bernie at codewiz dot org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=79001

Bernie Innocenti  changed:

   What|Removed |Added

 CC||bernie at codewiz dot org

--- Comment #3 from Bernie Innocenti  ---
Same behavior on GCC 11.2