Fix four clang 22 regen regressions (size_t constant macros, __unaligned leak, namespace remap, NativeTypeName namespace)#826
Merged
tannergooding merged 3 commits intoJul 18, 2026
Conversation
…mport as constants clang 22 models size_t as a PredefinedSugarType with no wrapper in ClangSharp's Type hierarchy, so an unsigned/size_t-typed constant expression macro degraded to the base Type and emitted a malformed ref readonly getter instead of a constant. Fall back to the desugared type in IsType and GetTypeName so these import as plain constants again. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ace-qualified remaps apply clang 22 folds local qualifiers (const, volatile, __unaligned) into a tag type's spelling and no longer emits an ElaboratedType, so the old string-based leaf handling leaked __unaligned struct tagFoo* into C# and applied a --remap keyed by a namespace-qualified name (e.g. Gdiplus.PointF) to the declaration but not its use-sites. Resolve the name through the decl instead so references match their declaration exactly and qualifier keywords no longer leak. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…ype printer clang 22 omits the enclosing namespace from a reference spelled while that namespace is in scope (a `using namespace` or a reference from within the namespace), where-as older releases always spelled it. A `NativeTypeName` such as `Gdiplus::Status` then degraded to `Status`, and a remap that renamed the managed side surfaced the stripped spelling instead of suppressing it. Rebuild the dropped `Namespace::` prefix from the referenced decl so the attribute keeps the fully qualified, version-stable spelling for typedef, record (including by-pointer), and enum references. 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.
Regenerating terrafx.interop.windows against ClangSharp v22.1.8 (clang 22.1.8) surfaced four issues, all rooted in clang 22's changed type representation (it folds qualifiers into a type's spelling, desugars fewer sugar types on its own, and drops the enclosing namespace from an in-scope reference). Each fix is a focused commit with a golden-file regression test.
Bug 1 --
size_tconstant-expression macros emit an uncompilableref readonlygetter (blocking)An unsigned/
size_t-typed constant expression macro (e.g.ARRAYSIZE(x) - 1,sizeof(...)) took the experimentalref readonlypath and emitted a property body that was just the folded expression -- noreturn, no;-- so it failed withCS1002(and leaked the internal__size_ttype name). This was the dominant break in the regen (~152CS1002across 26 files). Root cause: clang 22 hands back a sugar typeIsType<T>no longer recognized, so the macro fell off the constant path. Desugar the unrecognized sugar as a fallback so these import as plain constants again, matching v21.Bug 2 --
__unaligned+ elaboratedstructspecifier leaks into C# (blocking)clang 22 folds local qualifiers into a tag type's spelling and no longer emits an
ElaboratedType, so aUNALIGNED FARpointer typedef leaked__unaligned struct tagFoo*-- not valid C#. Resolve the tag name through its decl so the qualifier keywords drop and the elaboratedstructspecifier resolves to the record type.Bug 3 -- namespace-qualified (dotted) remap keys stopped applying at use-sites
A
--remapkeyed by a namespace-qualified name (e.g.Gdiplus.PointF=@GpPointF) applied to the type declaration but not to references, silently renamingGp*back to the unprefixed names theGpprefix existed to avoid. Same root cause as Bug 2 -- the reference was matched by printed string rather than by decl. Resolving through the decl makes the remap apply consistently at declaration and use-site.Symptom C --
NativeTypeNameloses the C++ namespaceclang 22 omits the enclosing namespace from a reference spelled while that namespace is in scope (a
using namespaceor a reference from within the namespace), where-as older releases always spelled it, soGdiplus::Statusdegraded toStatus(~1332 lines in the regen, and it interacts with the Bug 3 remap). Rebuild the droppedNamespace::prefix from the referenced decl for typedef, record (including by-pointer), and enum references. The prepend is a no-op when there's no namespace ancestor, the printed name already carries the scope, or the decl is anonymous, so no existing (C-only self-host) baselines change.Each fix adds a golden-file regression test (
SizeTMacroBinding,UnalignedTypeBinding,NamespaceRemap,NamespaceNativeTypeName). Full generator suite: 4116 passed / 0 failed, 0 warnings.Note
This description was drafted by Copilot.