Commit Graph

5 Commits

Author SHA1 Message Date
Alexis Laferrière
839a334e05 PrintAsClang: Fix unicode-scalar-reference.swift on watchOS
rdar://158076988
2025-08-12 08:57:10 -07:00
Alexis Laferrière
d46655e538 PrintAsClang: Disable Float16 check on platforms where it's unsupported 2025-08-06 14:32:23 -07:00
Alexis Laferrière
20c7334db4 PrintAsClang: Print Unicode.Scalar as char32_t and Float16 as _Float16 2025-08-05 14:31:30 -07:00
Alexis Laferrière
ed61bcf121 PrintAsClang: Use TypeDecl to associate Swift types to C printed type names
There was a hard to see misalignment between types accepted as
representable in C languages defined in `BuiltinMappedTypes.def` and
those with an associated C type name defined in `PrimitiveTypeMapping`.
While `BuiltinMappedTypes` looked through typealiases,
`PrimitiveTypeMapping` didn't and instead referred only to types by
their identifier. So even when both files defined the same types by
name, their underlying type were only partially handled. An affected
type was `Unicode.Scalar` which is the underlying type of `CWideChar`
and `CChar32`. `Unicode.Scalar` was accepted as a C representable type
but was not printed using a corresponding C type name, breaking the
generated compatibility header.

Another issue with the use of identifiers in the PrimitiveTypeMapping
logic was a limited support for nested types. It would track
`Unicode.Scalar` only as `Scalar`.

This change updates `PrimitiveTypeMapping` to keep track of TypeDecls
instead of identifiers and look through typealiases. This fixes the
issue with `Unicode.Scalar`, allowing it to be printed using the type
defined by an alias and avoid matching an unrelated Scalar. It should
also prevent future types behind typealiases to trigger this same kind
of misalignment.

rdar://157332446
2025-08-05 13:36:37 -07:00
Alexis Laferrière
54362d846c PrintAsClang: Protect null dereference and document Scalar behavior
Fix crash when printing references to Unicode.Scalar in the
compatibility header.

Unicode.Scalar should not be printed in the first place, it's a Swift
struct. It should either be considered non-representable or printed as a
C / Objective-C type if that's the intent.

rdar://157120538
2025-07-31 17:22:11 -07:00