Assertion failed: LastArgWritten == 0 when building on windows

When building on windows, I get this error :

Assertion failed: LastArgWritten == 0, file S:\toolchain\swift\lib\IRGen\GenCall.cpp, line 1883

It is very similar to a previous thread I found :

I made sure I checked out the sources in the correct mode and on the correct branch.

Here is the the complete log. Any idea ?

@compnerd

FAILED: tools/swift/stdlib/public/core/WINDOWS/x86_64/Swift.obj
cmd.exe /C "cd /D S:\b\toolchain\tools\swift\stdlib\public\core && "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python37_64\python.exe" S:/toolchain/swift/utils/line-directive @S:/b/toolchain/tools/swift/stdlib/public/core/srmzE.txt -- S:/b/toolchain/./bin/swiftc -c -target x86_64-unknown-windows-msvc -resource-dir S:/b/toolchain/./lib/swift -Onone -g -D INTERNAL_CHECKS_ENABLED -module-cache-path S:/b/toolchain/./module-cache -no-link-objc-runtime -enable-library-evolution -Xfrontend -enable-ownership-stripping-after-serialization -Xfrontend -enforce-exclusivity=unchecked -nostdimport -parse-stdlib -module-name Swift -Xfrontend -group-info-path -Xfrontend S:/toolchain/swift/stdlib/public/core/GroupInfo.json -swift-version 5 -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements -warn-swift3-objc-inference-complete -Xfrontend -verify-syntax-tree -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -Xcc -DswiftCore_EXPORTS -warn-implicit-overrides -D_WINDLL -DswiftCore_EXPORTS -Xcc -isystem -Xcc "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\/include" -Xcc -isystem -Xcc "C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/ucrt" -Xcc -isystem -Xcc "C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/shared" -Xcc -isystem -Xcc "C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/um" -libc MultiThreadedDebugDLL -module-link-name swiftCore -force-single-frontend-invocation -parse-as-library -I S:/b/toolchain/./lib/swift/windows/x86_64 -o S:/b/toolchain/tools/swift/stdlib/public/core/WINDOWS/x86_64/Swift.obj @S:/b/toolchain/tools/swift/stdlib/public/core/srmzE.txt"
Assertion failed: LastArgWritten == 0, file S:\toolchain\swift\lib\IRGen\GenCall.cpp, line 1883

Stack dump:

0.      Program arguments: S:\b\toolchain\bin\swiftc.exe -frontend -c -filelist C:\Users\PDESCH~1\AppData\Local\Temp\sources-0efb94 -supplementary-output-file-map C:\Users\PDESCH~1\AppData\Local\Temp\supplementaryOutputs-26c7df -disable-objc-attr-requires-foundation-module -target x86_64-unknown-windows-msvc -disable-objc-interop -I S:/b/toolchain/./lib/swift/windows/x86_64 -warn-swift3-objc-inference-complete -warn-implicit-overrides -enable-library-evolution -g -module-cache-path S:/b/toolchain/./module-cache -module-link-name swiftCore -nostdimport -parse-stdlib -resource-dir S:/b/toolchain/./lib/swift -swift-version 5 -Onone -D INTERNAL_CHECKS_ENABLED -D _WINDLL -D swiftCore_EXPORTS -enable-ownership-stripping-after-serialization -enforce-exclusivity=unchecked -group-info-path S:/toolchain/swift/stdlib/public/core/GroupInfo.json -verify-syntax-tree -enable-anonymous-context-mangled-names -Xllvm -sil-inline-generics -Xllvm -sil-partial-specialization -Xcc -DswiftCore_EXPORTS -Xcc -isystem -Xcc C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.25.28610\/include -Xcc -isystem -Xcc C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/ucrt -Xcc -isystem -Xcc C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/shared -Xcc -isystem -Xcc C:\Program Files (x86)\Windows Kits\10\/Include/10.0.18362.0/um -autolink-library oldnames -autolink-library msvcrtd -Xcc -D_MT -Xcc -D_DLL -parse-as-library -module-name Swift -o S:/b/toolchain/tools/swift/stdlib/public/core/WINDOWS/x86_64/Swift.obj -runtime-compatibility-version none -disable-autolinking-runtime-compatibility-dynamic-replacements

1.      compnerd.org Swift version 5.3-dev (LLVM de1720dcc2, Swift d20c7276c0)

2.      Contents of C:\Users\PDESCH~1\AppData\Local\Temp\sources-0efb94:

---

S:/toolchain/swift/stdlib/public/core/Algorithm.swift

S:/toolchain/swift/stdlib/public/core/ArrayBody.swift

S:/toolchain/swift/stdlib/public/core/ArrayBuffer.swift

S:/toolchain/swift/stdlib/public/core/ArrayBufferProtocol.swift

S:/toolchain/swift/stdlib/public/core/ArrayCast.swift

S:/toolchain/swift/stdlib/public/core/Array.swift

S:/toolchain/swift/stdlib/public/core/ArrayShared.swift

S:/toolchain/swift/stdlib/public/core/ArraySlice.swift

S:/toolchain/swift/stdlib/public/core/ArrayType.swift

S:/toolchain/swift/stdlib/public/core/ASCII.swift

S:/toolchain/swift/stdlib/public/core/Assert.swift

S:/toolchain/swift/stdlib/public/core/AssertCommon.swift

S:/toolchain/swift/stdlib/public/core/BidirectionalCollection.swift

S:/toolchain/swift/stdlib/public/core/Bitset.swift

S:/toolchain/swift/stdlib/public/core/Bool.swift

S:/toolchain/swift/stdlib/public/core/BridgeObjectiveC.swift

S:/toolchain/swift/stdlib/public/core/BridgeStorage.swift

S:/toolchain/swift/stdlib/public/core/BridgingBuffer.swift

S:/toolchain/swift/stdlib/public/core/Builtin.swift

S:/toolchain/swift/stdlib/public/core/BuiltinMath.swift

S:/toolchain/swift/stdlib/public/core/Character.swift

S:/toolchain/swift/stdlib/public/core/CocoaArray.swift

S:/toolchain/swift/stdlib/public/core/Codable.swift

S:/toolchain/swift/stdlib/public/core/Collection.swift

S:/toolchain/swift/stdlib/public/core/CollectionAlgorithms.swift

S:/toolchain/swift/stdlib/public/core/Comparable.swift

S:/toolchain/swift/stdlib/public/core/CompilerProtocols.swift

S:/toolchain/swift/stdlib/public/core/ContiguousArray.swift

S:/toolchain/swift/stdlib/public/core/ContiguouslyStored.swift

S:/toolchain/swift/stdlib/public/core/ClosedRange.swift

S:/toolchain/swift/stdlib/public/core/ContiguousArrayBuffer.swift

S:/toolchain/swift/stdlib/public/core/CString.swift

S:/toolchain/swift/stdlib/public/core/CTypes.swift

S:/toolchain/swift/stdlib/public/core/DebuggerSupport.swift

S:/toolchain/swift/stdlib/public/core/Dictionary.swift

S:/toolchain/swift/stdlib/public/core/DictionaryBridging.swift

S:/toolchain/swift/stdlib/public/core/DictionaryBuilder.swift

S:/toolchain/swift/stdlib/public/core/DictionaryCasting.swift

S:/toolchain/swift/stdlib/public/core/DictionaryStorage.swift

S:/toolchain/swift/stdlib/public/core/DictionaryVariant.swift

S:/toolchain/swift/stdlib/public/core/DropWhile.swift

S:/toolchain/swift/stdlib/public/core/Dump.swift

S:/toolchain/swift/stdlib/public/core/EmptyCollection.swift

S:/toolchain/swift/stdlib/public/core/Equatable.swift

S:/toolchain/swift/stdlib/public/core/ErrorType.swift

S:/toolchain/swift/stdlib/public/core/ExistentialCollection.swift

S:/toolchain/swift/stdlib/public/core/Filter.swift

S:/toolchain/swift/stdlib/public/core/FixedArray.swift

S:/toolchain/swift/stdlib/public/core/FlatMap.swift

S:/toolchain/swift/stdlib/public/core/Flatten.swift

S:/toolchain/swift/stdlib/public/core/FloatingPoint.swift

S:/toolchain/swift/stdlib/public/core/Hashable.swift

S:/toolchain/swift/stdlib/public/core/AnyHashable.swift

S:/toolchain/swift/stdlib/public/core/Hasher.swift

S:/toolchain/swift/stdlib/public/core/Hashing.swift

S:/toolchain/swift/stdlib/public/core/HashTable.swift

S:/toolchain/swift/stdlib/public/core/ICU.swift

S:/toolchain/swift/stdlib/public/core/Identifiable.swift

S:/toolchain/swift/stdlib/public/core/Indices.swift

S:/toolchain/swift/stdlib/public/core/InputStream.swift

S:/toolchain/swift/stdlib/public/core/IntegerParsing.swift

S:/toolchain/swift/stdlib/public/core/Integers.swift

S:/toolchain/swift/stdlib/public/core/Join.swift

S:/toolchain/swift/stdlib/public/core/KeyPath.swift

S:/toolchain/swift/stdlib/public/core/KeyValuePairs.swift

S:/toolchain/swift/stdlib/public/core/LazyCollection.swift

S:/toolchain/swift/stdlib/public/core/LazySequence.swift

S:/toolchain/swift/stdlib/public/core/LegacyABI.swift

S:/toolchain/swift/stdlib/public/core/LifetimeManager.swift

S:/toolchain/swift/stdlib/public/core/ManagedBuffer.swift

S:/toolchain/swift/stdlib/public/core/Map.swift

S:/toolchain/swift/stdlib/public/core/MemoryLayout.swift

S:/toolchain/swift/stdlib/public/core/UnicodeScalar.swift

S:/toolchain/swift/stdlib/public/core/Mirrors.swift

S:/toolchain/swift/stdlib/public/core/Misc.swift

S:/toolchain/swift/stdlib/public/core/MutableCollection.swift

S:/toolchain/swift/stdlib/public/core/NativeDictionary.swift

S:/toolchain/swift/stdlib/public/core/NativeSet.swift

S:/toolchain/swift/stdlib/public/core/NewtypeWrapper.swift

S:/toolchain/swift/stdlib/public/core/ObjectIdentifier.swift

S:/toolchain/swift/stdlib/public/core/Optional.swift

S:/toolchain/swift/stdlib/public/core/OptionSet.swift

S:/toolchain/swift/stdlib/public/core/OutputStream.swift

S:/toolchain/swift/stdlib/public/core/Pointer.swift

S:/toolchain/swift/stdlib/public/core/Policy.swift

S:/toolchain/swift/stdlib/public/core/PrefixWhile.swift

S:/toolchain/swift/stdlib/public/core/Print.swift

S:/toolchain/swift/stdlib/public/core/PtrAuth.swift

S:/toolchain/swift/stdlib/public/core/Random.swift

S:/toolchain/swift/stdlib/public/core/RandomAccessCollection.swift

S:/toolchain/swift/stdlib/public/core/Range.swift

S:/toolchain/swift/stdlib/public/core/RangeReplaceableCollection.swift

S:/toolchain/swift/stdlib/public/core/ReflectionMirror.swift

S:/toolchain/swift/stdlib/public/core/Repeat.swift

S:/toolchain/swift/stdlib/public/core/REPL.swift

S:/toolchain/swift/stdlib/public/core/Result.swift

S:/toolchain/swift/stdlib/public/core/Reverse.swift

S:/toolchain/swift/stdlib/public/core/Runtime.swift

S:/toolchain/swift/stdlib/public/core/RuntimeFunctionCounters.swift

S:/toolchain/swift/stdlib/public/core/SipHash.swift

S:/toolchain/swift/stdlib/public/core/Sequence.swift

S:/toolchain/swift/stdlib/public/core/SequenceAlgorithms.swift

S:/toolchain/swift/stdlib/public/core/Set.swift

S:/toolchain/swift/stdlib/public/core/SetAlgebra.swift

S:/toolchain/swift/stdlib/public/core/SetAnyHashableExtensions.swift

S:/toolchain/swift/stdlib/public/core/SetBridging.swift

S:/toolchain/swift/stdlib/public/core/SetBuilder.swift

S:/toolchain/swift/stdlib/public/core/SetCasting.swift

S:/toolchain/swift/stdlib/public/core/SetStorage.swift

S:/toolchain/swift/stdlib/public/core/SetVariant.swift

S:/toolchain/swift/stdlib/public/core/ShadowProtocols.swift

S:/toolchain/swift/stdlib/public/core/Shims.swift

S:/toolchain/swift/stdlib/public/core/Slice.swift

S:/toolchain/swift/stdlib/public/core/SmallString.swift

S:/toolchain/swift/stdlib/public/core/Sort.swift

S:/toolchain/swift/stdlib/public/core/StaticString.swift

S:/toolchain/swift/stdlib/public/core/Stride.swift

S:/toolchain/swift/stdlib/public/core/StringHashable.swift

S:/toolchain/swift/stdlib/public/core/String.swift

S:/toolchain/swift/stdlib/public/core/StringBreadcrumbs.swift

S:/toolchain/swift/stdlib/public/core/StringBridge.swift

S:/toolchain/swift/stdlib/public/core/StringCharacterView.swift

S:/toolchain/swift/stdlib/public/core/StringComparable.swift

S:/toolchain/swift/stdlib/public/core/StringComparison.swift

S:/toolchain/swift/stdlib/public/core/StringCreate.swift

S:/toolchain/swift/stdlib/public/core/StringGuts.swift

S:/toolchain/swift/stdlib/public/core/StringGutsSlice.swift

S:/toolchain/swift/stdlib/public/core/StringGutsRangeReplaceable.swift

S:/toolchain/swift/stdlib/public/core/StringObject.swift

S:/toolchain/swift/stdlib/public/core/StringProtocol.swift

S:/toolchain/swift/stdlib/public/core/StringIndex.swift

S:/toolchain/swift/stdlib/public/core/StringIndexConversions.swift

S:/toolchain/swift/stdlib/public/core/StringInterpolation.swift

S:/toolchain/swift/stdlib/public/core/StringLegacy.swift

S:/toolchain/swift/stdlib/public/core/StringNormalization.swift

S:/toolchain/swift/stdlib/public/core/StringRangeReplaceableCollection.swift

S:/toolchain/swift/stdlib/public/core/StringStorage.swift

S:/toolchain/swift/stdlib/public/core/StringStorageBridge.swift

S:/toolchain/swift/stdlib/public/core/StringSwitch.swift

S:/toolchain/swift/stdlib/public/core/StringTesting.swift

S:/toolchain/swift/stdlib/public/core/StringUnicodeScalarView.swift

S:/toolchain/swift/stdlib/public/core/StringUTF16View.swift

S:/toolchain/swift/stdlib/public/core/StringUTF8View.swift

S:/toolchain/swift/stdlib/public/core/StringUTF8Validation.swift

S:/toolchain/swift/stdlib/public/core/Substring.swift

S:/toolchain/swift/stdlib/public/core/SwiftNativeNSArray.swift

S:/toolchain/swift/stdlib/public/core/ThreadLocalStorage.swift

S:/toolchain/swift/stdlib/public/core/UIntBuffer.swift

S:/toolchain/swift/stdlib/public/core/UnavailableStringAPIs.swift

S:/toolchain/swift/stdlib/public/core/UnicodeEncoding.swift

S:/toolchain/swift/stdlib/public/core/UnicodeHelpers.swift

S:/toolchain/swift/stdlib/public/core/UnicodeParser.swift

S:/toolchain/swift/stdlib/public/core/UnicodeScalarProperties.swift

S:/toolchain/swift/stdlib/public/core/CharacterProperties.swift

S:/toolchain/swift/stdlib/public/core/Unmanaged.swift

S:/toolchain/swift/stdlib/public/core/UnmanagedOpaqueString.swift

S:/toolchain/swift/stdlib/public/core/UnmanagedString.swift

S:/toolchain/swift/stdlib/public/core/UnsafePointer.swift

S:/toolchain/swift/stdlib/public/core/UnsafeRawPointer.swift

S:/toolchain/swift/stdlib/public/core/UTFEncoding.swift

S:/toolchain/swift/stdlib/public/core/UTF8.swift

S:/toolchain/swift/stdlib/public/core/UTF16.swift

S:/toolchain/swift/stdlib/public/core/UTF32.swift

S:/toolchain/swift/stdlib/public/core/Unicode.swift

S:/toolchain/swift/stdlib/public/core/StringGraphemeBreaking.swift

S:/toolchain/swift/stdlib/public/core/ValidUTF8Buffer.swift

S:/toolchain/swift/stdlib/public/core/WriteBackMutableSlice.swift

S:/toolchain/swift/stdlib/public/core/MigrationSupport.swift

S:/toolchain/swift/stdlib/public/core/Availability.swift

S:/toolchain/swift/stdlib/public/core/CollectionDifference.swift

S:/toolchain/swift/stdlib/public/core/CollectionOfOne.swift

S:/toolchain/swift/stdlib/public/core/DiscontiguousSlice.swift

S:/toolchain/swift/stdlib/public/core/Diffing.swift

S:/toolchain/swift/stdlib/public/core/Mirror.swift

S:/toolchain/swift/stdlib/public/core/PlaygroundDisplay.swift

S:/toolchain/swift/stdlib/public/core/CommandLine.swift

S:/toolchain/swift/stdlib/public/core/RangeSet.swift

S:/toolchain/swift/stdlib/public/core/RangeSetStorage.swift

S:/toolchain/swift/stdlib/public/core/SliceBuffer.swift

S:/toolchain/swift/stdlib/public/core/SIMDVector.swift

S:/toolchain/swift/stdlib/public/core/UnfoldSequence.swift

S:/toolchain/swift/stdlib/public/core/VarArgs.swift

S:/toolchain/swift/stdlib/public/core/Zip.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/AtomicInt.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/FloatingPointParsing.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/FloatingPointTypes.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/IntegerTypes.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/UnsafeBufferPointer.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/UnsafeRawBufferPointer.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/SIMDVectorTypes.swift

S:/b/toolchain/tools/swift/stdlib/public/core/8/Tuple.swift

---

3.      While evaluating request IRGenWholeModuleRequest(IR Generation for module Swift)

4.      While emitting IR SIL function "@$ss3minyxx_xtSLRzlF".

 for 'min(_:_:)' (at S:/toolchain/swift/stdlib/public/core/Algorithm.swift:20:8)

 #0 0x00007ff65c94fa5c HandleAbort S:\toolchain\llvm\lib\Support\Windows\Signals.inc:408:0

 #1 0x00007ff90ecec3e1 (C:\Windows\SYSTEM32\ucrtbased.dll+0x6c3e1)

 #2 0x00007ff90ecee039 (C:\Windows\SYSTEM32\ucrtbased.dll+0x6e039)

 #3 0x00007ff90ecf386f (C:\Windows\SYSTEM32\ucrtbased.dll+0x7386f)

 #4 0x00007ff90ecf1841 (C:\Windows\SYSTEM32\ucrtbased.dll+0x71841)

 #5 0x00007ff90ecf41cf (C:\Windows\SYSTEM32\ucrtbased.dll+0x741cf)

 #6 0x00007ff65489dd06 swift::irgen::CallEmission::~CallEmission(void) S:\toolchain\swift\lib\IRGen\GenCall.cpp:1883:0

 #7 0x00007ff6549a654c getCallEmissionForLoweredValue S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:2320:0

 #8 0x00007ff6549c1530 `anonymous namespace'::IRGenSILFunction::visitFullApplySite S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:2406:0

 #9 0x00007ff6549bac39 `anonymous namespace'::IRGenSILFunction::visitApplyInst S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:2346:0

#10 0x00007ff6549b8a3a swift::SILInstructionVisitor<`anonymous namespace'::IRGenSILFunction,void>::visit S:\toolchain\swift\include\swift\SIL\SILNodes.def:613:0

#11 0x00007ff6549c908c `anonymous namespace'::IRGenSILFunction::visitSILBasicBlock S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:1817:0

#12 0x00007ff6549a0fca `anonymous namespace'::IRGenSILFunction::emitSILFunction S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:1692:0

#13 0x00007ff6549a098f swift::irgen::IRGenModule::emitSILFunction(class swift::SILFunction *) S:\toolchain\swift\lib\IRGen\IRGenSIL.cpp:1598:0

#14 0x00007ff6546405bb swift::irgen::IRGenerator::emitGlobalTopLevel(class llvm::StringSet<class llvm::MallocAllocator> *) S:\toolchain\swift\lib\IRGen\GenDecl.cpp:1071:0

#15 0x00007ff6545d35d7 performIRGeneration S:\toolchain\swift\lib\IRGen\IRGen.cpp:989:0

#16 0x00007ff6545cd33e swift::IRGenWholeModuleRequest::evaluate(class swift::Evaluator &, struct swift::IRGenDescriptor) const S:\toolchain\swift\lib\IRGen\IRGen.cpp:1395:0

#17 0x00007ff6545de610 swift::SimpleRequest<class swift::IRGenWholeModuleRequest, (struct swift::IRGenDescriptor), 1>::callDerived<0>(class swift::Evaluator &, struct std::integer_sequence<unsigned __int64, 0>) const S:\toolchain\swift\include\swift\AST\SimpleRequest.h:266:0

#18 0x00007ff6545de4b2 swift::SimpleRequest<class swift::IRGenWholeModuleRequest, (struct swift::IRGenDescriptor), 1>::evaluateRequest(class swift::IRGenWholeModuleRequest const &, class swift::Evaluator &) S:\toolchain\swift\include\swift\AST\SimpleRequest.h:289:0

#19 0x00007ff6545bf082 swift::Evaluator::getResultUncached<class swift::IRGenWholeModuleRequest>(class swift::IRGenWholeModuleRequest const &) S:\toolchain\swift\include\swift\AST\Evaluator.h:410:0

#20 0x00007ff6545ba7b0 swift::Evaluator::operator()<class swift::IRGenWholeModuleRequest, 0>(class swift::IRGenWholeModuleRequest const &) S:\toolchain\swift\include\swift\AST\Evaluator.h:323:0

#21 0x00007ff6545d3f4d swift::performIRGeneration(class swift::IRGenOptions const &, class swift::ModuleDecl *, class std::unique_ptr<class swift::SILModule, struct std::default_delete<class swift::SILModule>>, class llvm::StringRef, class swift::PrimarySpecificPaths const &, class llvm::ArrayRef<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>, class llvm::GlobalVariable **, class llvm::StringSet<class llvm::MallocAllocator> *) S:\toolchain\swift\lib\IRGen\IRGen.cpp:1377:0

#22 0x00007ff6540bd818 generateIR S:\toolchain\swift\lib\FrontendTool\FrontendTool.cpp:1375:0

#23 0x00007ff6540c3b55 performCompileStepsPostSILGen S:\toolchain\swift\lib\FrontendTool\FrontendTool.cpp:1695:0

#24 0x00007ff6540c40e0 performCompileStepsPostSema S:\toolchain\swift\lib\FrontendTool\FrontendTool.cpp:1101:0

#25 0x00007ff6540c31fa performCompile S:\toolchain\swift\lib\FrontendTool\FrontendTool.cpp:1341:0

#26 0x00007ff6540c527d swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\toolchain\swift\lib\FrontendTool\FrontendTool.cpp:2215:0

#27 0x00007ff653f59a43 run_driver S:\toolchain\swift\tools\driver\driver.cpp:134:0

#28 0x00007ff653f5b934 main S:\toolchain\swift\tools\driver\driver.cpp:283:0

#29 0x00007ff65cc0abe9 invoke_main d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:79:0

#30 0x00007ff65cc0ab3e __scrt_common_main_seh d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0

#31 0x00007ff65cc0a9fe __scrt_common_main d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:331:0

#32 0x00007ff65cc0ac59 mainCRTStartup d:\agent\_work\4\s\src\vctools\crt\vcstartup\src\startup\exe_main.cpp:17:0

#33 0x00007ff92f857bd4 (C:\Windows\System32\KERNEL32.DLL+0x17bd4)

#34 0x00007ff93160ce51 (C:\Windows\SYSTEM32\ntdll.dll+0x6ce51)

<unknown>:0: error: compile command failed due to signal -2147483645 (use -v to see invocation)
[5891/5938] Generating S:/b/toolchain/./lib/swift/windows/x86_64/Swift.swiftmodule
ninja: build stopped: subcommand failed.

No, nothing really stands out as why that would suddenly start failing. At least you have an assert, so its telling you something went wrong in generating the code for min(_:_:).

Yesterday, as a quick test, I tried to change the implementation of the min(::) function (line 20) to see if the problem was for any function or just this particular implementation. So, I went from :

return y < x ? y : x

to :

return y

There is no logic by the way, it was just to simplify the expression. Anyway, after a recompile,
that function passed but the error showed up on the next function (line 38).

I will have to dig a little deeper to understant this one.

But my guess is that this problem has been present for a while but, it dit not show up on release build or when assertions are turned off (which seems to be the case in the azure pipeline).

The Azure Pipelines are built release, but assertions are enabled.

I think that this may be some UB in the compiler that is getting away from us. I assume that you are building in the debug configuration since I just realized that the documentation somehow missed the -D CMAKE_BUILD_TYPE=Release. I'll be updating the documentation for that.

I can confirm that the -D CMAKE_BUILD_TYPE=Release option solves the issue.

For a while, I tought the following line was the problem :

swift\lib\IRGen\GenCall.cpp:1580

#ifndef NDEBUG
  LastArgWritten = 0; // appease an assert
#endif

So, I tried commenting the #ifndef/#else for the Debug version but, that's not the issue.

Thats good and bad. I suppose that it would be good to figure out why the thing goes wrong, it's just insanely painful as debug mode compilation of the standard library is extremely slow.

Well, debugging is part of the journey. I see it as interesting challenge (however small).

Now that I know the release mode works, I am planning to compare debug vs. release mode :

  • compiler/linker options
  • logging LastArgWritten assigned values
  • ...

I suspect an optimisation flag which left a variable uninitialized or a symbol defined by a debug flag (e.g. /MTd defines _DEBUG and _MT) which could conditonnaly compile/not-compile some lines. We'll see.

By the way, thank you for your help on those issues, it's greatly appreciated. Especially knowing you are busy with so many other things.

I will keep you in touch when I find something.

It is indeed :slight_smile:

Hah, don't underestimate this, this is probably going to find some really subtle bug, but it should be loads of fun!

Happy to help! It's great to see more people get involved :smiley:

Thank you

I found something but, I don't know what to think about it since I'm no C++ expert.

I found that the behaviour changed in the return statement of function getCallEmissionForLoweredValue.

So I simplified the code to have a single C++ source file and tried to simplify which compiler option changed this behaviour. It appears that the /O2 option is the one at fault here (or, in this case, at right). To get the same behaviour as clang, we must use the /O2 or else, the compiled code show a different path (see below).

I forced the /O2 option in the debug build and, it solved the compilation of the standard library (Swift.obj).

Here is a simplified sample and its output depending on the compiler used and its options. Whether or not Constructor B should be invoked is beyond me (for now). I will have to read the C++ documentation.

I tough you might be interested.

#include <stdio.h>
#include <stdlib.h>

class CallEmission 
{
private:
    int Value;

public:
    CallEmission(int value)
        : Value(value)
    {
        printf("Constructor A\n");
    }

    CallEmission(CallEmission &&other);
};

CallEmission::CallEmission(CallEmission &&other)
    : Value(other.Value)
{
    printf("Constructor B\n");
}

static CallEmission getCallEmissionForLoweredValue()
{
    CallEmission callEmission(0);

    return callEmission;
}

int main()
{
    CallEmission callEmissionA(0);
    CallEmission callEmissionB = getCallEmissionForLoweredValue();

    return 0;
}

Using Microsoft C++ compiler (CL) with default options.

D:\> cl test.cpp /Fe:test 2> nul > nul && test

Constructor A
Constructor A
Constructor B

Using Microsoft C++ compiler (CL) with /O2 option

D:\> cl test.cpp /Fe:test /O2 2> nul > nul && test

Constructor A
Constructor A

Using clang either on Windows or Linux :

$ clang test.cpp -o test && ./test

Constructor A
Constructor A

They are generating an extra move which is fine. I think that the accounting is incorrect, and the moved type should not increment the value for the arguments written.

I am new to C++ and Swift so, I'm lost most of the time. But, during a long C++ compilation phase, I started thinking (maybe the only positive thing about long compilation time).

I've started thinking what the assertions meant in the destructor of CallEmission :

assert(LastArgWritten == 0);
assert(EmittedCall);

What I think it means is that the CallEmission must have written all its arguments and have emitted a call before its destruction. So, each CallEmission must emit or it will assert.

Now, if we do a copy of a CallEmission :

newEmission = originalEmission;

and it use the copy constructor :

CallEmission::CallEmission(CallEmission &&other)

Then, only the newEmission will be used to emit call and the originalEmission will be discarded.
If we assert the originalEmission in the destructor, its LastArgWritten and/or EmittedCall will
assert since the originalEmission have never and will never emit a call.

If we look at the copy constructor :

CallEmission::CallEmission(CallEmission &&other)
  : IGF(other.IGF),
    Args(std::move(other.Args)),
    CurCallee(std::move(other.CurCallee)),
    LastArgWritten(other.LastArgWritten),
    EmittedCall(other.EmittedCall) {
  // Prevent other's destructor from asserting.
  LastArgWritten = 0;
  EmittedCall = true;
}

According to the comment, I think it was the intent. Tell the originalEmission to act as if it emitted a call to prevent the destructor from asserting.

But, here is the problem, the implementation of the constructor prevent the assertion on the newEmission but not the originalEmission. So, when the originalEmission get destroyed, it will assert.

Since clang optimise this, it never use this constructor when copying a CallEmission so, it never really
have an originalEmission to discard and to assert.

I think the constructor should looks like this instead :

// Prevent other's destructor from asserting.
other.LastArgWritten = 0;
other.EmittedCall = true;

What do you think ?

The constructor is not the copy constructor, but the move constructor, which does not guarantee that the source is left alone. The source of call is left in some indeterminate state, so it's not clear what the assertions are testing for, especially in the destructor.

Since this bug never happens in normal condition, I would understand if you prefer to not touch it and put no more effort into this.

However, I think I found more bugs in the move constructor. Other than the previous one I mentionned, I also found that there were some unmoved fields (Temporaries, IsCoroutine) which are causing other assertions later on. I tested this new version and, it works :

diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp
index 86a0b91f9bd..5b299bd0ecc 100644
--- a/lib/IRGen/GenCall.cpp
+++ b/lib/IRGen/GenCall.cpp
@@ -1871,10 +1871,14 @@ CallEmission::CallEmission(CallEmission &&other)
     Args(std::move(other.Args)),
     CurCallee(std::move(other.CurCallee)),
     LastArgWritten(other.LastArgWritten),
-    EmittedCall(other.EmittedCall) {
+    EmittedCall(other.EmittedCall),
+    Temporaries(std::move(other.Temporaries)),
+    IsCoroutine(other.IsCoroutine) {
+
   // Prevent other's destructor from asserting.
-  LastArgWritten = 0;
-  EmittedCall = true;
+  other.LastArgWritten = 0;
+  other.EmittedCall = true;
+  other.Temporaries.clear();
 }

From a C++ perspective, I understand the source is not guaranteed to be left alone but, from a swift perspective, I highly doubt someone will continue using the source after a move intentionnaly. Why would someone want to emit the call twice ? And according to the comments, and I think it was the original assumption.

As for why the assertion existed in the first place, here's the comment for EmittedCall which may provides some tips :

/// Whether we've emitted the call for the current callee yet.  This
/// is just for debugging purposes --- e.g. the destructor asserts
/// that it's true --- but is otherwise derivable from
/// RemainingArgsForCallee, at least between calls.
bool EmittedCall;

Does my patch make sense ?

I think that in the case of a move constructor, other.EmittedCall should be false since it did not emit the call. The move constructor moves the state of the object to avoid the cost of a copy. The original object is left in an indeterminate state to be discarded. We should not be triggering any checks on the object as the entire state of the object has moved and the object does not have any state that it can validate.

That is what I normally do during move assignment and move construction. My normal inclination is to leave the moved variable in it's initial state, as if it had just been newly constructed, or in some null state that indicates it's not useful, in case someplace else I inadvertently try to reuse the moved variable. But, have to weigh that against performance.

Did this discussion go anywhere? I am running into the same issue when trying to build a debug version of Swift on Windows.

Patrick, would you want to submit a pull request with your suggested fix?

Saleem made a good point that other.EmittedCall should be false. But, at the same time, I don't see a good alternative without complicating the assertion logic in the destructor which would impact the performance for the debug version and also the release version.

In your case, I would suggest you to replace the move constructor with the code below.

If it works for you, you may do the pull request yourself. Let me know if it works.

lib/IRGen/GenCall.cpp:1886

CallEmission::CallEmission(CallEmission &&other)
  : IGF(other.IGF),
    Args(std::move(other.Args)),
    CurCallee(std::move(other.CurCallee)),
    LastArgWritten(other.LastArgWritten),
    EmittedCall(other.EmittedCall),
    Temporaries(std::move(other.Temporaries)),
    IsCoroutine(other.IsCoroutine) {
	
  // Prevent other's destructor from asserting.
  other.LastArgWritten = 0;
  other.EmittedCall = true;
  other.Temporaries.clear();
}