On 10/2/25 10:06 AM, Yangyu Chen wrote:


On 1/10/2025 15:40, Richard Biener wrote:
On Thu, Jul 31, 2025 at 5:47 PM Yangyu Chen <[email protected]> wrote:

When building with LTO, DECL_VINDEX is not always set for virtual
functions, which allows virtual functions to be incorrectly treated as
non-virtual and then being multi-versioned, and causes errors sometimes.

This patch addresses the issue by ensuring that we also check
DECL_VIRTUAL_P in addition to DECL_VINDEX when handling virtual
functions during multiversioning.

I think checking DECL_VINDEX is flawed - it's only relevant for creating
OBJ_TYPE_REFs IIRC.  That is, it's irrelevant to GIMPLE and thus freed
in free-lang-data (which we unfortunately run only with -flto).

So, can you test removing the DECL_VINDEX check and only rely on
DECL_VIRTUAL_P?


It can be hard to check since most real-world source code with optimizations may not use it.

I think we should keep checking these two since DECL_VIRTUAL_P will only be set by the frontend. For some future passes that may clone a member function and insert VINDEX, this behavior can be found during compilation time instead of a runtime crash.

Hmm, I'd expect such a hypothetical pass to also set DECL_VIRTUAL_P.

Jason

Reply via email to