https://gcc.gnu.org/bugzilla/show_bug.cgi?id=129145
Bug ID: 129145
Summary: [17 Regression] LTO ICE in IPA inline
Product: gcc
Version: 17.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: lto
Assignee: unassigned at gcc dot gnu.org
Reporter: dragon-archer at outlook dot com
Target Milestone: ---
`lto1` segfaults in the IPA inline pass when an LTO link inlines an
IPA-CP `constprop` clone of a member function that calls a base-class member
function pointer. The crash happens right after
`ipa_merge_fn_summary_after_inlining` has printed the updated mod-ref summary
of the caller.
Environment: GCC 17.0.0 20261122 (snapshot) for x86_64-w64-mingw32.
Can't reproduce with GCC 16.2.0. Haven't tried with GCC 17 on other platforms
Reproduction:
```
$ g++ -O2 -flto rml.cpp main.cpp -o z.exe
during IPA pass: inline
lto1.exe: internal compiler error: Segmentation fault
D:/msys64/ucrt64/lib/gcc/x86_64-w64-mingw32/17.0.0/lto1.exe -quiet -dumpbase
./z.wpa -mtune=generic -march=nocona -O2 -O2 -fno-openmp -fno-openacc -fpic
-fcf-protection=none -fltrans-output-list=... -fwpa -fresolution=...
-flinker-output=exec @...
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
```
`rml.cpp`:
```cpp
struct factory {
protected:
int (*wait_to_close)( factory& );
};
struct tbb_factory: factory {
void close();
};
void tbb_factory::close() {
(*wait_to_close)(*this);
}
```
`main.cpp`:
```cpp
struct factory {
protected:
int (*wait_to_close)( factory& );
};
struct tbb_factory: factory {
void close();
};
tbb_factory theFactory;
int main() { theFactory.close(); }
```
Some analysis with help of LLM (DeepSeek V4.1 Flash):
## Crash location
`-fdump-ipa-inline` ends with:
```
Considering close.constprop/5 with 8 size
to be inlined into main/1 in unknown:-1
Estimated badness is -1.166667, frequency 1.00.
Parm map: -1
Updated mod-ref summary for main/1
loads:
Base 0:struct tbb_factory (alias set 2)
Ref 0:int (*<T788>) (struct factory &) (alias set 1)
Every access
stores:
Nondeterministic
```
The crash follows the summary update, i.e. while the inliner continues to
process the call graph after `close.constprop` has been inlined into `main`.
## Trigger conditions
| variation | result |
| --- | --- |
| `-O2 -flto` (baseline) | ICE |
| `-O3 -flto` | ICE |
| `-Os -flto` | ICE |
| `-O1 -flto`, `-O0 -flto` | no ICE |
| `-O2` without `-flto` | no ICE |
| single translation unit | no ICE |
| `-flto-partition=one`, `-flto-partition=none` | ICE |
| `-fno-ipa-cp` | no ICE |
| `-fno-inline` | no ICE |
| `-fno-ipa-cp-clone` | ICE |
| `-fno-ipa-sra`, `-fno-ipa-icf`, `-fno-ipa-modref` | ICE |
Additional properties required for the crash, each verified by removing it
from the reproducer:
* the object must be a namespace-scope object (`theFactory`), so that its
address is an IPA-CP compile-time invariant; a local object does not
reproduce;
* the member function pointer must be declared in a base class and invoked
through `*this`, so that IPA-CP creates the `constprop` clone
(`close.constprop`) that is later inlined into `main`;
* the call must go through the function pointer, i.e.
`(*wait_to_close)(*this)`;
removing the indirect call removes the crash.
## Origin
Reduced from a oneTBB 2023.2.0 build, where `governor::release_resources()`
calls `rml::tbb_factory::close()`, which invokes the
`my_wait_to_close_routine` member function pointer declared in
`rml::factory`. The full object set of the library triggers the same crash;
the two-file reproducer above is the result of delta debugging the object
set followed by manual minimization.