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-15346] IRGen crashed with a function that has Self as parameter type #57668

Open
kemchenj opened this issue Oct 16, 2021 · 4 comments
Open
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 IRGen LLVM IR generation

Comments

@kemchenj
Copy link

Previous ID SR-15346
Radar None
Original Reporter @kemchenj
Type Bug
Environment

Xcode 13.0

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

md5: 1b44139f581b232275d47897a6071ae9

Issue Description:

Currently the compiler will complain this function call with `Result of call to `foo(bar: )` is unused`:

import Foundation

extension NSObject {
  func foo(bar: (Self) -> Void) {}
}

let object = NSObject()

object.foo { _ in } // Result of call to `foo(bar:)` is unused
@LucianoPAlmeida
Copy link
Collaborator

Also seems to crash in IRGen [Xcode 13.0 (13A233)]
Stacktrace bellow

/Users/lucianoalmeida/Documents/programming/Learning/switc/switc/main.swift:35:8: warning: result of call to 'foo(bar:)' is unused
object.foo { _ in }
       ^   ~~~~~~~~
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the project and the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/lucianoalmeida/Documents/programming/Learning/switc/switc/main.swift -emit-module-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main~partial.swiftmodule -emit-module-doc-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main~partial.swiftdoc -emit-module-source-info-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main~partial.swiftsourceinfo -emit-dependencies-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main.d -emit-reference-dependencies-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main.swiftdeps -serialize-diagnostics-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main.dia -target arm64-apple-macos11.2 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -I /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Products/Debug -F /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Products/Debug -enable-testing -g -module-cache-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -serialize-debugging-options -Xcc -working-directory -Xcc /Users/lucianoalmeida/Documents/programming/Learning/switc -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/switc-generated-files.hmap -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/switc-own-target-headers.hmap -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/switc-all-target-headers.hmap -Xcc -iquote -Xcc /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/switc-project-headers.hmap -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Products/Debug/include -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/DerivedSources-normal/arm64 -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/DerivedSources/arm64 -Xcc -I/Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/DerivedSources -Xcc -DDEBUG=1 -module-name switc -target-sdk-version 11.3.0 -o /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Build/Intermediates.noindex/switc.build/Debug/switc.build/Objects-normal/arm64/main.o -index-store-path /Users/lucianoalmeida/Library/Developer/Xcode/DerivedData/switc-hjhulawumcizrsccfgobepwmfhcu/Index/DataStore -index-system-modules
1.  Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)
2.  
3.  While evaluating request IRGenRequest(IR Generation for file "/Users/lucianoalmeida/Documents/programming/Learning/switc/switc/main.swift")
4.  While emitting IR SIL function "@main".
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x00000001052545e4 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001052536ec llvm::sys::RunSignalHandlers() + 128
2  swift-frontend           0x0000000105254c24 SignalHandler(int) + 292
3  libsystem_platform.dylib 0x00000001a1dcac44 _sigtramp + 56
4  swift-frontend           0x000000010138db44 swift::irgen::IRGenFunction::getDynamicSelfMetadata() + 140
5  swift-frontend           0x000000010148690c emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 528
6  swift-frontend           0x0000000101485dbc swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 256
7  swift-frontend           0x00000001014897a8 swift::irgen::emitMetatypeRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::MetatypeType>, swift::irgen::Explosion&) + 72
8  swift-frontend           0x0000000101453928 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 27676
9  swift-frontend           0x0000000101448180 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7732
10 swift-frontend           0x0000000101322684 swift::irgen::IRGenerator::emitGlobalTopLevel(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&) + 1332
11 swift-frontend           0x000000010141bd44 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 7572
12 swift-frontend           0x0000000101446074 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
13 swift-frontend           0x00000001014261c4 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 752
14 swift-frontend           0x000000010141f9e4 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 236
15 swift-frontend           0x0000000100fea300 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2544
16 swift-frontend           0x0000000100fdd4fc swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6508
17 swift-frontend           0x0000000100f37e6c main + 932
18 libdyld.dylib            0x00000001a1d9d430 start + 4
error: Segmentation fault: 11 (in target 'switc' from project 'switc')

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@kemchenj kemchenj changed the title [SR-15346] void function call with Result of call is unused warnings [SR-15346] IRGen crashed with a function that has Self as parameter type May 5, 2022
@xwu xwu added IRGen LLVM IR generation crash Bug: A crash, i.e., an abnormal termination of software labels May 27, 2022
@kemchenj
Copy link
Author

kemchenj commented Jun 13, 2022

Update, still crash in Xcode 14 beta 1

Stack dump:
0.	Program arguments: /Applications/Xcode-14-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file Untitled.swift -target arm64-apple-macosx12.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode-14-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk -new-driver-path /Applications/Xcode-14-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode-14-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name Untitled -disable-clang-spi -target-sdk-version 13.0 -o /var/folders/0g/19fzt3zj69dgvkfh_v7tbl1h0000gn/T/TemporaryDirectory.wr65sQ/Untitled-1.o
1.	Apple Swift version 5.7 (swiftlang-5.7.0.113.202 clang-1400.0.16.2)
2.	Compiling with the current language version
3.	While evaluating request IRGenRequest(IR Generation for file "Untitled.swift")
4.	While emitting IR SIL function "@main".
Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000105890160 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010588f174 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x00000001058907e4 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001ac4d74a4 _sigtramp + 56
4  swift-frontend           0x000000010134ba10 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 868
5  swift-frontend           0x000000010134ba10 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 868
6  swift-frontend           0x000000010134aec4 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 268
7  swift-frontend           0x000000010134ecbc swift::irgen::emitMetatypeRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::MetatypeType>, swift::irgen::Explosion&) + 72
8  swift-frontend           0x000000010130dc20 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 9776
9  swift-frontend           0x0000000101306650 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7772
10 swift-frontend           0x00000001011d3574 swift::irgen::IRGenerator::emitGlobalTopLevel(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&) + 1660
11 swift-frontend           0x00000001012d4914 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2556
12 swift-frontend           0x0000000101304528 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
13 swift-frontend           0x00000001012e0e00 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 744
14 swift-frontend           0x00000001012d7cf4 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 236
15 swift-frontend           0x0000000100f04e98 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 2140
16 swift-frontend           0x0000000100f06d4c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6252
17 swift-frontend           0x0000000100eaa474 swift::mainEntry(int, char const**) + 3940
18 dyld                     0x0000000107fc508c start + 520

@AnthonyLatsis
Copy link
Collaborator

This is expected because dynamic Self (or Self?) is not supposed to be allowed anywhere other than in direct, top-level result position. So the real bug is that we fail to diagnose an unsupported usage of Self.

@kemchenj
Copy link
Author

This is expected because dynamic Self (or Self?) is not supposed to be allowed anywhere other than in direct, top-level result position. So the real bug is that we fail to diagnose an unsupported usage of Self.

Oh, I got it now. Thanks for your explanation.

@AnthonyLatsis AnthonyLatsis added CompilerCrash and removed crash Bug: A crash, i.e., an abnormal termination of software labels Sep 17, 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 IRGen LLVM IR generation
Projects
None yet
Development

No branches or pull requests

4 participants