https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116377
Bug ID: 116377
Summary: Warnings emit repeatedly when inlining occurs
Product: gcc
Version: 15.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: peter0x44 at disroot dot org
Target Milestone: ---
https://gcc.godbolt.org/z/njehnfTdW
The following testcase:
static int foo(char* p) {
__builtin_strncpy(p, p, 1);
foo(p);
return 0;
}
void bar() {
char c[0];
foo(c);
}
Emits this warning spam:
<source>: In function 'foo':
<source>:2:12: warning: infinite recursion detected [-Winfinite-recursion]
2 | static int foo(char* p) {
| ^~~
<source>:4:6: note: recursive call
4 | foo(p);
| ^~~~~~
<source>: In function 'foo.isra':
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo' at <source>:4:6,
inlined from 'foo.isra' at <source>:4:6:
<source>:3:6: warning: '__builtin_strncpy' source argument is the same as
destination [-Wrestrict]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'foo',
inlined from 'bar' at <source>:10:6:
<source>:3:6: warning: '__builtin_strncpy' offset 0 is out of the bounds [0, 0]
of object 'c' with type 'char[0]' [-Warray-bounds=]
3 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In function 'bar':
<source>:9:11: note: 'c' declared here
9 | char c[0];
| ^
Compiler returned: 0
This applies to both C and C++.