Mangle synthesized error structs as a variant of the imported enum

When importing a C enum with the ns_error_domain attribute, we
synthesize a struct containing an NSError object to represent errors
in that domain. That synthesized struct should have a mangled name
that ties it to the original C enum, if we want it to be stable, and
now it does.

Before: $SSC7MyErrorV (a normal struct, which is a lie)
After: $SSC11MyErrorCode13ns_error_enumLLV
  kind=Global
    kind=Structure
      kind=Module, text="__C_Synthesized"
      kind=PrivateDeclName
        kind=Identifier, text="ns_error_enum"
        kind=Identifier, text="MyErrorCode"

Using the "private discriminator" feature allows us to pack in extra
information about the declaration without changing the mangling
grammar, and without stepping on anything the importer is using.

More rdar://problem/24688918
This commit is contained in:
Jordan Rose
2018-01-09 17:15:30 -08:00
parent 9c4d6f4893
commit 9c1a22ad0f
18 changed files with 239 additions and 67 deletions

View File

@@ -1422,6 +1422,8 @@ namespace decls_block {
= BCRecordLayout<ObjCRuntimeName_DECL_ATTR>;
using RestatedObjCConformanceDeclAttrLayout
= BCRecordLayout<RestatedObjCConformance_DECL_ATTR>;
using CustomTypeNameManglingDeclAttrLayout
= BCRecordLayout<CustomTypeNameMangling_DECL_ATTR>;
using InlineDeclAttrLayout = BCRecordLayout<
Inline_DECL_ATTR,