Fix crash on out-of-line class-template member definitions and harden getVtblIdx#769
Merged
tannergooding merged 2 commits intoJul 14, 2026
Conversation
An out-of-line definition of a class-template member (e.g.
emplate<class T, class P> C<T, P>::C() {}) is a CXXMethodDecl with a
dependent his type, so its parent record, function type, and vtable
index all resolve to null/invalid. It isn't a TemplateDecl and so slips
past the template exclusion, then crashes the naming machinery with an
ArgumentNullException (and, on older native libs, an AccessViolation via
the vtable index path). Exclude it up front in IsExcludedByName, before
any naming runs.
Repros against the Steamworks SDK headers from dotnet#510.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…g vtable index getMethodVFTableLocation/getMethodVTableIndex assert the decl is present in the vtable layout; with asserts disabled (release libs) a missing entry dereferences an end() iterator and AVs (dotnet#534, dotnet#510). Guard the query behind a computable-vtable check (complete, non-dependent, polymorphic parent) and fall back to the existing -1 sentinel otherwise. This changes native libClangSharp, which requires building LLVM/Clang to compile and verify -- not possible in this session -- so it is committed separately and clearly marked so it can be reviewed and trivially dropped independently of the verified managed dotnet#510 fix. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tannergooding
marked this pull request as ready for review
July 14, 2026 16:21
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.
Addresses two crash/robustness issues: #510 (verified fix) and #534 (native hardening, unverified — see note below).
5cef78c2— Fix crash on out-of-line class-template member definitions (#510)An out-of-line class-template member definition (e.g.
template<class T, class P> CCallResult<T,P>::CCallResult()) is aCXXMethodDeclwhosethistype is dependent, soParent(base.Parent ?? ThisObjectType.AsCXXRecordDecl) isnull— the semantic parent cursor is null andThisObjectTypeis aPointerType, not aCXXRecordDecl. It is not aTemplateDecl, so the!GenerateTemplateBindingsexclusion doesn't catch it, and the naming code assumes a non-null parent behindDebug.Assert(a no-op in Release), so it dereferences null and crashes. Under the Steamworks SDK headers from #510 this surfaces as anArgumentNullExceptionin the naming path.Fix: exclude these decls up front in
IsExcludedByNameon the exactParent is nullsignal, before any naming runs. One guard at the exclusion layer covers every downstream naming site becauseIsExcludedruns first inVisitDecl. AddedCXXMethodDeclarationTest.OutOfLineTemplateConstructorDefinitionTest; the test reproduces the exactArgumentNullExceptionwhen the fix is reverted and passes with it. These decls produce no output today (templates aren't generated by default), so the baselines are empty — the regression value is "doesn't crash". Full suite green.d09fc4f8— HardengetVtblIdxagainst a missing vtable index (#534)Warning
UNVERIFIED — this commit could not be compiled or tested here (it needs an LLVM/Clang build). The predicates are reasonable but not compile-checked; API names should be confirmed against the target Clang version before merging. It is isolated on top of the #510 fix so it can be dropped independently.
#534 is an
AccessViolationExceptioninCursor_getVtblIdx, reached viaCXXMethodDecl.VtblIndexduring ordering inIsExcluded. The native ItaniumgetMethodVTableIndex/ MicrosoftgetMethodVFTableLocationassert the method is present in the vtable map; with asserts disabled in release they dereference anend()iterator → AV. The managedVtblIndexalready guardsIsVirtual; the gap is purely native. It did not reproduce on the current native lib (clang 21.1.8), so this is defensive.This guards both vtable queries behind a computable-vtable check (
RDnon-null, complete definition, non-dependent context, dynamic/polymorphic class) and falls back to the existing-1sentinel instead of dereferencing an invalid iterator.CC. @tannergooding — the native commit needs a real LLVM/Clang build to verify; happy to drop it if you'd rather land only the verified #510 fix.
Note
This PR description was drafted by Copilot.