Model multiple-inheritance vtbl bases as ABI-correct subobjects#750
Merged
tannergooding merged 1 commit intoJul 13, 2026
Merged
Conversation
A struct deriving from two or more polymorphic bases previously flattened every base into a single `lpVtbl`, which emitted duplicate members (a CS0111 compile error) and silently dispatched secondary-base methods through the primary vtable. Only the primary (first) polymorphic base shares the derived type's vtable pointer, so it alone is flattened into `lpVtbl`; every other polymorphic base is emitted as a nested subobject field, preserving its own vtable pointer at the correct offset. A field-bearing polymorphic primary base cannot be flattened and is likewise emitted as a subobject, so the derived type declares no `lpVtbl` of its own. Nested multiple inheritance would require carrying a flattened base's own non-primary polymorphic subobjects onto the derived type, which is not yet modeled; those records fall back to the legacy run-on `lpVtbl` (keeping every inherited method reachable) and are flagged with a warning. Fixes dotnet#592 Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A struct deriving from two or more polymorphic bases previously flattened every base into a single
lpVtbl, which emitted duplicate members (a CS0111 compile error) and silently dispatched secondary-base methods through the primary vtable. This builds on #748 (the interim dedupe) and makes the layout ABI-correct.Only the primary (first) polymorphic base shares the derived type's vtable pointer, so it alone is flattened into
lpVtbl; every other polymorphic base is emitted as a nested subobject field, preserving its own vtable pointer at the correct offset. A field-bearing polymorphic primary base cannot be flattened and is likewise emitted as a subobject, so the derived type declares nolpVtblof its own.Nested multiple inheritance would require carrying a flattened base's own non-primary polymorphic subobjects onto the derived type. Faithfully modeling that needs changes to the generator's naming and base-field/dispatch resolution (both assume every emitted base is a direct base of the record), so it is deferred. Those records fall back to the legacy run-on
lpVtbl-- every inherited method stays reachable so the bindings still compile -- and are flagged with a warning rather than silently mislaid out.Known limitations (deferred, tracked for follow-up):
lpVtbl+ warning.CXXBaseSpecifier.IsVirtual) is not modeled anywhere in the generator (pre-existing, orthogonal).Validation:
Failed: 0), zero golden churn.MultipleBaseVtblSubobjectTest.cs: secondary-base subobject (unifying and non-unifying), explicit-vtbl and marker-interface variants, field-bearing primary, and the nested-MI fallback (asserts the warning).Fixes #592