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-12792] as [String: AnyObject?] crashes compiler/runtime #55237

Open
ahti opened this issue May 12, 2020 · 2 comments
Open

[SR-12792] as [String: AnyObject?] crashes compiler/runtime #55237

ahti opened this issue May 12, 2020 · 2 comments
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior.

Comments

@ahti
Copy link
Contributor

ahti commented May 12, 2020

Previous ID SR-12792
Radar rdar://problem/63199234
Original Reporter @ahti
Type Bug
Environment

Swift 5.2.2 on macOS 10.15.4, as well as Swift 5.2.3 in Docker, both on x86_64

Additional Detail from JIRA
Votes 0
Component/s
Labels Bug
Assignee None
Priority Medium

md5: 72f4d6c17f4c4d46cbf107dcf22a4330

Issue Description:

Combining various dictionary literals with as [String: AnyObject?] crashes either the compiler or at runtime. Examples with stack traces:

print(["a": 42] as [String: AnyObject?])
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret test.swift -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test
1.  Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
2.  While running user code "test.swift"
0  swift                    0x000000010b5ac4ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000010b5abcc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6eb905fd _sigtramp + 29
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 2437347872
4  libswiftCore.dylib       0x00007fff6e25c478 outlined init with copy of Any + 24
5  libswiftCore.dylib       0x00007fff6e0c5398 Swift.Optional.debugDescription.getter : Swift.String + 296
6  libswiftCore.dylib       0x00007fff6e04ebb2 Swift._debugPrint_unlocked<A, B where B: Swift.TextOutputStream>(A, inout B) -> () + 306
7  libswiftCore.dylib       0x00007fff6e0cd035 generic specialization <Swift.String> of Swift._debugPrint<A where A: Swift.TextOutputStream>(_: [Any], separator: Swift.String, terminator: Swift.String, to: inout A) -> () + 197
8  libswiftCore.dylib       0x00007fff6e039427 Swift.Dictionary.description.getter : Swift.String + 1143
9  libswiftCore.dylib       0x00007fff6e04e28c Swift._print_unlocked<A, B where B: Swift.TextOutputStream>(A, inout B) -> () + 684
10 libswiftCore.dylib       0x00007fff6e0ce462 merged generic specialization <Swift._Stdout> of Swift._print<A where A: Swift.TextOutputStream>(_: [Any], separator: Swift.String, terminator: Swift.String, to: inout A) -> () + 258
11 libswiftCore.dylib       0x00007fff6e0ccf29 merged Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 185
12 libswiftCore.dylib       0x00007fff6e0cc67f Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 31
13 libswiftCore.dylib       0x000000010daf3110 Swift.print(_: Any..., separator: Swift.String, terminator: Swift.String) -> () + 2678221488
14 swift                    0x000000010732f48a llvm::MCJIT::runFunction(llvm::Function*, llvm::ArrayRef<llvm::GenericValue>) + 458
15 swift                    0x00000001073364fb llvm::ExecutionEngine::runFunctionAsMain(llvm::Function*, 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&, char const* const*) + 2011
16 swift                    0x000000010730b5ba performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, 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*) + 14362
17 swift                    0x00000001072fff75 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55813
18 swift                    0x0000000107275f53 main + 1283
19 libdyld.dylib            0x00007fff6e997cc9 start + 1
print(["a": nil, "b": 1] as [String: AnyObject?])
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test -o /var/folders/kn/dv65kcr95js91rgy1vlf6zrm0000gn/T/test-4c142f.o
1.  Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
2.  While emitting IR SIL function "@main".
0  swift                    0x0000000104c734ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000104c72cc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6eb905fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007fc73e200000 _sigtramp + 3479632416
4  swift                    0x0000000100a35e89 llvm::GetElementPtrInst::getGEPReturnType(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>) + 121
5  swift                    0x0000000100a35c01 llvm::GetElementPtrInst::Create(llvm::Type*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::Twine const&, llvm::Instruction*) + 161
6  swift                    0x0000000100a35a58 llvm::IRBuilder<llvm::ConstantFolder, llvm::IRBuilderDefaultInserter>::CreateConstInBoundsGEP2_32(llvm::Type*, llvm::Value*, unsigned int, unsigned int, llvm::Twine const&) + 504
7  swift                    0x0000000100aca9d7 (anonymous namespace)::PayloadEnumImplStrategyBase::projectExtraTagBits(swift::irgen::IRGenFunction&, swift::irgen::Address) const + 87
8  swift                    0x0000000100ac6d06 (anonymous namespace)::PayloadEnumImplStrategyBase::initialize(swift::irgen::IRGenFunction&, swift::irgen::Explosion&, swift::irgen::Address, bool) const + 118
9  swift                    0x0000000100c06355 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 35301
10 swift                    0x0000000100bfa433 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
11 swift                    0x0000000100aadb02 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
12 swift                    0x0000000100bd8a29 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**) + 1097
13 swift                    0x00000001009cfe3f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, 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*) + 4255
14 swift                    0x00000001009c529a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48426
15 swift                    0x000000010093cf53 main + 1283
16 libdyld.dylib            0x00007fff6e997cc9 start + 1
17 libdyld.dylib            0x0000000000000010 start + 2439414600
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
print(["a": "hello there", "b": 1] as [String: AnyObject?])
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file test.swift -target x86_64-apple-darwin19.4.0 -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -color-diagnostics -module-name test -o /var/folders/kn/dv65kcr95js91rgy1vlf6zrm0000gn/T/test-e8149f.o
1.  Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
2.  While emitting IR SIL function "@main".
0  swift                    0x00000001055ef4ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x00000001055eecc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff6eb905fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007ffeee95fb00 _sigtramp + 2145187104
4  swift                    0x000000010157d942 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 16338
5  swift                    0x0000000101576433 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8835
6  swift                    0x0000000101429b02 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1410
7  swift                    0x0000000101554a29 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**) + 1097
8  swift                    0x000000010134be3f performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation&, 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*) + 4255
9  swift                    0x000000010134129a swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 48426
10 swift                    0x00000001012b8f53 main + 1283
11 libdyld.dylib            0x00007fff6e997cc9 start + 1
12 libdyld.dylib            0x0000000000000010 start + 2439414600
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal 11 (use -v to see invocation)
@CodaFi
Copy link
Member

CodaFi commented May 13, 2020

On master these crash in the SIL verifier

SIL verification failed: EnumInst operand type does not match type of case
  $AnyObject
  $Int
Verifying instruction:
     %26 = apply %25(%23, %24) : $@convention(method) (Builtin.IntLiteral, @thin Int.Type) -> Int // user: %27
->   %27 = enum $Optional<AnyObject>, #Optional.some!enumelt, %26 : $Int // user: %28
     store %27 to [init] %15 : $*Optional<AnyObject> // id: %28
SIL verification failed: EnumInst operand must be an object: UI->getOperand()->getType().isObject()
Verifying instruction:
     %23 = alloc_stack $Any                       // users: %55, %32, %30
->   %32 = enum $Optional<AnyObject>, #Optional.some!enumelt, %23 : $*Any // user: %33
     store %32 to [init] %15 : $*Optional<AnyObject> // id: %33

@CodaFi
Copy link
Member

CodaFi commented May 13, 2020

@swift-ci create

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 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.
Projects
None yet
Development

No branches or pull requests

2 participants