Skip to content

Collection bridging coercion miscompiles in noasserts #83201

Description

@hamishknight

The following hits a SIL verification error for asserts builds:

import Foundation
var a = 1
[a] as [NSNumber?]
SIL verification failed: EnumInst operand type does not match type of case
  $NSNumber
  $Int
Verifying instruction:
     %17 = load [trivial] %16 : $*Int             // user: %19
->   %19 = enum $Optional<NSNumber>, #Optional.some!enumelt, %17 : $Int // user: %20
     store %19 to [init] %15 : $*Optional<NSNumber> // id: %20

But in noasserts builds it miscompiles

Seems like we're incorrectly inserting a BridgeFromObjCExpr instead of a BridgeToObjCExpr:

(brace_stmt implicit range=[main.swift:1270:1 - line:1270:18]
  (coerce_expr type="[NSNumber?]" location=main.swift:1270:5 range=[main.swift:1270:1 - line:1270:18] written_type="[NSNumber?]"
    (array_expr type="[NSNumber?]" location=main.swift:1270:1 range=[main.swift:1270:1 - line:1270:3] initializer="Swift.(file).Array extension.init(arrayLiteral:) [with (substitution_map generic_signature=<Element where Element : Copyable, Element : Escapable> Element -> NSNumber?)]"
      (bridge_from_objc_expr implicit type="NSNumber?" location=main.swift:1270:2 range=[main.swift:1270:2 - line:1270:2]
        (load_expr implicit type="Int" location=main.swift:1270:2 range=[main.swift:1270:2 - line:1270:2]
          (declref_expr type="@lvalue Int" location=main.swift:1270:2 range=[main.swift:1270:2 - line:1270:2] decl="main.(file).a@main.swift:1269:5" function_ref=unapplied))))))))

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    assertion failureBug → crash: An assertion failurecompilerThe Swift compiler itselfcrashBug: A crash, i.e., an abnormal termination of softwareexpressionsFeature: expressionsimplicit conversionsFeature: implicit conversionsmiscompileBug: Compiler produces incorrect codegentype checkerArea → compiler: Semantic analysis

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions