Swift 1.2b2: swiftc -O Crash When Accessing Members of Cast Object In Conditional

Originator:wetzeal
Number:rdar://19948357 Date Originated:24-Feb-2015 09:03 PM
Status:Closed Resolved:23-Mar-2015
Product:Developer Tools Product Version:Xcode-beta (6D532l)
Classification:Serious Bug Reproducible:Always
 
Summary:
Accessing a member of an object cast inside an if {} conditional that checks the object is not of some type crashes the swift compiler when optimizations are enabled.
This only occurs inside an application target, I cannot reproduce it via swiftc or in a playground.

Steps to Reproduce:
Compile the following code in an iOS target with optimizations enabled:

class A { var d = "" }
func t() {
    let o: AnyObject = A()
    if !(o is A) {
        _ = (o as! A).d
    }
}

Expected Results:
The code compiles

Actual Results:
The compiler crashes with the following error:
0  swift                    0x00000001048a1508 llvm::sys::PrintStackTrace(__sFILE*) + 40
1  swift                    0x00000001048a19e4 SignalHandler(int) + 452
2  libsystem_platform.dylib 0x00007fff97c49f1a _sigtramp + 26
3  libsystem_platform.dylib 0x00007fff5ba78650 _sigtramp + 3286427472
4  swift                    0x00000001043e0eda (anonymous namespace)::DCE::markControllingTerminatorsLive(swift::SILBasicBlock*) + 346
5  swift                    0x00000001043e0c69 (anonymous namespace)::DCE::markValueLive(swift::ValueBase*) + 201
6  swift                    0x00000001043e047f (anonymous namespace)::DCE::run() + 1983
7  swift                    0x000000010438814e swift::SILPassManager::runFunctionPasses(llvm::ArrayRef<swift::SILFunctionTransform*>) + 1310
8  swift                    0x0000000104388bd9 swift::SILPassManager::runOneIteration() + 633
9  swift                    0x0000000104387646 swift::runSILOptimizationPasses(swift::SILModule&) + 790
10 swift                    0x000000010418b478 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 4584
11 swift                    0x000000010418a0e6 main + 1814
12 libdyld.dylib            0x00007fff8e5a15c9 start + 1
13 libdyld.dylib            0x000000000000003c start + 1906698868


Regression:
This does not occur with Swift 1.1 and Xcode 6.1.1

Notes:
The test given is a meaningless trivial example, but this error happens in less tautological code. Removing either the ! in the if check, or the member access inside the body, causes the crash to go away.

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!