swiftlang / swift

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

[SR-13607] 3 line program that'll crash macOS playground in either Xcode 12.0 (12A7209) or 12.2 beta (12B5018i) #56042

Open haikusw opened 3 years ago

haikusw commented 3 years ago
Previous ID SR-13607
Radar rdar://problem/69549212
Original Reporter @haikusw
Type Bug
Environment Xcode 12.0 (12A7209) macOS 10.15.6 $ \~ % xcode-select -p /Applications/Xcode.app/Contents/Developer $ \~ % swift --version Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1) Target: x86_64-apple-darwin19.6.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 21f88a9b912cb19e00cbce32ffe60b7e

Issue Description:

This crashes the macOS playground in Xcode 12.0 (12A7209) and 12.2 beta (12B5018i):

import Cocoa

enum Test {
    case one(String.Type)
}

let crash = Test.one(String.self)   
Xcode 12.0:
// error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x3).

Xcode 12.2 beta:
// error: Execution was interrupted, reason: EXC_BAD_ACCESS (code=1, address=0x746f4e746360).

Steps:

1) Launch Xcode 12.0 GM (12A7209) or 12.2 beta (12B5018i)
2) File -> New Playground…
3) choose "macOS", "Empty"
4) paste or type in the few lines of code above.
5) run playground (or let it auto run)

-> when the playground runs (or when you run it), crash on last line with error indicated.

typesanitizer commented 3 years ago

@swift-ci create

typesanitizer commented 3 years ago

Yikes. Slightly reduced example:

enum Test {
    case one(String.Type)
}
print(Test.one(String.self))

Backtrace on crash

* thread #​1, queue = 'com.apple.main-thread', stop reason = EXC_BAD_ACCESS (code=1, address=0x3b6000000002)
  * frame #&#8203;0: 0x00007fff6d54bd89 libswiftCore.dylib`swift::gatherWrittenGenericArgs(swift::TargetMetadata<swift::InProcess> const*, swift::TargetTypeContextDescriptor<swift::InProcess> const*, llvm::SmallVectorImpl<swift::TargetMetadata<swift::InProcess> const*>&, swift::Demangle::Demangler&) + 25
    frame #&#8203;1: 0x00007fff6d52a963 libswiftCore.dylib`swift::_swift_buildDemanglingForMetadata(swift::TargetMetadata<swift::InProcess> const*, swift::Demangle::Demangler&) + 707
    frame #&#8203;2: 0x00007fff6d524ea9 libswiftCore.dylib`swift::nameForMetadata(swift::TargetMetadata<swift::InProcess> const*, bool) + 297
    frame #&#8203;3: 0x00007fff6d525179 libswiftCore.dylib`swift_getTypeName + 393
    frame #&#8203;4: 0x00007fff6d354de1 libswiftCore.dylib`printTypeName #&#8203;1 <A, B where B: Swift.TextOutputStream>(Any.Type) -> () in Swift._adHocPrint_unlocked<A, B where B: Swift.TextOutputStream>(_: A, _: Swift.Mirror, _: inout B, isDebugPrint: Swift.Bool) -> () + 33
    frame #&#8203;5: 0x00007fff6d35398e libswiftCore.dylib`Swift._adHocPrint_unlocked<A, B where B: Swift.TextOutputStream>(_: A, _: Swift.Mirror, _: inout B, isDebugPrint: Swift.Bool) -> () + 2526
    frame #&#8203;6: 0x00007fff6d2bef01 libswiftCore.dylib`Swift._debugPrint_unlocked<A, B where B: Swift.TextOutputStream>(A, inout B) -> () + 737
    frame #&#8203;7: 0x00007fff6d3543f8 libswiftCore.dylib`Swift._adHocPrint_unlocked<A, B where B: Swift.TextOutputStream>(_: A, _: Swift.Mirror, _: inout B, isDebugPrint: Swift.Bool) -> () + 5192
    frame #&#8203;8: 0x00007fff6d2be525 libswiftCore.dylib`Swift._print_unlocked<A, B where B: Swift.TextOutputStream>(A, inout B) -> () + 1077
    frame #&#8203;9: 0x00007fff6d35b532 libswiftCore.dylib`merged generic specialization <Swift._Stdout> of Swift._print<A where A: Swift.TextOutputStream>(_: Swift.Array<Any>, separator: Swift.String, terminator: Swift.String, to: inout A) -> () + 258
    frame #&#8203;10: 0x00007fff6d359ee9 libswiftCore.dylib`merged Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 185
    frame #&#8203;11: 0x00007fff6d35941f libswiftCore.dylib`Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 31
    frame #&#8203;13: 0x0000000100003b74 tmp3`main + 20
    frame #&#8203;14: 0x00007fff6dbee991 libdyld.dylib`start + 1
typesanitizer commented 3 years ago

Lifting out the print statement into a function myFunc and printing the IR:

define hidden swiftcc void @"$s4main6myFuncyyF"() #&#8203;0 {
entry:
  %0 = call swiftcc { %swift.bridge*, i8* } @"$ss27_allocateUninitializedArrayySayxG_BptBwlF"(i64 1, %swift.type* getelementptr inbounds (%swift.full_type, %swift.full_
type* @"$sypN", i32 0, i32 1))
  %1 = extractvalue { %swift.bridge*, i8* } %0, 0
  %2 = extractvalue { %swift.bridge*, i8* } %0, 1
  %3 = bitcast i8* %2 to %Any*
  %4 = getelementptr inbounds %Any, %Any* %3, i32 0, i32 1
  store %swift.type* bitcast (i64* getelementptr inbounds (<{ i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32 }>* }>, <{ i8**, i64, <{ i32, i32, i32, i32, i32, i32, i32
 }>* }>* @"$s4main4TestOMf", i32 0, i32 1) to %swift.type*), %swift.type** %4, align 8
  %5 = getelementptr inbounds %Any, %Any* %3, i32 0, i32 0
  %6 = getelementptr inbounds %Any, %Any* %3, i32 0, i32 0
  %7 = bitcast [24 x i8]* %6 to %T4main4TestO*
  %8 = call swiftcc { i64, %swift.bridge* } @"$ss5print_9separator10terminatoryypd_S2StFfA0_"()
  %9 = extractvalue { i64, %swift.bridge* } %8, 0
  %10 = extractvalue { i64, %swift.bridge* } %8, 1
  %11 = call swiftcc { i64, %swift.bridge* } @"$ss5print_9separator10terminatoryypd_S2StFfA1_"()
  %12 = extractvalue { i64, %swift.bridge* } %11, 0
  %13 = extractvalue { i64, %swift.bridge* } %11, 1
  call swiftcc void @"$ss5print_9separator10terminatoryypd_S2StF"(%swift.bridge* %1, i64 %9, %swift.bridge* %10, i64 %12, %swift.bridge* %13)
  call void @swift_bridgeObjectRelease(%swift.bridge* %13) #&#8203;1
  call void @swift_bridgeObjectRelease(%swift.bridge* %10) #&#8203;1
  call void @swift_bridgeObjectRelease(%swift.bridge* %1) #&#8203;1
  ret void
}
haikusw commented 2 years ago

Still crashes Xcode 13.0 macOS playground (on macOS 11.5.2) fwiw.