Skip to content

Cherrypick fixes for issue 74866 to release/5.10 #77277

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

Closed
wants to merge 10 commits into from

Conversation

hjyamauchi
Copy link
Contributor

@hjyamauchi hjyamauchi commented Oct 29, 2024

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

1 similar comment
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

1 similar comment
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hyp
Copy link
Contributor

hyp commented Oct 31, 2024

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

@swift-ci please test Windows Platform

@hjyamauchi
Copy link
Contributor Author

Hi @shahmishal I'd like to test this PR along with the associated swiftlang/llvm-project#9478. But the swift-ci directive

Please test with following PRs:
https://github.com/swiftlang/llvm-project/pull/9478

@swift-ci please test

doesn't seem to pick up the associated PR, as seen in the empty related PR list in the CI log line

Found related pull requests: []

The same CI directive worked on a similar PR on the release/6.0 CI here: #77261

Is this a bug? Is there a way to work around this? Thanks.

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@finagolfin
Copy link
Member

This branch has been abandoned for almost 5 months now, there have been no commits since June. Swift always abandons the previous release branch once a new release comes out, so no 5.10 commits will be taken now that 6.0 is out.

@compnerd, perhaps you should explain the Swift branching process to the BC team.

@hjyamauchi
Copy link
Contributor Author

hjyamauchi commented Nov 1, 2024

Here's the context: to get the win/arm64 compiler back to a working state, we'd need to fix (the win/arm64 codegen in) the bootstrap/pinned toolchain, that we use to build a newer toolchain (as in the swift compiler self-hosting, or the fact that swift compiler is partially written in swift) and we currently use the 5.10 toolchain to bootstrap the 6.0 and the main toolchain. For reference: #74866 (comment)

I'm not 100% sure if patching and using 5.10 as the bootstrap toolchain is strictly necessary, not just customary, and I think we probably can use a 6.0 build to bootstrap 6.0 and main, but to do that, we'd need to

  • disable SwiftCompilerSources for win/arm64 in 6.0 (*this assumes that the 6.0 (win/arm64) compiler still works with SwiftCompilerSources disabled as that was likely-irreversibly broken and dropped around July/August '24 Compiler crash building swiftpm with Windows ARM toolchain #75809 (comment))
  • apply the codegen patches to 6.0
  • build a new 6.0
  • (r)enabling SwiftCompilerSources in 6.0/main
  • applying the rest of the fixes in 6.0/main
  • using that 6.0 build, bootstrap a new 6.0/mainand
  • permanently requiring the bootstrap toolchain for 6.0/main to be this 6.0 build or later.

If we can patch 5.10, it'd take to

  • apply the codegen patches to 5.1
  • build a new 5.10 release
  • patching 6.0/main (+ enabling SwiftCompilerSources in main)
  • updating their bootstrap toolchains to the new 5.10
  • rebuilding 6.0/main.

Given this, patching 5.1 seemed to be a bit simpler, if possible. Hence a preference to make this fix in the 5.10 toolchain. I think @compnerd suggested patching 5.10 for that reason.
I am afraid that this is just what it takes to fix the win/arm64 compiler.

@DougGregor @eeckstein @compnerd What do you think?

@hjyamauchi
Copy link
Contributor Author

hjyamauchi commented Nov 1, 2024

Cherrypicking the fixes for issue 74866 into release/5.10 (this PR and swiftlang/llvm-project#9478) seems to cause the following test failures, which do not occur with release/6.0 and main:

  Swift(windows-x86_64) :: Interop/Cxx/class/inheritance/functions.swift
  Swift(windows-x86_64) :: Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-msvc.swift
  Swift(windows-x86_64) :: Interop/Cxx/class/method/methods.swift
  Swift(windows-x86_64) :: Interop/Cxx/operators/member-inline-typechecker.swift
  Swift(windows-x86_64) :: Interop/Cxx/operators/member-inline.swift

Interop/Cxx/operators/member-inline-typechecker.swift

S:\SourceCache\swift\test\Interop\Cxx\operators\member-inline-typechecker.swift:9:5: error: unexpected warning produced: result of operator '+=' is unused
lhs += rhs
    ^

error: command failed with exit status: 1

This is likely caused by that we don't drop the return type of an operator+= unless it's a reference type. We could add this warning to the type to make the test pass, but maybe the code that adds @discardableResult on non trivial return type that you mentioned that's in release/6.0 and main doesn't exist in release/5.10? @rjmccall Do you happen to know what code that is?

The other four tests

They all fail with this assert failure:

Assertion failed: empty() && "explosion had values remaining when destroyed!", file S:\SourceCache\swift\lib\IRGen\Explosion.h, line 68

This seems to be happening in a C++ method that returns a C++ struct/class as a value type. Perhaps the isSRetAfterThis refactoring in GenCall.cpp is causing. I'd reintroduce the debug assertions for the isSRetAfterThis refactoring like the one from #76324 (comment) and report back what I get.

The stack dumps of the four test failures

Stack dump:
0.      Program arguments: s:\\b\\1\\bin\\swiftc.exe -frontend -c -primary-file S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\inheritance\\functions.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -I S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\inheritance/Inputs/ -vfsoverlay S:/b/1/tools/swift\\stdlib\\windows-vfs-overlay.yaml -module-cache-path S:\\b\\1\\swift-test-results\\x86_64-unknown-windows-msvc\\clang-module-cache -swift-version 4 -define-availability "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -define-availability "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" -define-availability "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" -define-availability "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" -define-availability "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" -define-availability "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" -define-availability "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" -define-availability "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" -define-availability "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" -define-availability "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4" -define-availability "SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0" -define-availability "SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4" -enable-experimental-cxx-interop -plugin-path s:\\b\\1\\bin -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name main -o C:\\Users\\hiroshi\\AppData\\Local\\Temp\\lit-tmp-a5slxcxc\\functions-beec42.o
1.      Swift version 5.10.1-dev (LLVM e1e3547d15121a9, Swift 1c15b1d7e585bdc)
2.      Compiling with effective version 4.1.50
3.      While evaluating request IRGenRequest(IR Generation for file "S:\SourceCache\swift\test\Interop\Cxx\class\inheritance\functions.swift")
4.      While emitting IR SIL function "@$sSo011DerivedFromA0V23returnsNonTrivialInBaseSo0dE0VyF".
 for 'returnsNonTrivialInBase()' (in module 'Functions')
Exception Code: 0x80000003
 #0 0x00007ff7c2e75415 HandleAbort S:\SourceCache\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ff9fc4be6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9fc4bf6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff9fc4c108e (C:\Windows\System32\ucrtbase.dll+0x8108e)
 #4 0x00007ff9fc4c12d1 (C:\Windows\System32\ucrtbase.dll+0x812d1)
 #5 0x00007ff7bcba04de llvm::SmallVector<llvm::Value *,8>::{dtor} S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:1207:0
 #6 0x00007ff7bcba04de swift::irgen::Explosion::{dtor} S:\SourceCache\swift\lib\IRGen\Explosion.h:69:0
 #7 0x00007ff7bcba04de `anonymous namespace'::IRGenSILFunction::visitFullApplySite S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:3672:0
 #8 0x00007ff7bcb919c2 swift::SILInstructionVisitor<`anonymous namespace'::IRGenSILFunction,void>::visit S:\SourceCache\swift\include\swift\SIL\SILNodes.def:565:0
 #9 0x00007ff7bcba92df llvm::SmallVectorBase<unsigned int>::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:94:0
#10 0x00007ff7bcba92df llvm::SetVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,llvm::SmallVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2>,llvm::SmallDenseSet<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2,llvm::DenseMapInfo<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,void> > >::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SetVector.h:73:0
#11 0x00007ff7bcba92df `anonymous namespace'::IRGenSILFunction::visitSILBasicBlock S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2650:0
#12 0x00007ff7bcb82f85 `anonymous namespace'::IRGenSILFunction::emitSILFunction S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2514:0
#13 0x00007ff7bcb81f84 swift::irgen::IRGenModule::emitSILFunction(class swift::SILFunction *) S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2369:0
#14 0x00007ff7bc9ebc83 swift::irgen::CurrentIGMPtr::{dtor} S:\SourceCache\swift\lib\IRGen\IRGenModule.h:1889:0
#15 0x00007ff7bc9ebc83 swift::irgen::IRGenerator::emitLazyDefinitions(void) S:\SourceCache\swift\lib\IRGen\GenDecl.cpp:1498:0
#16 0x00007ff7bc9404cd swift::IRGenRequest::evaluate(class swift::Evaluator &, struct swift::IRGenDescriptor) const S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1177:0
#17 0x00007ff7bc94baf6 swift::SimpleRequest<class swift::IRGenRequest, (struct swift::IRGenDescriptor), 9>::evaluateRequest(class swift::IRGenRequest const &, class swift::Evaluator &) S:\SourceCache\swift\include\swift\AST\SimpleRequest.h:292:0
#18 0x00007ff7bc93222c swift::Evaluator::getResultUncached<class swift::IRGenRequest>(class swift::IRGenRequest const &) S:\SourceCache\swift\include\swift\AST\Evaluator.h:370:0
#19 0x00007ff7bc9455ea swift::performIRGeneration(class swift::FileUnit *, class swift::IRGenOptions const &, struct swift::TBDGenOptions const &, class std::unique_ptr<class swift::SILModule, struct std::default_delete<class swift::SILModule>>, class llvm::StringRef, class swift::PrimarySpecificPaths const &, class llvm::StringRef, class llvm::GlobalVariable **) S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1591:0
#20 0x00007ff7bc56f4ad performCompileStepsPostSILGen S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1851:0
#21 0x00007ff7bc570042 swift::performCompileStepsPostSema(class swift::CompilerInstance &, int &, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:862:0
#22 0x00007ff7bc56e838 performAction S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1398:0
#23 0x00007ff7bc56ee0b std::unique_ptr<swift::ASTContext,std::default_delete<swift::ASTContext> >::operator bool C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3305:0
#24 0x00007ff7bc56ee0b std::operator== C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3550:0
#25 0x00007ff7bc56ee0b std::operator!= C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3561:0
#26 0x00007ff7bc56ee0b swift::CompilerInstance::hasASTContext S:\SourceCache\swift\include\swift\Frontend\Frontend.h:560:0
#27 0x00007ff7bc56ee0b performCompile S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1471:0
#28 0x00007ff7bc571355 swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:2420:0
#29 0x00007ff7bc3ddf24 run_driver S:\SourceCache\swift\lib\DriverTool\driver.cpp:235:0
#30 0x00007ff7bc3dda09 swift::mainEntry(int, char const **) S:\SourceCache\swift\lib\DriverTool\driver.cpp:498:0
#31 0x00007ff7c2f265ac invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#32 0x00007ff7c2f265ac __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#33 0x00007ff9fe7f257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#34 0x00007ff9ff18af08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)


Stack dump:
0.      Program arguments: s:\\\\b\\\\1\\\\bin\\\\swift-frontend.exe -target x86_64-unknown-windows-msvc -module-cache-path S:\\b\\1\\swift-test-results\\x86_64-unknown-windows-msvc\\clang-module-cache -vfsoverlay S:/b/1/tools/swift\\stdlib\\windows-vfs-overlay.yaml -swift-version 4 -define-availability "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -define-availability "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" -define-availability "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" -define-availability "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" -define-availability "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" -define-availability "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" -define-availability "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" -define-availability "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" -define-availability "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" -define-availability "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4" -define-availability "SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0" -define-availability "SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4" -typo-correction-limit 10 -emit-irgen -I S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\method/Inputs -enable-experimental-cxx-interop S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\method\\methods-this-and-indirect-return-irgen-msvc.swift
1.      Swift version 5.10.1-dev (LLVM e1e3547d15121a9, Swift 1c15b1d7e585bdc)
2.      Compiling with effective version 4.1.50
3.      While evaluating request IRGenRequest(IR Generation for module main)
4.      While emitting IR SIL function "@$s4main3uses5Int32VyF".
 for 'use()' (at S:\SourceCache\swift\test\Interop\Cxx\class\method\methods-this-and-indirect-return-irgen-msvc.swift:7:8)
Exception Code: 0x80000003
 #0 0x00007ff707ca5415 HandleAbort S:\SourceCache\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ff9fc4be6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9fc4bf6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff9fc4c108e (C:\Windows\System32\ucrtbase.dll+0x8108e)
 #4 0x00007ff9fc4c12d1 (C:\Windows\System32\ucrtbase.dll+0x812d1)
 #5 0x00007ff7019d04de llvm::SmallVector<llvm::Value *,8>::{dtor} S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:1207:0
 #6 0x00007ff7019d04de swift::irgen::Explosion::{dtor} S:\SourceCache\swift\lib\IRGen\Explosion.h:69:0
 #7 0x00007ff7019d04de `anonymous namespace'::IRGenSILFunction::visitFullApplySite S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:3672:0
 #8 0x00007ff7019c19c2 swift::SILInstructionVisitor<`anonymous namespace'::IRGenSILFunction,void>::visit S:\SourceCache\swift\include\swift\SIL\SILNodes.def:565:0
 #9 0x00007ff7019d92df llvm::SmallVectorBase<unsigned int>::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:94:0
#10 0x00007ff7019d92df llvm::SetVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,llvm::SmallVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2>,llvm::SmallDenseSet<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2,llvm::DenseMapInfo<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,void> > >::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SetVector.h:73:0
#11 0x00007ff7019d92df `anonymous namespace'::IRGenSILFunction::visitSILBasicBlock S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2650:0
#12 0x00007ff7019b2f85 `anonymous namespace'::IRGenSILFunction::emitSILFunction S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2514:0
#13 0x00007ff7019b1f84 swift::irgen::IRGenModule::emitSILFunction(class swift::SILFunction *) S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2369:0
#14 0x00007ff70181ab88 swift::irgen::CurrentIGMPtr::{dtor} S:\SourceCache\swift\lib\IRGen\IRGenModule.h:1889:0
#15 0x00007ff70181ab88 swift::irgen::IRGenerator::emitGlobalTopLevel(class std::vector<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>, class std::allocator<class std::basic_string<char, struct std::char_traits<char>, class std::allocator<char>>>> const &) S:\SourceCache\swift\lib\IRGen\GenDecl.cpp:1302:0
#16 0x00007ff70177039f std::vector<std::basic_string<char,std::char_traits<char>,std::allocator<char> >,std::allocator<std::basic_string<char,std::char_traits<char>,std::allocator<char> > > >::{dtor} C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\vector:765:0
#17 0x00007ff70177039f swift::IRGenRequest::evaluate(class swift::Evaluator &, struct swift::IRGenDescriptor) const S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1158:0
#18 0x00007ff70177baf6 swift::SimpleRequest<class swift::IRGenRequest, (struct swift::IRGenDescriptor), 9>::evaluateRequest(class swift::IRGenRequest const &, class swift::Evaluator &) S:\SourceCache\swift\include\swift\AST\SimpleRequest.h:292:0
#19 0x00007ff70176222c swift::Evaluator::getResultUncached<class swift::IRGenRequest>(class swift::IRGenRequest const &) S:\SourceCache\swift\include\swift\AST\Evaluator.h:370:0
#20 0x00007ff701775b93 swift::performIRGeneration(class swift::ModuleDecl *, class swift::IRGenOptions const &, struct swift::TBDGenOptions const &, 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 **) S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1574:0
#21 0x00007ff70139f516 performCompileStepsPostSILGen S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1856:0
#22 0x00007ff70139fc16 std::unique_ptr<swift::SILModule,std::default_delete<swift::SILModule> >::{dtor} C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3279:0
#23 0x00007ff70139fc16 swift::performCompileStepsPostSema(class swift::CompilerInstance &, int &, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:847:0
#24 0x00007ff70139e838 performAction S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1398:0
#25 0x00007ff70139ee0b std::unique_ptr<swift::ASTContext,std::default_delete<swift::ASTContext> >::operator bool C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3305:0
#26 0x00007ff70139ee0b std::operator== C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3550:0
#27 0x00007ff70139ee0b std::operator!= C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3561:0
#28 0x00007ff70139ee0b swift::CompilerInstance::hasASTContext S:\SourceCache\swift\include\swift\Frontend\Frontend.h:560:0
#29 0x00007ff70139ee0b performCompile S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1471:0
#30 0x00007ff7013a1355 swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:2420:0
#31 0x00007ff70120e392 run_driver S:\SourceCache\swift\lib\DriverTool\driver.cpp:277:0
#32 0x00007ff70120da09 swift::mainEntry(int, char const **) S:\SourceCache\swift\lib\DriverTool\driver.cpp:498:0
#33 0x00007ff707d565ac invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#34 0x00007ff707d565ac __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#35 0x00007ff9fe7f257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#36 0x00007ff9ff18af08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)

Stack dump:
0.      Program arguments: s:\\b\\1\\bin\\swiftc.exe -frontend -c -primary-file S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\method\\methods.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -I S:\\SourceCache\\swift\\test\\Interop\\Cxx\\class\\method/Inputs/ -vfsoverlay S:/b/1/tools/swift\\stdlib\\windows-vfs-overlay.yaml -module-cache-path S:\\b\\1\\swift-test-results\\x86_64-unknown-windows-msvc\\clang-module-cache -swift-version 4 -define-availability "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -define-availability "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" -define-availability "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" -define-availability "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" -define-availability "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" -define-availability "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" -define-availability "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" -define-availability "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" -define-availability "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" -define-availability "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4" -define-availability "SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0" -define-availability "SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4" -enable-experimental-cxx-interop -plugin-path s:\\b\\1\\bin -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name main -o C:\\Users\\hiroshi\\AppData\\Local\\Temp\\lit-tmp-a5slxcxc\\methods-133bc1.o
1.      Swift version 5.10.1-dev (LLVM e1e3547d15121a9, Swift 1c15b1d7e585bdc)
2.      Compiling with effective version 4.1.50
3.      While evaluating request IRGenRequest(IR Generation for file "S:\SourceCache\swift\test\Interop\Cxx\class\method\methods.swift")
4.      While emitting IR SIL function "@$s4mainyycfU4_".
 for expression at [S:\SourceCache\swift\test\Interop\Cxx\class\method\methods.swift:45:57 - line:50:1] RangeText="{
  var instance = HasMethods()
  expectEqual(42, instance.nonConstPassThroughAsWrapper(42).value)
  expectEqual(42, instance.constPassThroughAsWrapper(42).value)
"
Exception Code: 0x80000003
 #0 0x00007ff7c2e75415 HandleAbort S:\SourceCache\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ff9fc4be6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9fc4bf6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff9fc4c108e (C:\Windows\System32\ucrtbase.dll+0x8108e)
 #4 0x00007ff9fc4c12d1 (C:\Windows\System32\ucrtbase.dll+0x812d1)
 #5 0x00007ff7bcba04de llvm::SmallVector<llvm::Value *,8>::{dtor} S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:1207:0
 #6 0x00007ff7bcba04de swift::irgen::Explosion::{dtor} S:\SourceCache\swift\lib\IRGen\Explosion.h:69:0
 #7 0x00007ff7bcba04de `anonymous namespace'::IRGenSILFunction::visitFullApplySite S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:3672:0
 #8 0x00007ff7bcb919c2 swift::SILInstructionVisitor<`anonymous namespace'::IRGenSILFunction,void>::visit S:\SourceCache\swift\include\swift\SIL\SILNodes.def:565:0
 #9 0x00007ff7bcba92df llvm::SmallVectorBase<unsigned int>::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:94:0
#10 0x00007ff7bcba92df llvm::SetVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,llvm::SmallVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2>,llvm::SmallDenseSet<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2,llvm::DenseMapInfo<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,void> > >::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SetVector.h:73:0
#11 0x00007ff7bcba92df `anonymous namespace'::IRGenSILFunction::visitSILBasicBlock S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2650:0
#12 0x00007ff7bcb82f85 `anonymous namespace'::IRGenSILFunction::emitSILFunction S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2514:0
#13 0x00007ff7bcb81f84 swift::irgen::IRGenModule::emitSILFunction(class swift::SILFunction *) S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2369:0
#14 0x00007ff7bc9ebc83 swift::irgen::CurrentIGMPtr::{dtor} S:\SourceCache\swift\lib\IRGen\IRGenModule.h:1889:0
#15 0x00007ff7bc9ebc83 swift::irgen::IRGenerator::emitLazyDefinitions(void) S:\SourceCache\swift\lib\IRGen\GenDecl.cpp:1498:0
#16 0x00007ff7bc9404cd swift::IRGenRequest::evaluate(class swift::Evaluator &, struct swift::IRGenDescriptor) const S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1177:0
#17 0x00007ff7bc94baf6 swift::SimpleRequest<class swift::IRGenRequest, (struct swift::IRGenDescriptor), 9>::evaluateRequest(class swift::IRGenRequest const &, class swift::Evaluator &) S:\SourceCache\swift\include\swift\AST\SimpleRequest.h:292:0
#18 0x00007ff7bc93222c swift::Evaluator::getResultUncached<class swift::IRGenRequest>(class swift::IRGenRequest const &) S:\SourceCache\swift\include\swift\AST\Evaluator.h:370:0
#19 0x00007ff7bc9455ea swift::performIRGeneration(class swift::FileUnit *, class swift::IRGenOptions const &, struct swift::TBDGenOptions const &, class std::unique_ptr<class swift::SILModule, struct std::default_delete<class swift::SILModule>>, class llvm::StringRef, class swift::PrimarySpecificPaths const &, class llvm::StringRef, class llvm::GlobalVariable **) S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1591:0
#20 0x00007ff7bc56f4ad performCompileStepsPostSILGen S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1851:0
#21 0x00007ff7bc570042 swift::performCompileStepsPostSema(class swift::CompilerInstance &, int &, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:862:0
#22 0x00007ff7bc56e838 performAction S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1398:0
#23 0x00007ff7bc56ee0b std::unique_ptr<swift::ASTContext,std::default_delete<swift::ASTContext> >::operator bool C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3305:0
#24 0x00007ff7bc56ee0b std::operator== C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3550:0
#25 0x00007ff7bc56ee0b std::operator!= C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3561:0
#26 0x00007ff7bc56ee0b swift::CompilerInstance::hasASTContext S:\SourceCache\swift\include\swift\Frontend\Frontend.h:560:0
#27 0x00007ff7bc56ee0b performCompile S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1471:0
#28 0x00007ff7bc571355 swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:2420:0
#29 0x00007ff7bc3ddf24 run_driver S:\SourceCache\swift\lib\DriverTool\driver.cpp:235:0
#30 0x00007ff7bc3dda09 swift::mainEntry(int, char const **) S:\SourceCache\swift\lib\DriverTool\driver.cpp:498:0
#31 0x00007ff7c2f265ac invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#32 0x00007ff7c2f265ac __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#33 0x00007ff9fe7f257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#34 0x00007ff9ff18af08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)


Stack dump:
0.      Program arguments: s:\\b\\1\\bin\\swiftc.exe -frontend -c -primary-file S:\\SourceCache\\swift\\test\\Interop\\Cxx\\operators\\member-inline.swift -target x86_64-unknown-windows-msvc -disable-objc-interop -I S:\\SourceCache\\swift\\test\\Interop\\Cxx\\operators/Inputs -vfsoverlay S:/b/1/tools/swift\\stdlib\\windows-vfs-overlay.yaml -module-cache-path S:\\b\\1\\swift-test-results\\x86_64-unknown-windows-msvc\\clang-module-cache -swift-version 4 -define-availability "SwiftStdlib 9999:macOS 9999, iOS 9999, watchOS 9999, tvOS 9999" -define-availability "SwiftStdlib 5.0:macOS 10.14.4, iOS 12.2, watchOS 5.2, tvOS 12.2" -define-availability "SwiftStdlib 5.1:macOS 10.15, iOS 13.0, watchOS 6.0, tvOS 13.0" -define-availability "SwiftStdlib 5.2:macOS 10.15.4, iOS 13.4, watchOS 6.2, tvOS 13.4" -define-availability "SwiftStdlib 5.3:macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0" -define-availability "SwiftStdlib 5.4:macOS 11.3, iOS 14.5, watchOS 7.4, tvOS 14.5" -define-availability "SwiftStdlib 5.5:macOS 12.0, iOS 15.0, watchOS 8.0, tvOS 15.0" -define-availability "SwiftStdlib 5.6:macOS 12.3, iOS 15.4, watchOS 8.5, tvOS 15.4" -define-availability "SwiftStdlib 5.7:macOS 13.0, iOS 16.0, watchOS 9.0, tvOS 16.0" -define-availability "SwiftStdlib 5.8:macOS 13.3, iOS 16.4, watchOS 9.4, tvOS 16.4" -define-availability "SwiftStdlib 5.9:macOS 14.0, iOS 17.0, watchOS 10.0, tvOS 17.0" -define-availability "SwiftStdlib 5.10:macOS 14.4, iOS 17.4, watchOS 10.4, tvOS 17.4" -enable-experimental-cxx-interop -plugin-path s:\\b\\1\\bin -autolink-library oldnames -autolink-library msvcrt -Xcc -D_MT -Xcc -D_DLL -module-name main -o C:\\Users\\hiroshi\\AppData\\Local\\Temp\\lit-tmp-a5slxcxc\\member-inline-16963c.o
1.      Swift version 5.10.1-dev (LLVM e1e3547d15121a9, Swift 1c15b1d7e585bdc)
2.      Compiling with effective version 4.1.50
3.      While evaluating request IRGenRequest(IR Generation for file "S:\SourceCache\swift\test\Interop\Cxx\operators\member-inline.swift")
4.      While emitting IR SIL function "@$s4mainyycfU23_".
 for expression at [S:\SourceCache\swift\test\Interop\Cxx\operators\member-inline.swift:280:91 - line:292:1] RangeText="{
  var arr = DerivedFromNonTrivialArrayByVal()
  let NonTrivialByVal = arr[0];
  let cStr = NonTrivialByVal.Str!
  expectEqual("Non-Trivial", String(cString: cStr))
  expectEqual(1, NonTrivialByVal.a)
  expectEqual(2, NonTrivialByVal.b)
  expectEqual(3, NonTrivialByVal.c)
  expectEqual(4, NonTrivialByVal.d)
  expectEqual(5, NonTrivialByVal.e)
  expectEqual(6, NonTrivialByVal.f)
"
Exception Code: 0x80000003
 #0 0x00007ff7c2e75415 HandleAbort S:\SourceCache\llvm-project\llvm\lib\Support\Windows\Signals.inc:414:0
 #1 0x00007ff9fc4be6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ff9fc4bf6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ff9fc4c108e (C:\Windows\System32\ucrtbase.dll+0x8108e)
 #4 0x00007ff9fc4c12d1 (C:\Windows\System32\ucrtbase.dll+0x812d1)
 #5 0x00007ff7bcba04de llvm::SmallVector<llvm::Value *,8>::{dtor} S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:1207:0
 #6 0x00007ff7bcba04de swift::irgen::Explosion::{dtor} S:\SourceCache\swift\lib\IRGen\Explosion.h:69:0
 #7 0x00007ff7bcba04de `anonymous namespace'::IRGenSILFunction::visitFullApplySite S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:3672:0
 #8 0x00007ff7bcb919c2 swift::SILInstructionVisitor<`anonymous namespace'::IRGenSILFunction,void>::visit S:\SourceCache\swift\include\swift\SIL\SILNodes.def:565:0
 #9 0x00007ff7bcba92df llvm::SmallVectorBase<unsigned int>::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SmallVector.h:94:0
#10 0x00007ff7bcba92df llvm::SetVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,llvm::SmallVector<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2>,llvm::SmallDenseSet<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,2,llvm::DenseMapInfo<std::tuple<swift::irgen::StackAddress,llvm::Value *,unsigned char>,void> > >::empty S:\SourceCache\llvm-project\llvm\include\llvm\ADT\SetVector.h:73:0
#11 0x00007ff7bcba92df `anonymous namespace'::IRGenSILFunction::visitSILBasicBlock S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2650:0
#12 0x00007ff7bcb82f85 `anonymous namespace'::IRGenSILFunction::emitSILFunction S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2514:0
#13 0x00007ff7bcb81f84 swift::irgen::IRGenModule::emitSILFunction(class swift::SILFunction *) S:\SourceCache\swift\lib\IRGen\IRGenSIL.cpp:2369:0
#14 0x00007ff7bc9ebc83 swift::irgen::CurrentIGMPtr::{dtor} S:\SourceCache\swift\lib\IRGen\IRGenModule.h:1889:0
#15 0x00007ff7bc9ebc83 swift::irgen::IRGenerator::emitLazyDefinitions(void) S:\SourceCache\swift\lib\IRGen\GenDecl.cpp:1498:0
#16 0x00007ff7bc9404cd swift::IRGenRequest::evaluate(class swift::Evaluator &, struct swift::IRGenDescriptor) const S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1177:0
#17 0x00007ff7bc94baf6 swift::SimpleRequest<class swift::IRGenRequest, (struct swift::IRGenDescriptor), 9>::evaluateRequest(class swift::IRGenRequest const &, class swift::Evaluator &) S:\SourceCache\swift\include\swift\AST\SimpleRequest.h:292:0
#18 0x00007ff7bc93222c swift::Evaluator::getResultUncached<class swift::IRGenRequest>(class swift::IRGenRequest const &) S:\SourceCache\swift\include\swift\AST\Evaluator.h:370:0
#19 0x00007ff7bc9455ea swift::performIRGeneration(class swift::FileUnit *, class swift::IRGenOptions const &, struct swift::TBDGenOptions const &, class std::unique_ptr<class swift::SILModule, struct std::default_delete<class swift::SILModule>>, class llvm::StringRef, class swift::PrimarySpecificPaths const &, class llvm::StringRef, class llvm::GlobalVariable **) S:\SourceCache\swift\lib\IRGen\IRGen.cpp:1591:0
#20 0x00007ff7bc56f4ad performCompileStepsPostSILGen S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1851:0
#21 0x00007ff7bc570042 swift::performCompileStepsPostSema(class swift::CompilerInstance &, int &, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:862:0
#22 0x00007ff7bc56e838 performAction S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1398:0
#23 0x00007ff7bc56ee0b std::unique_ptr<swift::ASTContext,std::default_delete<swift::ASTContext> >::operator bool C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3305:0
#24 0x00007ff7bc56ee0b std::operator== C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3550:0
#25 0x00007ff7bc56ee0b std::operator!= C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Tools\MSVC\14.38.33130\include\memory:3561:0
#26 0x00007ff7bc56ee0b swift::CompilerInstance::hasASTContext S:\SourceCache\swift\include\swift\Frontend\Frontend.h:560:0
#27 0x00007ff7bc56ee0b performCompile S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:1471:0
#28 0x00007ff7bc571355 swift::performFrontend(class llvm::ArrayRef<char const *>, char const *, void *, class swift::FrontendObserver *) S:\SourceCache\swift\lib\FrontendTool\FrontendTool.cpp:2420:0
#29 0x00007ff7bc3ddf24 run_driver S:\SourceCache\swift\lib\DriverTool\driver.cpp:235:0
#30 0x00007ff7bc3dda09 swift::mainEntry(int, char const **) S:\SourceCache\swift\lib\DriverTool\driver.cpp:498:0
#31 0x00007ff7c2f265ac invoke_main D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78:0
#32 0x00007ff7c2f265ac __scrt_common_main_seh D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288:0
#33 0x00007ff9fe7f257d (C:\Windows\System32\KERNEL32.DLL+0x1257d)
#34 0x00007ff9ff18af08 (C:\Windows\SYSTEM32\ntdll.dll+0x5af08)

@eeckstein
Copy link
Contributor

@hjyamauchi did you verify that a 5.10 toolchain built with this PR is good for building a windows arm64 compiler with SwiftCompilerSources enabled?

@hjyamauchi
Copy link
Contributor Author

As per #77277 (comment), I added back the debug assertions that I used for the isSretAfterThis refactoring (shown at the bottom) and got the following assertion failures. I think that means that CGFunction.getReturnInfo isn't indicating the C++ methods are indirect-returning when they return a C++ class/struct as a value for some reason in release/5.10 (unlike release/6.0 and main where no test/assert failures). Perhaps some patches are missing in release/5.10 for CGFunction to be accurate? Any thoughts @rjmccall?

I also tested with cherrypicking only the arrangeCXXMethodCall part without the isSRetAfterThis refactoring part (from #76324) and all the tests passed (no test failures). @rjmccall do you think it may be an option to do that sort of 'partial' cherrypicking?

Interop/Cxx/class/method/methods-this-and-indirect-return-irgen-msvc.swift1

llvm::FunctionType
void (ptr, ptr, i32)
OrigFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @inout HasMethods) -> @out NonTrivialInWrapper
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=Methods.(file).HasMethods)
  (result=struct_type decl=Methods.(file).NonTrivialInWrapper)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
SubstFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @inout HasMethods) -> @out NonTrivialInWrapper
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=Methods.(file).HasMethods)
  (result=struct_type decl=Methods.(file).NonTrivialInWrapper)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
IGF.IGM.Triple.isWindowsMSVCEnvironment() 1
getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod 1
substResultType.isVoid() 1
getCallee().getFunctionPointer().getRawPointer() 1
returnInfo.isIndirect() 0
returnInfo.getKind() 4
fnConv.getNumIndirectSILResults() 1
Assertion failed: returnInfo.isIndirect(), file S:\SourceCache\swift\lib\IRGen\GenCall.cpp, line 2405

Interop/Cxx/class/method/methods.swift

llvm::FunctionType
void (ptr, ptr, i32)
OrigFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @inout HasMethods) -> @out NonTrivialInWrapper
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=Methods.(file).HasMethods)
  (result=struct_type decl=Methods.(file).NonTrivialInWrapper)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
SubstFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @inout HasMethods) -> @out NonTrivialInWrapper
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=Methods.(file).HasMethods)
  (result=struct_type decl=Methods.(file).NonTrivialInWrapper)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
IGF.IGM.Triple.isWindowsMSVCEnvironment() 1
getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod 1
substResultType.isVoid() 1
getCallee().getFunctionPointer().getRawPointer() 1
returnInfo.isIndirect() 0
returnInfo.getKind() 4
fnConv.getNumIndirectSILResults() 1
Assertion failed: returnInfo.isIndirect(), file S:\SourceCache\swift\lib\IRGen\GenCall.cpp, line 2405

Interop/Cxx/operators/member-inline.swift

llvm::FunctionType
void (ptr, ptr, i32)
OrigFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @in_guaranteed DerivedFromNonTrivialArrayByVal) -> @out NonTrivial
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=MemberInline.(file).DerivedFromNonTrivialArrayByVal)
  (result=struct_type decl=MemberInline.(file).NonTrivial)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
SubstFunctionType
(sil_function_type type=@convention(cxx_method) (Int32, @in_guaranteed DerivedFromNonTrivialArrayByVal) -> @out NonTrivial
  (input=struct_type decl=Swift.(file).Int32)
  (input=struct_type decl=MemberInline.(file).DerivedFromNonTrivialArrayByVal)
  (result=struct_type decl=MemberInline.(file).NonTrivial)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
IGF.IGM.Triple.isWindowsMSVCEnvironment() 1
getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod 1
substResultType.isVoid() 1
getCallee().getFunctionPointer().getRawPointer() 1
returnInfo.isIndirect() 0
returnInfo.getKind() 4
fnConv.getNumIndirectSILResults() 1
Assertion failed: returnInfo.isIndirect(), file S:\SourceCache\swift\lib\IRGen\GenCall.cpp, line 2405

Interop/Cxx/class/inheritance/functions.swift

llvm::FunctionType
void (ptr, ptr)
OrigFunctionType
(sil_function_type type=@convention(cxx_method) (@in_guaranteed DerivedFromDerived) -> @out NonTrivial
  (input=struct_type decl=Functions.(file).DerivedFromDerived)
  (result=struct_type decl=Functions.(file).NonTrivial)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
SubstFunctionType
(sil_function_type type=@convention(cxx_method) (@in_guaranteed DerivedFromDerived) -> @out NonTrivial
  (input=struct_type decl=Functions.(file).DerivedFromDerived)
  (result=struct_type decl=Functions.(file).NonTrivial)
  (substitution_map generic_signature=<nullptr>)
  (substitution_map generic_signature=<nullptr>))
IGF.IGM.Triple.isWindowsMSVCEnvironment() 1
getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod 1
substResultType.isVoid() 1
getCallee().getFunctionPointer().getRawPointer() 1
returnInfo.isIndirect() 0
returnInfo.getKind() 4
fnConv.getNumIndirectSILResults() 1
Assertion failed: returnInfo.isIndirect(), file S:\SourceCache\swift\lib\IRGen\GenCall.cpp, line 2405

The debug assertion patch on top of this PR:

diff --git a/lib/IRGen/Callee.h b/lib/IRGen/Callee.h
index b3875a1c584..f816d316861 100644
--- a/lib/IRGen/Callee.h
+++ b/lib/IRGen/Callee.h
@@ -561,7 +561,7 @@ namespace irgen {

     const FunctionPointer &getFunctionPointer() const { return Fn; }

-    llvm::FunctionType *getLLVMFunctionType() {
+    llvm::FunctionType *getLLVMFunctionType() const {
       return Fn.getFunctionType();
     }

diff --git a/lib/IRGen/GenCall.cpp b/lib/IRGen/GenCall.cpp
index 4cb15a430f6..29e5c170657 100644
--- a/lib/IRGen/GenCall.cpp
+++ b/lib/IRGen/GenCall.cpp
@@ -1528,6 +1528,10 @@ void SignatureExpansion::expandExternalSignatureTypes() {

   // If we return indirectly, that is the first parameter type.
   if (returnInfo.isIndirect()) {
+    // *** (1) *** This passes tests.
+    assert((IGM.Triple.isWindowsMSVCEnvironment() &&
+            FnType->getRepresentation() == SILFunctionTypeRepresentation::CXXMethod) ==
+           returnInfo.isSRetAfterThis());
     if (returnInfo.isSRetAfterThis()) {
       // Windows ABI places `this` before the
       // returned indirect values.
@@ -2369,8 +2373,38 @@ public:

         // Windows ABI places `this` before the
         // returned indirect values.
+        // *** (2) *** This passes tests.
+        assert(getCallee().getForeignInfo().ClangInfo != nullptr);
         auto &returnInfo =
             getCallee().getForeignInfo().ClangInfo->getReturnInfo();
+        if (fnConv.getNumIndirectSILResults() > 0) {
+          if (!returnInfo.isIndirect()) {
+            llvm::dbgs() << "llvm::FunctionType " << "\n";
+            getCallee().getLLVMFunctionType()->dump();
+            llvm::dbgs() << "OrigFunctionType " << "\n";
+            getCallee().getOrigFunctionType()->dump();
+            llvm::dbgs() << "SubstFunctionType " << "\n";
+            getCallee().getSubstFunctionType()->dump();
+            llvm::dbgs() << "IGF.IGM.Triple.isWindowsMSVCEnvironment() "
+                         << IGF.IGM.Triple.isWindowsMSVCEnvironment() << "\n";
+            llvm::dbgs() << "getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod "
+                         << (getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod) << "\n";
+            SILType substResultType =
+                fnConv.getSILResultType(IGF.IGM.getMaximalTypeExpansionContext());
+            llvm::dbgs() << "substResultType.isVoid() " << substResultType.isVoid() << "\n";
+            llvm::dbgs() << "getCallee().getFunctionPointer().getRawPointer() "
+                         << (getCallee().getFunctionPointer().getRawPointer() != 0) << "\n";
+            llvm::dbgs() << "returnInfo.isIndirect() " << returnInfo.isIndirect() << "\n";
+            llvm::dbgs() << "returnInfo.getKind() " << (unsigned)returnInfo.getKind() << "\n";
+            if (returnInfo.isIndirect()) {
+              llvm::dbgs() << "returnInfo.isSRetAfterThis() "
+                           << returnInfo.isSRetAfterThis() << "\n";
+            }
+            llvm::dbgs() << "fnConv.getNumIndirectSILResults() " << fnConv.getNumIndirectSILResults() << "\n";
+          }
+          assert(returnInfo.isIndirect());
+          assert(returnInfo.isSRetAfterThis() == IGF.IGM.Triple.isWindowsMSVCEnvironment());
+        }
         if (returnInfo.isIndirect() && !returnInfo.isSRetAfterThis())
           passIndirectResults();
         adjusted.add(arg);
@@ -2915,7 +2949,43 @@ void CallEmission::emitToUnmappedMemory(Address result) {

   Args[0] = result.getAddress();

+  // *** (3) *** This fails in some test. TBA what test.
   auto *FI = getCallee().getForeignInfo().ClangInfo;
+  if ((IGF.IGM.Triple.isWindowsMSVCEnvironment() &&
+       getCallee().getRepresentation() ==
+           SILFunctionTypeRepresentation::CXXMethod &&
+       Args[1] == getCallee().getCXXMethodSelf()) !=
+      (FI && FI->getReturnInfo().isIndirect() &&
+       FI->getReturnInfo().isSRetAfterThis() &&
+       Args[1] == getCallee().getCXXMethodSelf())) {
+    llvm::dbgs() << "IGF.IGM.Triple.isWindowsMSVCEnvironment() "
+                 << IGF.IGM.Triple.isWindowsMSVCEnvironment() << "\n";
+    llvm::dbgs() << "getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod "
+                 << (getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod) << "\n";
+    llvm::dbgs() << "FI != nullptr " << (FI != nullptr) << "\n";
+    if (FI) {
+      llvm::dbgs() << "FI->getReturnInfo().isIndirect() "
+                   << FI->getReturnInfo().isIndirect() << "\n";
+      llvm::dbgs() << "FI->getReturnInfo().getKind() "
+                   << (unsigned)FI->getReturnInfo().getKind() << "\n";
+      if (FI->getReturnInfo().isIndirect()) {
+        llvm::dbgs() << "FI->getReturnInfo().isSRetAfterThis()"
+                     << FI->getReturnInfo().isSRetAfterThis() << "\n";
+      }
+    }
+    llvm::dbgs() << "Args.size() " << Args.size() << "\n";
+    if (Args.size() >= 2) {
+      llvm::dbgs() << "Args[1] == getCallee().getCXXMethodSelf() "
+                   << (Args[1] == getCallee().getCXXMethodSelf()) << "\n";
+    }
+  }
+  assert((IGF.IGM.Triple.isWindowsMSVCEnvironment() &&
+          getCallee().getRepresentation() ==
+              SILFunctionTypeRepresentation::CXXMethod &&
+          Args[1] == getCallee().getCXXMethodSelf()) ==
+         (FI && FI->getReturnInfo().isIndirect() &&
+          FI->getReturnInfo().isSRetAfterThis() &&
+          Args[1] == getCallee().getCXXMethodSelf()));
   if (FI && FI->getReturnInfo().isIndirect() &&
       FI->getReturnInfo().isSRetAfterThis() &&
       Args[1] == getCallee().getCXXMethodSelf()) {
@@ -3295,7 +3365,55 @@ void CallEmission::emitToExplosion(Explosion &out, bool isOutlined) {
       return;
     }

+    // *** (4) ***
+    // Didn't work due to operator+=() that returns void but CGFunctionInfo doesn't say it's indirect
+    // Tests:
+    // Interop/Cxx/class/method/msvc-abi-return-indirect-trivial-record.swift
+    // Interop/Cxx/operators/member-inline.swift
     auto *FI = getCallee().getForeignInfo().ClangInfo;
+    if ((IGF.IGM.Triple.isWindowsMSVCEnvironment() &&
+         getCallee().getRepresentation() ==
+             SILFunctionTypeRepresentation::CXXMethod &&
+         substResultType.isVoid() &&
+         getCallee().getFunctionPointer().getRawPointer()) !=
+        (FI && FI->getReturnInfo().isIndirect() &&
+         FI->getReturnInfo().isSRetAfterThis() &&
+         substResultType.isVoid() &&
+         getCallee().getFunctionPointer().getRawPointer())) {
+      llvm::dbgs() << "llvm::FunctionType " << "\n";
+      getCallee().getLLVMFunctionType()->dump();
+      llvm::dbgs() << "OrigFunctionType " << "\n";
+      getCallee().getOrigFunctionType()->dump();
+      llvm::dbgs() << "SubstFunctionType " << "\n";
+      getCallee().getSubstFunctionType()->dump();
+      llvm::dbgs() << "IGF.IGM.Triple.isWindowsMSVCEnvironment() "
+                   << IGF.IGM.Triple.isWindowsMSVCEnvironment() << "\n";
+      llvm::dbgs() << "getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod "
+                   << (getCallee().getRepresentation() == SILFunctionTypeRepresentation::CXXMethod) << "\n";
+      llvm::dbgs() << "substResultType.isVoid() " << substResultType.isVoid() << "\n";
+      llvm::dbgs() << "getCallee().getFunctionPointer().getRawPointer() "
+                   << (getCallee().getFunctionPointer().getRawPointer() != 0) << "\n";
+      llvm::dbgs() << "FI != nullptr " << (FI != nullptr) << "\n";
+      if (FI) {
+        llvm::dbgs() << "FI->getReturnInfo().isIndirect() "
+                     << FI->getReturnInfo().isIndirect() << "\n";
+        llvm::dbgs() << "FI->getReturnInfo().getKind() "
+                     << (unsigned)FI->getReturnInfo().getKind() << "\n";
+        if (FI->getReturnInfo().isIndirect()) {
+          llvm::dbgs() << "FI->getReturnInfo().isSRetAfterThis() "
+                       << FI->getReturnInfo().isSRetAfterThis() << "\n";
+        }
+      }
+    }
+    assert((IGF.IGM.Triple.isWindowsMSVCEnvironment() &&
+            getCallee().getRepresentation() ==
+                SILFunctionTypeRepresentation::CXXMethod &&
+            substResultType.isVoid() &&
+            getCallee().getFunctionPointer().getRawPointer()) ==
+           (FI && FI->getReturnInfo().isIndirect() &&
+            FI->getReturnInfo().isSRetAfterThis() &&
+            substResultType.isVoid() &&
+            getCallee().getFunctionPointer().getRawPointer()));
     if (FI && FI->getReturnInfo().isIndirect() &&
         FI->getReturnInfo().isSRetAfterThis() && substResultType.isVoid()) {
       // Some C++ methods return a value but are imported as

@hjyamauchi
Copy link
Contributor Author

hjyamauchi commented Nov 4, 2024

@hjyamauchi did you verify that a 5.10 toolchain built with this PR is good for building a windows arm64 compiler with SwiftCompilerSources enabled?

@eeckstein Yes, I was able to locally (tested up to ~Oct 9, 2024 on main):

  1. Build the 5.10 toolchain with this PR (with Cherrypick fixes for issue 74866 to swift/release/5.10 llvm-project#9478) on win/x64
  2. Using 1. as the bootstrap toolchain, cross-compiled the main win/arm64 toolchain on win/x64 with SwiftCompilerSources enabled.
  3. Using 2. as the bootstrap toolchain, built the main win/arm64 toolchain natively on win/arm64 (with SwiftCompilerSources enabled).

I'll repeat it one more time to re-verify this.

@rjmccall
Copy link
Contributor

rjmccall commented Nov 4, 2024

Yes, you may need to hunt down the last six months of patches in this area if we're serious about back porting the work to it.

@hjyamauchi
Copy link
Contributor Author

@egorzhdan @ahatanaka Do you know what code adds @discardableResult on a non-trivial return type of a C++ method so that we don't get a warning like the following?

Interop/Cxx/operators/member-inline-typechecker.swift

S:\SourceCache\swift\test\Interop\Cxx\operators\member-inline-typechecker.swift:9:5: error: unexpected warning produced: result of operator '+=' is unused
lhs += rhs
    ^

error: command failed with exit status: 1

This PR would like to drop the return type of an operator+= only if it's a reference type, but the above warning started appearing.

954e740

@hjyamauchi
Copy link
Contributor Author

Yes, you may need to hunt down the last six months of patches in this area if we're serious about back porting the work to it.

@rjmccall CGFunctionInfo comes straight from Clang (perhaps we're looking for a clang patch), right? Or does the swift repo code or ClangImporter affect how they are created?

@rjmccall
Copy link
Contributor

rjmccall commented Nov 4, 2024

Swift decides the function signature that it passes to Clang, and I expect the bug fixes will be on that side.

@hjyamauchi
Copy link
Contributor Author

Swift decides the function signature that it passes to Clang, and I expect the bug fixes will be on that side.

Do you mean the bug fixes will be on the Swift side?

@rjmccall
Copy link
Contributor

rjmccall commented Nov 4, 2024

That's my guess, yes.

@hjyamauchi
Copy link
Contributor Author

@hjyamauchi did you verify that a 5.10 toolchain built with this PR is good for building a windows arm64 compiler with SwiftCompilerSources enabled?

@eeckstein Yes, I was able to locally (tested up to ~Oct 9, 2024 on main):

  1. Build the 5.10 toolchain with this PR (with Cherrypick fixes for issue 74866 to swift/release/5.10 llvm-project#9478) on win/x64
  2. Using 1. as the bootstrap toolchain, cross-compiled the main win/arm64 toolchain on win/x64 with SwiftCompilerSources enabled.
  3. Using 2. as the bootstrap toolchain, built the main win/arm64 toolchain natively on win/arm64 (with SwiftCompilerSources enabled).

I'll repeat it one more time to re-verify this.

@eeckstein Yes, I was able to confirm this works again. The 5.10 toolchain built with this PR is able to bootstrap a main-branch windows arm64 toolchain with SwiftCompilerSources enabled, as described above.

@compnerd
Copy link
Member

compnerd commented Nov 7, 2024

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

1 similar comment
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@compnerd
Copy link
Member

compnerd commented Nov 8, 2024

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

1 similar comment
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

The use of 'nocapture' for parameters and return values is incorrect for C++ types, as they can actually capture a pointer into its own value (e.g. std::string in libstdc++)

rdar://115062687

Cherrypick commit 4858cb6
Cherrypick PR swiftlang#68481
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

We do not synthesize the inheritance thunks correctly for such methods. Do not try to synthesize them, as that causes issues when there are two overloads of the same method, one with rvalue this and one without.

The proper solution is tracked as swiftlang#69745

Unblocks rdar://114282353

Cherrypick commit f9bf957
Cherrypick PR swiftlang#69746
…e classes

If a C++ type `Derived` inherits from `Base` privately, the public methods from `Base` should not be callable on an instance of `Derived`. However, C++ supports exposing such methods via a using declaration: `using MyPrivateBase::myPublicMethod;`.

MSVC started using this feature for `std::optional` which means Swift doesn't correctly import `var pointee: Pointee` for instantiations of `std::optional` on Windows. This prevents the automatic conformance to `CxxOptional` from being synthesized.

rdar://114282353 / resolves swiftlang#68068

Cherrypick commit efc008a
Cherrypick PR swiftlang#69623
…kup table elsewhere

NFC intended

Cherrypick commit 0b69eb5
Cherrypick PR swiftlang#69991
…base class

This is required for proper support for `std::vector::iterator` on Windows.

rdar://118657936 / resolves swiftlang#69990

Cherrypick commit ece33a4
Cherrypick PR swiftlang#69991
…wiftlang#71790)

This fixes a bug where the thunk for a C++ constructor call wasn't being
called when the constructor was called the second time.

Cherrypick commit 97a8148
Cherrypick PR swiftlang#71790
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test Windows Platform

…lang#71459)

Fix a bug in expandExternalSignatureTypes where it wasn't annotating a function call parameter type with sret when the result was being returned indirectly.

The bug was causing calls to ObjC methods that return their results indirectly to crash.

Additionally, fix the return type for C++ constructors computed in expandExternalSignatureTypes. Previously, the return type was always void even on targets that require constructors to return this (e.g., Apple arm64), which was causing C++ constructor thunks to be emitted needlessly.

Resolves rdar://121618707

Cherrypick commit b3f302b
Cherrypick PR swiftlang#71459
On Windows/AArch64, a different register is used between when an
arugment is both inreg and sret (X0 or X1) and when it is just sret
(X8) as the following comment indicates:

https://github.com/llvm/llvm-project/blob/46fe36a4295f05d5d3731762e31fc4e6e99863e9/llvm/lib/Target/AArch64/AArch64CallingConvention.td#L42

```
  // In AAPCS, an SRet is passed in X8, not X0 like a normal pointer parameter.
  // However, on windows, in some circumstances, the SRet is passed in X0 or X1
  // instead.  The presence of the inreg attribute indicates that SRet is
  // passed in the alternative register (X0 or X1), not X8:
  // - X0 for non-instance methods.
  // - X1 for instance methods.

  // The "sret" attribute identifies indirect returns.
  // The "inreg" attribute identifies non-aggregate types.
  // The position of the "sret" attribute identifies instance/non-instance
  // methods.
  // "sret" on argument 0 means non-instance methods.
  // "sret" on argument 1 means instance methods.

  CCIfInReg<CCIfType<[i64],
        CCIfSRet<CCIfType<[i64], CCAssignToReg<[X0, X1]>>>>>,

  CCIfSRet<CCIfType<[i64], CCAssignToReg<[X8]>>>,
```

So missing/dropping inreg can cause a codegen bug.

This is a partial fix for swiftlang#74866

Cherrypick commit 3f0de57
Cherrypick PR swiftlang#76159
In GenCall, fix the IR gen for C++ method calls as under MSVC as the
calling conventions for free functions and C++ methods can be
different. This also fixes the missing inreg (on sret arguments)
issues on Windows ARM64. Also refactor to use CGFunctionInfo
returnInfo isSretAfterThis to detect when to reorder the sret and the
this arguments under MSVC.

In ClagImporter, don't drop the return type for the compound
assignment operators such as operator+= when the return value is a
reference so that the CGFunctionInfo will be correctly indicate an
indirect return for the compound assignment operators.

Cherrypick commit fcc1f6b
Cherrypick PR swiftlang#76324
@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test Windows Platform

@hjyamauchi
Copy link
Contributor Author

Please test with following PRs:
swiftlang/llvm-project#9478

@swift-ci please test

@hjyamauchi
Copy link
Contributor Author

I managed to figure out a set of additional PRs (~10-ish in total) to get the failing tests fixed. The CI testing passed and this is ready for review. Please take a look @rjmccall.

@hjyamauchi hjyamauchi marked this pull request as ready for review November 15, 2024 18:46
@compnerd compnerd requested a review from a team November 15, 2024 18:58
@hjyamauchi
Copy link
Contributor Author

We decided not to cherrypick the fixes to 5.10

@hjyamauchi hjyamauchi closed this Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants