swiftlang / swift

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

[SR-6210] Compiler crashes when subscripting with key path and IUO #48762

Open swift-ci opened 6 years ago

swift-ci commented 6 years ago
Previous ID SR-6210
Radar None
Original Reporter miodrag (JIRA User)
Type Bug

Attachment: Download

Environment Apple Swift version 4.0 (swiftlang-900.0.65.2 clang-900.0.37) Target: x86_64-apple-macosx10.9 and Apple Swift version 4.1-dev (LLVM f35a4270ce, Clang bb20a94e86, Swift 34e602b93a) Target: x86_64-apple-darwin16.7.0
Additional Detail from JIRA | | | |------------------|-----------------| |Votes | 0 | |Component/s | Compiler | |Labels | Bug, CompilerCrash, KeyPaths | |Assignee | None | |Priority | Medium | md5: 2df0fac06009918ebe35f22540c170c0

relates to:

Issue Description:

This could be related to SR-6198 which appears to be fixed in the latest toolchain. The following code does not compile with -O in swift 4.0 and in 4.1-dev(with or without -O):

struct A {
    var a:Int
}
let a:A! = A(a:1)
_ = a[keyPath: \A.a]

with 4.0 and -O the result is:

0  swift                    0x0000000109cfddba PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000109cfd1f6 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff8ff5ab3a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000001 _sigtramp + 1879725281
4  swift                    0x00000001066af47e llvm::GetElementPtrInst::getGEPReturnType(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>) + 62
5  swift                    0x00000001066af348 llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::Instruction*) + 136
6  swift                    0x00000001066af151 llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateConstInBoundsGEP2_32(llvm::Type*, llvm::Value*, unsigned int, unsigned int, llvm::Twine const&) + 401
7  swift                    0x00000001067297d4 (anonymous namespace)::PayloadEnumImplStrategyBase::projectExtraTagBits(swift::irgen::IRGenFunction&, swift::irgen::Address) const + 84
8  swift                    0x000000010672815b (anonymous namespace)::PayloadEnumImplStrategyBase::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address) const + 123
9  swift                    0x0000000106811a71 swift::SILVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::ValueBase*) + 26865
10 swift                    0x00000001068089b0 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9152
11 swift                    0x00000001067133ee swift::irgen::IRGenerator::emitGlobalTopLevel() + 1022
12 swift                    0x00000001067eab7b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1243
13 swift                    0x00000001067e87b9 swift::performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, llvm::LLVMContext&, llvm::GlobalVariable**) + 1529
14 swift                    0x00000001066713ef performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 17615
15 swift                    0x000000010666b6b4 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7716
16 swift                    0x00000001066205d8 main + 12248
17 libdyld.dylib            0x00007fff8fd4b235 start + 1
Stack dump:
0. Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret bug.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -O -module-name bug 
1. While emitting IR SIL function "@main".
Segmentation fault: 11

with 4.1-dev, with or without -O :

TYPE MISMATCH IN ARGUMENT 0 OF APPLY AT expression at [bug.swift:5:5 - line:5:20] RangeText="a[keyPath: \A.a]"
  argument value:   %13 = alloc_stack $Optional<A>                  // user: %15
  parameter type: $*A
0  swift                    0x0000000108cc99c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 40
1  swift                    0x0000000108cc8916 llvm::sys::RunSignalHandlers() + 86
2  swift                    0x0000000108cc9f8e SignalHandler(int) + 366
3  libsystem_platform.dylib 0x00007fff8ff5ab3a _sigtramp + 26
4  libsystem_platform.dylib 0x000000010fb6f551 _sigtramp + 2143373873
5  libsystem_c.dylib        0x00007fff8fddf420 abort + 129
6  swift                    0x0000000105f4500b swift::Lowering::SILGenFunction::emitApply(std::__1::unique_ptr<swift::Lowering::ResultPlan, std::__1::default_delete<swift::Lowering::ResultPlan> >&&, swift::Lowering::ArgumentScope&&, swift::SILLocation, swift::Lowering::ManagedValue, llvm::ArrayRef<swift::Substitution>, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::Lowering::ApplyOptions, swift::Lowering::SGFContext) + 5019
7  swift                    0x0000000105f4a375 swift::Lowering::SILGenFunction::emitApplyOfLibraryIntrinsic(swift::SILLocation, swift::FuncDecl*, llvm::ArrayRef<swift::Substitution> const&, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::SGFContext) + 1093
8  swift                    0x0000000105f49efc swift::Lowering::SILGenFunction::emitApplyOfLibraryIntrinsic(swift::SILLocation, swift::FuncDecl*, swift::SubstitutionMap const&, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::SGFContext) + 220
9  swift                    0x0000000105fae6d4 swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 28852
10 swift                    0x0000000105fa2934 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 516
11 swift                    0x0000000105fa935f swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 7487
12 swift                    0x0000000105fa2934 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 516
13 swift                    0x0000000105f3d6c6 swift::Lowering::SILGenModule::visitTopLevelCodeDecl(swift::TopLevelCodeDecl*) + 406
14 swift                    0x0000000105f3deeb swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 875
15 swift                    0x0000000105f3ec65 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool) + 437
16 swift                    0x0000000105f3f17c swift::performSILGeneration(swift::ModuleDecl*, swift::SILOptions&, bool) + 28
17 swift                    0x00000001058b3897 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 12423
18 swift                    0x00000001058af8e3 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3315
19 swift                    0x00000001058705d0 main + 3360
20 libdyld.dylib            0x00007fff8fd4b235 start + 1
Stack dump:
0. Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2017-10-23-a.xctoolchain/usr/bin/swift -frontend -interpret bug.swift -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -color-diagnostics -module-name bug 
Abort trap: 6
belkadan commented 6 years ago

@jckarter, look familiar?