so duplicating an inline for example in the case we split a function
and then
inline both parts or in the case we inline a IPA-CP forwarder and the
specific
clone. It's not obvious what we should do here since of course for a
recursive
function we can have a function inlined two times in a row.
I think this is already happening. I'm not regressing anything.
The testcase only triggers the first case, right?
In v4 I have changed part of the testcase so, I think does exercise this
now:
https://gcc.godbolt.org/z/KdYPh39js
The testcase however does include infinite recursion. But it may still
be relevant to real-world code.
static int bar(char* p) {
__builtin_strncpy(p, p, 1);
bar(p);
return 0;
}
void baz() {
char c[0];
bar(c);
}
Outputs:
<source>: In function 'bar':
<source>:4:12: warning: infinite recursion detected
[-Winfinite-recursion]
4 | static int bar(char* p) {
| ^~~
<source>:6:5: note: recursive call
6 | bar(p);
| ^~~~~~
<source>: In function 'bar.isra':
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar' at <source>:6:5,
inlined from 'bar.isra' at <source>:6:5:
<source>:5:5: warning: '__builtin_strncpy' source argument is the same
as destination [-Wrestrict]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
In function 'bar',
inlined from 'baz' at <source>:12:5:
<source>:5:5: warning: '__builtin_strncpy' offset 0 is out of the bounds
[0, 0] of object 'c' with type 'char[0]' [-Warray-bounds=]
5 | __builtin_strncpy(p, p, 1);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In function 'baz':
<source>:11:10: note: 'c' declared here
11 | char c[0];
| ^