Skip to content

Fix four clang 22 regen regressions (size_t constant macros, __unaligned leak, namespace remap, NativeTypeName namespace)#826

Merged
tannergooding merged 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-v22-regen-bugs
Jul 18, 2026
Merged

Fix four clang 22 regen regressions (size_t constant macros, __unaligned leak, namespace remap, NativeTypeName namespace)#826
tannergooding merged 3 commits into
dotnet:mainfrom
tannergooding:tannergooding-fix-v22-regen-bugs

Conversation

@tannergooding

Copy link
Copy Markdown
Member

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_t constant-expression macros emit an uncompilable ref readonly getter (blocking)

An unsigned/size_t-typed constant expression macro (e.g. ARRAYSIZE(x) - 1, sizeof(...)) took the experimental ref readonly path and emitted a property body that was just the folded expression -- no return, no ; -- so it failed with CS1002 (and leaked the internal __size_t type name). This was the dominant break in the regen (~152 CS1002 across 26 files). Root cause: clang 22 hands back a sugar type IsType<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 + elaborated struct specifier leaks into C# (blocking)

clang 22 folds local qualifiers into a tag type's spelling and no longer emits an ElaboratedType, so a UNALIGNED FAR pointer typedef leaked __unaligned struct tagFoo* -- not valid C#. Resolve the tag name through its decl so the qualifier keywords drop and the elaborated struct specifier resolves to the record type.


Bug 3 -- namespace-qualified (dotted) remap keys stopped applying at use-sites

A --remap keyed by a namespace-qualified name (e.g. Gdiplus.PointF=@GpPointF) applied to the type declaration but not to references, silently renaming Gp* back to the unprefixed names the Gp prefix 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 -- NativeTypeName loses the C++ namespace

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, so Gdiplus::Status degraded to Status (~1332 lines in the regen, and it interacts with the Bug 3 remap). Rebuild the dropped Namespace:: 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.

tannergooding and others added 3 commits July 18, 2026 15:38
…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>
@tannergooding
tannergooding merged commit 60fca48 into dotnet:main Jul 18, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-fix-v22-regen-bugs branch July 18, 2026 23:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant