Skip to content

Incorrect argument evaluation order with opened existential passed inout vs. default argument #65091

@kishikawakatsumi

Description

@kishikawakatsumi

Description

The Swift compiler is crashing with a segmentation fault when attempting to compile the following code:

var output: TextOutputStream = "" print("", to: &output)

See https://swiftfiddle.com/alu6jt5ltretvk2nwlxetcldzm

Steps to reproduce

  1. Create a new Swift file containing the following code:
// test.swift var output: TextOutputStream = "" print("", to: &output)
  1. Compile the Swift file using the Swift compiler.
$ swiftc test.swift
Actual result
error: compile command failed due to signal 11 (use -v to see invocation) Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace. Stack dump: 0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file test.swift -target arm64-apple-macosx13.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.3.sdk -color-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name test -disable-clang-spi -target-sdk-version 13.3 -target-sdk-name macosx13.3 -o /var/folders/lv/3lh_qlh52mnfr6mktw83hb0w0000gn/T/TemporaryDirectory.qtp9Ha/test-1.o 1.	Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) 2.	Compiling with the current language version 3.	While evaluating request IRGenRequest(IR Generation for file "test.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 0x00000001097df300 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56 1 swift-frontend 0x00000001097de2e4 llvm::sys::RunSignalHandlers() + 112 2 swift-frontend 0x00000001097df910 SignalHandler(int) + 344 3 libsystem_platform.dylib 0x000000019226ea84 _sigtramp + 56 4 swift-frontend 0x0000000104a2e748 swift::irgen::emitArchetypeTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::irgen::DynamicMetadataRequest) + 384 5 swift-frontend 0x0000000104c7f754 emitDirectTypeMetadataRef(swift::irgen::IRGenFunction&, swift::CanType, swift::irgen::DynamicMetadataRequest) + 252 6 swift-frontend 0x0000000104c7ef94 swift::irgen::IRGenFunction::emitTypeMetadataRef(swift::CanType, swift::irgen::DynamicMetadataRequest) + 292 7 swift-frontend 0x0000000104b8258c swift::irgen::emitGenericRequirementFromSubstitutions(swift::irgen::IRGenFunction&, swift::GenericRequirement, swift::SubstitutionMap, swift::irgen::DynamicMetadataRequest) + 260 8 swift-frontend 0x0000000104b88008 void llvm::function_ref<void (swift::GenericRequirement)>::callback_fn<(anonymous namespace)::EmitPolymorphicArguments::emit(swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&)::$_22>(long, swift::GenericRequirement) + 68 9 swift-frontend 0x0000000104b88124 void llvm::function_ref<void (swift::GenericRequirement)>::callback_fn<(anonymous namespace)::PolymorphicConvention::enumerateUnfulfilledRequirements(llvm::function_ref<void (swift::GenericRequirement)> const&)::$_12>(long, swift::GenericRequirement) + 200 10 swift-frontend 0x0000000104b88544 void llvm::function_ref<void (swift::GenericTypeParamType*, bool)>::callback_fn<swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&)::$_0>(long, swift::GenericTypeParamType*, bool) + 44 11 swift-frontend 0x0000000105e084bc swift::GenericSignatureImpl::forEachParam(llvm::function_ref<void (swift::GenericTypeParamType*, bool)>) const + 756 12 swift-frontend 0x0000000104b7a8c4 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::GenericRequirement)> const&) + 1044 13 swift-frontend 0x0000000104b81b7c swift::irgen::emitPolymorphicArguments(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::SILFunctionType>, swift::SubstitutionMap, swift::irgen::WitnessMetadata*, swift::irgen::Explosion&) + 336 14 swift-frontend 0x0000000104c4ab64 (anonymous namespace)::IRGenSILFunction::visitFullApplySite(swift::FullApplySite) + 4264 15 swift-frontend 0x0000000104c24534 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 2740 16 swift-frontend 0x0000000104c21ffc swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 10696 17 swift-frontend 0x0000000104aac6e8 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&) + 1704 18 swift-frontend 0x0000000104bd664c swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 10976 19 swift-frontend 0x0000000104c1f368 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188 20 swift-frontend 0x0000000104be7ca0 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 832 21 swift-frontend 0x0000000104bd99b0 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 22 swift-frontend 0x00000001046d2f30 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >) + 228 23 swift-frontend 0x00000001046cd7a0 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*) + 1684 24 swift-frontend 0x00000001046d0520 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1856 25 swift-frontend 0x00000001046ce944 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4308 26 swift-frontend 0x000000010469368c swift::mainEntry(int, char const**) + 4116 27 dyld 0x0000000191ee7f28 start + 2236 

Expected behavior

The Swift compiler should compile the code without crashing.

Environment

  • Swift compiler version info
swift-driver version: 1.75.2 Apple Swift version 5.8 (swiftlang-5.8.0.124.2 clang-1403.0.22.11.100) Target: arm64-apple-macosx13.0 
  • Xcode version info
Xcode 14.3 Build version 14E222b 

Additional context

The compiler will not crash if the some keyword is added to the type annotation as follows

var output: some TextOutputStream = "" print("", to: &output)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.default argumentsFeature: default arguments for value parametersimplicit existential openingFeature → existentials: implicit opening of existentials when passed to parameters of generic typeinoutFeature → types: `inout` types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions