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-10062] Providing default value for inout parameter leads to compiler crash #52464

Closed
swift-ci opened this issue Mar 8, 2019 · 5 comments
Closed
Assignees
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 default arguments Feature: default arguments for value parameters function parameters Feature → declarations: function parameters inout Feature → types: `inout` types regression SILGen Area → compiler: The SIL generation stage swift 5.0 types Feature: types

Comments

@swift-ci
Copy link
Collaborator

swift-ci commented Mar 8, 2019

Previous ID SR-10062
Radar rdar://problem/48703420
Original Reporter palle (JIRA User)
Type Bug
Status Closed
Resolution Done
Environment

swift --version:

Apple Swift version 5.0 (swiftlang-1001.0.69 clang-1001.0.45.2)
Target: x86_64-apple-darwin18.2.0

Xcode Version 10.2 beta 4 (10P107d)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, 5.0Regression, CompilerCrash
Assignee @theblixguy
Priority Medium

md5: d348d3279200779d6fecde1effa5849a

is duplicated by:

  • SR-10911 SIGSEGV for missing optional inout parameter

Issue Description:

If a default value is provided for an inout parameter, the compiler crashes when the function is called with no value provided.

The crash can be reproduced with the following example:

func foo(x: inout Int = 0) {}
foo()

The code should probably give a syntax error, as an immutable value is passed as an inout parameter.

The following crash dump has been observed when compiling the above example with swiftc

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-darwin18.2.0 -enable-objc-interop -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.14.sdk -color-diagnostics -module-name Test -o /var/folders/05/3xrysdd95n93dv9hkw5k2lqm0000gn/T/Test-5b05a7.o 
0  swift                    0x000000010c1fbeb3 PrintStackTraceSignalHandler(void*) + 51
1  swift                    0x000000010c1fb68c SignalHandler(int) + 348
2  libsystem_platform.dylib 0x00007fff680fbb3d _sigtramp + 29
3  swift                    0x0000000108ba2a5d void std::__1::vector<swift::Lowering::ManagedValue, std::__1::allocator<swift::Lowering::ManagedValue> >::__push_back_slow_path<swift::Lowering::ManagedValue const&>(swift::Lowering::ManagedValue const&) + 157
4  swift                    0x0000000108bbe043 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, swift::SubstitutionMap, llvm::ArrayRef<swift::Lowering::ManagedValue>, swift::Lowering::CalleeTypeInfo const&, swift::Lowering::ApplyOptions, swift::Lowering::SGFContext) + 5971
5  swift                    0x0000000108bc22d0 emitDelayedArguments(swift::Lowering::SILGenFunction&, llvm::MutableArrayRef<(anonymous namespace)::DelayedArgument>, llvm::MutableArrayRef<llvm::SmallVector<swift::Lowering::ManagedValue, 4u> >) + 1936
6  swift                    0x0000000108bcfd37 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::CanTypeWrapper<swift::FunctionType>&, swift::Lowering::AbstractionPattern&, swift::CanTypeWrapper<swift::SILFunctionType>, llvm::Optional<swift::ForeignErrorConvention> const&, swift::ImportAsMemberStatus, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::Optional<swift::SILLocation>&, swift::CanTypeWrapper<swift::FunctionType>&) + 1607
7  swift                    0x0000000108bcd6a8 (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 2792
8  swift                    0x0000000108bc97cb swift::Lowering::SILGenFunction::emitApplyExpr(swift::Expr*, swift::Lowering::SGFContext) + 2331
9  swift                    0x0000000108c3cb3b swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 811
10 swift                    0x0000000108bb9d51 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 1041
11 swift                    0x0000000108bb8b66 swift::Lowering::SILGenModule::emitSourceFile(swift::SourceFile*) + 1206
12 swift                    0x0000000108bba97c swift::SILModule::constructSIL(swift::ModuleDecl*, swift::SILOptions&, swift::FileUnit*) + 1228
13 swift                    0x000000010805bb0a performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 30106
14 swift                    0x0000000108050c9e swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 6862
15 swift                    0x0000000107feedae main + 1246
16 libdyld.dylib            0x00007fff67f10ed9 start + 1
17 libdyld.dylib            0x000000000000000f start + 2551116087
<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)
@theblixguy
Copy link
Collaborator

PR: #23187

@theblixguy
Copy link
Collaborator

Fixed on master.

@AnnaZaks: Is the swift-5.0 branch still accepting PRs? If yes, then I can cherry pick this over otherwise this fix will ship with 5.1 instead.

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Mar 12, 2019

I think it's too late for swift-5.0 branch. Sorry!

@theblixguy
Copy link
Collaborator

No problem!

@AnnaZaks
Copy link
Mannequin

AnnaZaks mannequin commented Aug 9, 2019

palle (JIRA User), Could you verify if the problem is fixed and if so move the JIRA to "Closed"?

Thanks!
Anna

@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
@AnthonyLatsis AnthonyLatsis added default arguments Feature: default arguments for value parameters function parameters Feature → declarations: function parameters inout Feature → types: `inout` types types Feature: types SILGen Area → compiler: The SIL generation stage labels Nov 8, 2023
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 default arguments Feature: default arguments for value parameters function parameters Feature → declarations: function parameters inout Feature → types: `inout` types regression SILGen Area → compiler: The SIL generation stage swift 5.0 types Feature: types
Projects
None yet
Development

No branches or pull requests

3 participants