Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-10981] Compiler crash while access Error's localizedDescription by using KeyPath #53370

Open
swift-ci opened this issue Jun 20, 2019 · 5 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-10981
Radar None
Original Reporter cuzv (JIRA User)
Type Bug
Environment

Apple Swift version 5.1 (swiftlang-1100.0.38.29 clang-1100.0.20.14)
Target: x86_64-apple-darwin18.6.0

Xcode
Version 11.0 beta (11M336w)

Additional Detail from JIRA
Votes 2
Component/s Compiler
Labels Bug, CompilerCrash
Assignee None
Priority Medium

md5: a274109893ff51ab490a446b86926261

Issue Description:

This line will cause compiler crash.

 _ = \Error.localizedDescription
 

Log:

1. While emitting IR SIL function "@$s9SwiftDemo14ViewControllerC11viewDidLoadyyF".  for 'viewDidLoad()' (at ~/xx/xxx/ViewController.swift:15:12)
 0  swift                    0x000000010db798a3 PrintStackTraceSignalHandler(void*) + 51
 1  swift                    0x000000010db79076 SignalHandler(int) + 358
 2  libsystem_platform.dylib 0x00007fff5d65ab5d _sigtramp + 29
 3  swift                    0x000000010db3c632 llvm::StringMapImpl::FindKey(llvm::StringRef) const + 354
 4  swift                    0x00000001099b8e8b clang::CodeGen::ConstantInitFuture llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>::callback_fn<swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature*, bool)::$_1>(long, swift::irgen::ConstantInitBuilder&) + 923
 5  swift                    0x0000000109a6b139 swift::irgen::IRGenModule::getAddrOfStringForMetadataRef(llvm::StringRef, unsigned int, bool, llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>) + 345
 6  swift                    0x00000001099b89a8 swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature*, bool) + 1512
 7  swift                    0x0000000109964618 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool)::$_5>(long, swift::irgen::GenericRequirement) + 472
 8  swift                    0x000000010995c352 emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool) + 3378
 9  swift                    0x000000010995a821 swift::irgen::IRGenModule::getAddrOfKeyPathPattern(swift::KeyPathPattern*, swift::SILLocation) + 2913
 10 swift                    0x0000000109a24559 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 11545
 11 swift                    0x0000000109a1ecca swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 9818
 12 swift                    0x00000001098d1150 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1616
 13 swift                    0x00000001099fc05e performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::_1::unique_ptr<swift::SILModule, std::_1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**) + 1182
 14 swift                    0x00000001097ede2a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 37130
 15 swift                    0x00000001097e1424 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6868
 16 swift                    0x00000001097706b3 main + 1219
 17 libdyld.dylib            0x00007fff5d46f3d5 start + 1
 18 libdyld.dylib            0x0000000000000048 start + 2730036340
 error: Segmentation fault: 11
 
@belkadan
Copy link
Contributor

On master I get "type of expression is ambiguous without more context", which isn't really correct either. @jckarter, @xedin, any idea what's going on?

@jckarter
Copy link
Member

Hm, brentdax (JIRA User) was recently tweaking key path type checking. Might be related to his changes?

I'm still planning on looking into the IRGen/runtime side of this.

@beccadax
Copy link
Contributor

@jckarter That work hasn't been merged to master and probably won't make 5.1.

This might be the same bug you're fixing in #25421 the backtrace looks pretty familiar.

@jckarter
Copy link
Member

Thanks Brent. I don't know why the type checking behavior would have changed, then.

@mayoff
Copy link

mayoff commented Feb 20, 2020

This still crashes the compiler as of swift-DEVELOPMENT-SNAPSHOT-2020-02-16-a.xctoolchain.

Note that the description doesn't include everything necessary to crash. You also have to import Foundation:

import Foundation
_ = \Error.localizedDescription

Here's my stack trace:

Stack dump:
0.  Program arguments: /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2020-02-16-a.xctoolchain/usr/bin/swift -frontend -interpret /Users/mayoff/TestProjects/dynamicMemberLookupCrash/dynamicMemberLookupCrash/main.swift -enable-objc-interop -sdk /Applications/Xcode-11.3.1.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -module-name main 
1.  Apple Swift version 5.2-dev (LLVM 89a551f495, Swift 4b2b436033)
2.  While running user code "/Users/mayoff/TestProjects/dynamicMemberLookupCrash/dynamicMemberLookupCrash/main.swift"
3.  While emitting IR SIL function "@main".
0  swift                    0x00000001099a8ba5 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x00000001099a7de5 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x00000001099a918c SignalHandler(int) + 268
3  libsystem_platform.dylib 0x00007fff6f29642d _sigtramp + 29
4  libsystem_platform.dylib 0x00007f9d52d96798 _sigtramp + 18446743652327752584
5  swift                    0x0000000105bd7f13 clang::CodeGen::ConstantInitFuture llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>::callback_fn<swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature, bool)::$_1>(long, swift::irgen::ConstantInitBuilder&) + 483
6  swift                    0x0000000105c64b1f swift::irgen::IRGenModule::getAddrOfStringForMetadataRef(llvm::StringRef, unsigned int, bool, llvm::function_ref<clang::CodeGen::ConstantInitFuture (swift::irgen::ConstantInitBuilder&)>) + 255
7  swift                    0x0000000105bd27aa swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature, bool) + 730
8  swift                    0x0000000105ba3a59 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool)::$_5>(long, swift::irgen::GenericRequirement) + 361
9  swift                    0x0000000105bc4605 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 277
10 swift                    0x0000000105b9e4fe emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool) + 2078
11 swift                    0x0000000105b9d78e swift::irgen::IRGenModule::getAddrOfKeyPathPattern(swift::KeyPathPattern*, swift::SILLocation) + 1950
12 swift                    0x0000000105c325f3 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 19971
13 swift                    0x0000000105c2a14e swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7742
14 swift                    0x0000000105b420b1 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 881
15 swift                    0x0000000105c03ac6 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1350
16 swift                    0x0000000105c02344 swift::performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1172
17 swift                    0x00000001059e67f6 swift::RunImmediately(swift::CompilerInstance&, std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&, swift::IRGenOptions const&, swift::SILOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >&&) + 310
18 swift                    0x00000001059d02ba performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, bool, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, bool, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 2378
19 swift                    0x00000001059c4d61 performCompile(swift::CompilerInstance&, swift::CompilerInvocation const&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 9297
20 swift                    0x00000001059c1948 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4472
21 swift                    0x000000010595519d main + 861
22 libdyld.dylib            0x00007fff6f09d7fd start + 1
23 libdyld.dylib            0x0000000000000009 start + 18446603338653247501

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@AnthonyLatsis AnthonyLatsis added the crash Bug: A crash, i.e., an abnormal termination of software label Dec 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself crash Bug: A crash, i.e., an abnormal termination of software
Projects
None yet
Development

No branches or pull requests

6 participants