Skip to content

Onboard ClangSharp to clang 22.1.8#805

Merged
tannergooding merged 17 commits into
dotnet:mainfrom
tannergooding:tannergooding-v22-regen
Jul 16, 2026
Merged

Onboard ClangSharp to clang 22.1.8#805
tannergooding merged 17 commits into
dotnet:mainfrom
tannergooding:tannergooding-v22-regen

Conversation

@tannergooding

Copy link
Copy Markdown
Member

Onboards the managed and generator layers to clang 22.1.8, regenerates the self-hosted interop, and surfaces the reshaped v22 Type API.

clang 22 removed the ElaboratedType and DependentTemplateSpecializationType Type classes. The elaborated-type keyword moved directly onto every TypeWithKeyword-derived type, and the dependent template-specialization case folded into TemplateSpecializationType via a dependent TemplateName. This bumps the managed version and interop headers to 22.1.8, regenerates ClangSharp.Interop against the 22.1.8 native surface, and reconciles the managed AST with the removals.


Managed AST port. Deletes ElaboratedType/DependentTemplateSpecializationType and their Type.Create arms, and reparents TagType, TypedefType, UsingType, UnresolvedUsingType, and TemplateSpecializationType under TypeWithKeyword to match the clang 22 hierarchy (joining the already-parented DependentNameType). The elaboration keyword is now observable on each via TypeWithKeyword.Keyword, and a plain tag/typedef/using type correctly reports CX_ETK_None rather than falling through to Invalid.

Type keyword + dependence surface. Wires the reshaped v22 bridges through all three layers: CXType.Keyword/Dependence/AutoTypeKeyword on the interop extension, and on the managed AST TypeWithKeyword.Keyword, AutoType.Keyword, plus the Type dependence predicates (IsDependentType, IsInstantiationDependentType, IsVariablyModifiedType, ContainsUnexpandedParameterPack, ContainsErrors) over the consolidated Dependence flags -- mirroring the existing Expr/TemplateArgument dependence pattern.

Generator. Removes the dead ElaboratedType handling (the five branches never match under clang 22 since the underlying RecordType/EnumType/TypedefType is hit directly; golden baselines are unchanged, confirming the removal is output-neutral), and normalizes the clang 22 unnamed-tag spelling back to the anonymous form the baselines expect.

Self-hosting. The generator once again reproduces the committed ClangSharp.Interop bindings byte-for-byte (bootstrap), except the two intentionally hand-curated CX_TemplateArgument/CX_TemplateArgumentLoc structs.


Out of scope / follow-up: the 22.1.8 regen brought a large batch of newly-available clangsharp_* bridges into the raw interop that the mid/high layers don't yet expose (LambdaExpr cluster, CXXRecordDecl structural predicates, Expr value/object kind, constexpr family, empty-shell Stmt/Expr classes, FunctionProtoType exception spec). These were previously blocked on a native rebuild and are now unblocked managed-side; they'll land as separate focused PRs.

Verified: dotnet build -c Release 0 warnings; full suite green (4077 generator golden-file + 37 CLI + 75 interop, incl. new TypeTest coverage for the keyword/dependence accessors).

Note

Authored with Copilot.

tannergooding and others added 12 commits July 16, 2026 09:19
Bump VersionPrefix to 22.1.8.0 (resetting the build portion for the new LLVM version), the clang.MajorVersion/MinorVersion resolver constants to 22.1, and the libClang/libClangSharp package pins to 22.1.8/22.1.8.2 to match the native packages. Point the README runtime-package example at 22.1.8.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Refresh the auto-generated clangsharp/*.cs P/Invoke layer against the 22.1.8
libClangSharp surface (CX_* enum reshape and the new bridge entry points), and
add CXCursor_OMPFuseDirective to the clang-c CXCursorKind enum.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Update the attr/stmt/type-class spelling switches and Debug.Assert range markers
for clang 22: drop the removed HLSLSV_*/Replaceable/TriviallyRelocatable and
Elaborated/DependentTemplateSpecialization arms, add the new attr spellings, and
rename the OMP loop-transformation markers to their canonical-loop-nest form.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
clang 22 removes the ElaboratedType and DependentTemplateSpecializationType Type
classes (the keyword moved onto each TypeWithKeyword-derived type, and dependent
template specializations fold into TemplateSpecializationType). Remove the two
managed Type classes and their dead Create arms, and reconcile the Attr.Create
switch with the v22 attr-kind set.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The five ElaboratedType branches never match under clang 22 since the underlying
RecordType/EnumType/TypedefType is now hit directly; golden baselines are
unchanged, confirming the removal is output-neutral.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
clang 22 changed the type printer to spell an unnamed tag as `(unnamed at ...)`,
dropping the tag keyword that older releases embedded (`(anonymous struct at ...)`).
The keyword is still present as the elaborated prefix, so key off it to restore the
historical, version-stable NativeTypeName spelling rather than leaking the new form.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Adjust TemplateNameTest for the v22 sugar chain (SpecT's underlying type is now
the TemplateSpecializationType directly), drop the ElaboratedType desugar
assertions from ObjectiveCTest, and bump the embedded GeneratedCode version to
22.1.8.0.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Make a fresh generator run reproduce the committed clangsharp interop bindings so
ClangSharp self-hosts on clang 22. Several generator gaps had to be closed:

- Escape type names that are only lowercase ASCII (e.g. `clang`, `config`) with
  `@` to avoid CS8981. Applied centrally to every `TypeDecl` name and tag-type
  reference in name resolution; config and remap lookups strip the implicit `@`
  first so a user's raw `name`/`name=value` still matches.
- Preserve enumerator initializers that are a pure alias to (or `|` combination
  of) sibling enumerators, so range markers like `CX_DeclKind_FirstObjCImpl =
  CX_DeclKind_ObjCImplementation` stay symbolic instead of folding to a literal.
- When a folded enum member's value equals a prior sibling, emit that sibling
  symbolically. This keeps `_Last`/`MaxSemantics` markers -- whose initializer is
  an opaque X-macro count rather than a `DeclRefExpr` -- readable (e.g.
  `CX_UTT_Last = CX_UTT_IsTypedResourceElementCompatible`).

----------

List the specific enums that mirror an excluded companion in
GenerateClangSharp.rsp instead of folding everything with `*`.

----------

Fix the `CX_UETT_Last` off-by-one in libClangSharp: it kept clang's `-1` base
(clang's `UnaryExprOrTypeTrait` has no `Invalid` sentinel) even though we prepend
`CX_UETT_Invalid`, where-as `CX_TypeTrait` already uses `0`. `CX_UETT_Last` now
lands on `CX_UETT_VectorElements` like the other trait `_Last` markers.

Regenerate the affected clangsharp enums and add regression tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Wire clangsharp_Type_getKeyword, getDependence, and getAutoTypeKeyword through the
CXType handle wrapper as Keyword, Dependence, and AutoTypeKeyword, mirroring the
existing Type_get* accessor style.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
clang 22 reparented TagType, TypedefType, UsingType, UnresolvedUsingType, and
TemplateSpecializationType under TypeWithKeyword, so the elaboration keyword is now
observable on each; reparent them to match and surface it as TypeWithKeyword.Keyword.
Add the Type dependence predicates (IsDependentType, IsInstantiationDependentType,
IsVariablyModifiedType, ContainsUnexpandedParameterPack, ContainsErrors) over the
consolidated Dependence flags, and AutoType.Keyword.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
…state

A generation aborted mid-visit left `_outputBuilder` (and related builder
state) dangling, tripping the `_outputBuilder is null` assert from the
finalizer during GC teardown and crashing the test host, which masked the
underlying error and aborted the entire run.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
tannergooding and others added 5 commits July 16, 2026 10:29
…clang 22

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The win-arm64 libClangSharp 22.1.8.2 prebuilt ships broken clangsharp shims that access-violate and crash the test host. See dotnet#806.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Port the three Stmt kinds libclang added in clang 22 (DeferStmt,
MatrixSingleSubscriptExpr, OMPFuseDirective) into MakeCXCursor, and bump the
"Ported from" stamps on the mirrored libclang files to llvmorg-22.1.8. The
remaining files are byte-identical to the 22.1.8 upstream sources.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
The win-arm64 libClangSharp 22.1.8.2 native returns invalid template names and
access-violates in the cursor/type shims, so tests that read a TemplateName
cannot be validated there. Skip TemplateNameTest and DependentTemplateBaseTest
via a shared SkipUntilNativeRebuild helper on the interop and generator test
bases until the native is rebuilt. See dotnet#806.

Also drop the speculative dependent-base fallback added while diagnosing this;
the anonymous-name fix is retained.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@tannergooding
tannergooding merged commit 82645ae into dotnet:main Jul 16, 2026
12 checks passed
@tannergooding
tannergooding deleted the tannergooding-v22-regen branch July 16, 2026 20:07
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