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-4058] Compiler crashes if overloaded method signature contains varargs followed by a second parameter #46641

Closed
swift-ci opened this issue Feb 24, 2017 · 2 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 SILGen Area → compiler: The SIL generation stage

Comments

@swift-ci
Copy link
Collaborator

Previous ID SR-4058
Radar None
Original Reporter palle (JIRA User)
Type Bug
Status Resolved
Resolution Duplicate
Environment

swift version:
Apple Swift version 3.1 (swiftlang-802.0.36.2 clang-802.0.35)
Target: x86_64-apple-macosx10.9

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

md5: 6fbdac0e11237695e145dea45bd8e6e7

duplicates:

  • SR-1076 SILGen crash on overloading functions which take varargs & arrays

relates to:

  • SR-3734 Mangling variadicity of function parameters

Issue Description:

The following code will crash the swift compiler (and REPL):

func foo(foo: [Int], bar: Int) {
}
func foo(foo: Int..., bar: Int) {
}

This issue appears if the first argument of the first function is an array of any type and the first argument of the second function is a variadic argument of the same type.

The second argument is required on both methods for the issue to appear and the type of the second argument must be the same on both methods, but it does not need to match the type of the first argument.

Initializers of structs and classes are also affected.

The swift compiler produces the following output when called with the -v flag:

Apple Swift version 3.1 (swiftlang-802.0.36.2 clang-802.0.35)
Target: x86_64-apple-macosx10.9
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file bug.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name bug -o /var/folders/_z/r4w3qsxd51z_2r9ww94k5z6w0000gn/T/bug-ee7056.o
0  swift                    0x00000001117527a7 PrintStackTraceSignalHandler(void*) + 39
1  swift                    0x0000000111751d36 SignalHandler(int) + 662
2  libsystem_platform.dylib 0x00007fff96627bba _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 1771930720
4  swift                    0x000000010f0a6287 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*)::$_1::operator()(swift::SILFunction*) const + 1191
5  swift                    0x000000010f0a5102 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 642
6  swift                    0x000000010f0b3a81 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 657
7  swift                    0x000000010f0b2b3b swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*, unsigned int) + 1483
8  swift                    0x000000010f0b4719 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*, llvm::Optional<unsigned int>, bool, bool) + 1593
9  swift                    0x000000010e9d93f2 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 45842
10 swift                    0x000000010e9893c2 main + 11298
11 libdyld.dylib            0x00007fff9641a255 start + 1
Stack dump:
0.  Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file bug.swift -target x86_64-apple-macosx10.9 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk -color-diagnostics -module-name bug -o /var/folders/_z/r4w3qsxd51z_2r9ww94k5z6w0000gn/T/bug-ee7056.o 
1.  While emitting SIL for 'foo' at bug.swift:3:1
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
@swift-ci
Copy link
Collaborator Author

Comment by Pawel Szot (JIRA)

It seems that mangled name is the same for both functions.

@swift-ci
Copy link
Collaborator Author

Comment by Pawel Szot (JIRA)

I think proper fix requires solving SR-3734 first. As a temporary workaround we could maybe add "invalid redeclaration" style warning, so at least it doesn't crash.

@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
This issue was closed.
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 SILGen Area → compiler: The SIL generation stage
Projects
None yet
Development

No branches or pull requests

2 participants