swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.58k stars 10.36k forks source link

Swiftc miscompiles availability checks in catalyst builds #62884

Closed etcwilde closed 4 weeks ago

etcwilde commented 1 year ago

Catalyst builds fail to test in SILGen/availability_query_maccatalyst_zippered_canonical_versions.swift.

The code in question

if #available(OSX 10.16, iOS 51.1.2, *) { }

The expected output for a catalyst executable should include checks for both the macOS and the iOS version numbers. The SILGen emitted from the open-source compiler only includes the check for the macOS version.

Expected:

  %2 = integer_literal $Builtin.Word, 10          // user: %9
  %3 = integer_literal $Builtin.Word, 16          // user: %9
  %4 = integer_literal $Builtin.Word, 0           // user: %9
  %5 = integer_literal $Builtin.Word, 51          // user: %9
  %6 = integer_literal $Builtin.Word, 1           // user: %9
  %7 = integer_literal $Builtin.Word, 2           // user: %9
  // function_ref _stdlib_isOSVersionAtLeastOrVariantVersionAtLeast(_:_:_:_:_:_:)
  %8 = function_ref @$ss042_stdlib_isOSVersionAtLeastOrVariantVersiondE0yBi1_Bw_BwBwBwBwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1 // user: %9                                                                                                                                         
  %9 = apply %8(%2, %3, %4, %5, %6, %7) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1 // user: %10

Got:

  %2 = integer_literal $Builtin.Word, 10          // user: %6
  %3 = integer_literal $Builtin.Word, 16          // user: %6
  %4 = integer_literal $Builtin.Word, 0           // user: %6
  // function_ref _stdlib_isOSVersionAtLeast(_:_:_:)
  %5 = function_ref @$ss26_stdlib_isOSVersionAtLeastyBi1_Bw_BwBwtF : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1 // user: %6
  %6 = apply %5(%2, %3, %4) : $@convention(thin) (Builtin.Word, Builtin.Word, Builtin.Word) -> Builtin.Int1 // user: %7

I've disabled the catalyst build from the nightly toolchain here; https://github.com/apple/swift/pull/62882

etcwilde commented 1 year ago

This issue is linked to rdar://103960437

drodriguez commented 3 months ago

Found the same problem in #75261 when I tried to implement macCatalyst in the compiler. My solution was changing the test, which is probably not right, if the test works unchanged internally for Apple.

tshortli commented 4 weeks ago

This was fully resolved by https://github.com/swiftlang/swift/pull/75646.