swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.66k stars 10.38k forks source link

Crash in DestroyAddrHoisting on Simple Code Example #77693

Open compnerd opened 1 week ago

compnerd commented 1 week ago

Description

No response

Reproduction

// %target-swift-frontend -O -module-name reduced -o %t -primary-file %s

protocol P {}
enum E {
    case c(any P)
    var d: [String:String] { [:] }
}

final class C {
    var o: [String:String]?
}

func f(_ e: E?) {
    if let e {
        C().o?.merge(e.d) { c, _ in c }
    }
}

Stack dump

Stack dump:
0.      Program arguments: "S:\\Program Files\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\bin\\swift-frontend.exe" -frontend -c -primary-file .\\reduced.swift -target x86_64-unknown-windows-msvc -sdk "S:\\Program Files\\Swift\\Platforms\\Windows.platform\\Developer\\SDKs\\Windows.sdk" -O -resource-dir "S:\\Program Files\\Swift\\Toolchains\\0.0.0+Asserts\\usr\\lib\\swift" -module-name reduced -o C:\\Users\\abdulras\\AppData\\Local\\Temp\\TemporaryDirectory.G2spNa\\reduced-1.o
1.      Swift version 6.1-dev (LLVM 5728735dd595a22, Swift 95c6590e575d8eb)
2.      Compiling with effective version 5.10
3.      While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for reduced)
4.      While running pass #3299 SILFunctionTransform "DestroyAddrHoisting" on SILFunction "@$s7reduced1fyyAA1EOSgF".
 for 'f(_:)' (at .\reduced.swift:11:1)
Exception Code: 0x80000003
 #0 0x00007ff6e071fa85 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x7ebfa85)
 #1 0x00007ffc6f8ae6d5 (C:\Windows\System32\ucrtbase.dll+0x7e6d5)
 #2 0x00007ffc6f8af6e1 (C:\Windows\System32\ucrtbase.dll+0x7f6e1)
 #3 0x00007ffc6f8b114a (C:\Windows\System32\ucrtbase.dll+0x8114a)
 #4 0x00007ffc6f8b103d (C:\Windows\System32\ucrtbase.dll+0x8103d)
 #5 0x00007ffc6f8b12d1 (C:\Windows\System32\ucrtbase.dll+0x812d1)
 #6 0x00007ff6d9b1f40d (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x12bf40d)
 #7 0x00007ff6d9b1c8b3 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x12bc8b3)
 #8 0x00007ff6d9b1b266 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x12bb266)
 #9 0x00007ff6d9b1e172 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x12be172)
#10 0x00007ff6d983d8bd (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfdd8bd)
#11 0x00007ff6d983cb27 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfdcb27)
#12 0x00007ff6d98328c7 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfd28c7)
#13 0x00007ff6d9832ba6 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfd2ba6)
#14 0x00007ff6d98325b7 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfd25b7)
#15 0x00007ff6d98a91bd (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x10491bd)
#16 0x00007ff6d9832d3f (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfd2d3f)
#17 0x00007ff6d98127a5 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0xfb27a5)
#18 0x00007ff6d9122c85 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x8c2c85)
#19 0x00007ff6d8d9df0d (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x53df0d)
#20 0x00007ff6d8d9e9ef (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x53e9ef)
#21 0x00007ff6d8d9d667 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x53d667)
#22 0x00007ff6d8d9dc02 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x53dc02)
#23 0x00007ff6d8d9f99b (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x53f99b)
#24 0x00007ff6d8bd42f0 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x3742f0)
#25 0x00007ff6d8bd3e67 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x373e67)
#26 0x00007ff6e07adc40 (S:\Program Files\Swift\Toolchains\0.0.0+Asserts\usr\bin\swift-frontend.exe+0x7f4dc40)
#27 0x00007ffc70e3259d (C:\Windows\System32\KERNEL32.DLL+0x1259d)
#28 0x00007ffc7200af38 (C:\Windows\SYSTEM32\ntdll.dll+0x5af38)

### Expected behavior

For this code to compile.

### Environment

Swift version 6.1-dev (LLVM 5728735dd595a22, Swift 95c6590e575d8eb) Target: x86_64-unknown-windows-msvc



### Additional information

_No response_
compnerd commented 1 week ago

Reproduces on Linux

gottesmm commented 1 week ago

I confirmed using godbolt that this crashes on Linux as well.

gottesmm commented 1 week ago

https://godbolt.org/z/aaz7asKPE

eeckstein commented 1 week ago

Crashes on mac as well:

Assertion failed: (!foundLocalKill && "found local kill for non-local gen?!"), function visitBlockFromGen, file VisitBarrierAccessScopes.h, line 202.
...
7  swift-frontend           0x00000001073f93ec (anonymous namespace)::DeinitBarriers::compute() (.cold.49) + 0
8  swift-frontend           0x0000000101d7a2d4 (anonymous namespace)::DeinitBarriers::compute() + 7388
9  swift-frontend           0x0000000101d77d5c hoistDestroys(swift::SILValue, bool, llvm::SmallPtrSetImpl<swift::SILInstruction*>&, swift::InstructionDeleter&, swift::BasicCalleeAnalysis*) + 1044
10 swift-frontend           0x0000000101d7d534 (anonymous namespace)::DestroyAddrHoisting::run() + 1888
hjyamauchi commented 1 week ago

Can also confirm it crashes on my mac:

Assertion failed: (!foundLocalKill && "found local kill for non-local gen?!"), function visitBlockFromGen, file VisitBarrierAccessScopes.h, line 202.
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Users/hiroshi/dev/swift-project/build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/bin/swift-frontend -frontend -c -primary-file test.swift -target arm64-apple-darwin23.6.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -color-diagnostics -O -in-process-plugin-server-path /Users/hiroshi/dev/swift-project/build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Users/hiroshi/dev/swift-project/build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/lib/swift/host/plugins -plugin-path /Users/hiroshi/dev/swift-project/build/Ninja-ReleaseAssert+swift-DebugAssert/swift-macosx-arm64/local/lib/swift/host/plugins -dwarf-version=4 -module-name test -o /var/folders/ww/kxcj3hm12kd92gcwr9t3y7k40000gq/T/test-5cc2ac.o
1.  Swift version 6.1-dev (LLVM 94d9cd16d9b38ed, Swift 2affbd8945c02a3)
2.  Compiling with effective version 5.10
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for test)
4.  While running pass #5191 SILFunctionTransform "DestroyAddrHoisting" on SILFunction "@$s4test1fyyAA1EOSgF".
 for 'f(_:)' (at test.swift:11:1)
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           0x000000010b401038 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010b3ff248 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010b4016dc SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000018c1ba584 _sigtramp + 56
4  libsystem_pthread.dylib  0x000000018c189c20 pthread_kill + 288
5  libsystem_c.dylib        0x000000018c096a30 abort + 180
6  libsystem_c.dylib        0x000000018c095d20 err + 0
7  swift-frontend           0x0000000104084290 swift::VisitBarrierAccessScopes<(anonymous namespace)::DeinitBarriers::DestroyReachability, (anonymous namespace)::DeinitBarriers::DestroyReachability>::visitBlockFromGen(swift::SILInstruction*) + 332
8  swift-frontend           0x0000000104082554 swift::VisitBarrierAccessScopes<(anonymous namespace)::DeinitBarriers::DestroyReachability, (anonymous namespace)::DeinitBarriers::DestroyReachability>::visit() + 608
9  swift-frontend           0x0000000104081a78 (anonymous namespace)::DeinitBarriers::DestroyReachability::solve() + 80
10 swift-frontend           0x0000000104080c84 (anonymous namespace)::DeinitBarriers::compute() + 60
11 swift-frontend           0x00000001040808e4 (anonymous namespace)::HoistDestroys::perform() + 296
12 swift-frontend           0x00000001040806fc hoistDestroys(swift::SILValue, bool, llvm::SmallPtrSetImpl<swift::SILInstruction*>&, swift::InstructionDeleter&, swift::BasicCalleeAnalysis*) + 492
13 swift-frontend           0x000000010408e978 (anonymous namespace)::DestroyAddrHoisting::run() + 1644
14 swift-frontend           0x0000000103e3e468 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1460
15 swift-frontend           0x0000000103e3f62c swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 796
16 swift-frontend           0x0000000103e434e4 swift::SILPassManager::execute() + 552
17 swift-frontend           0x0000000103e3c4c8 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 380
18 swift-frontend           0x0000000103e3c2bc swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 96
19 swift-frontend           0x0000000103ead5f8 std::__1::tuple<> swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 92
20 swift-frontend           0x0000000103ead55c swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 32
21 swift-frontend           0x0000000103e71158 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 204
22 swift-frontend           0x0000000103e71080 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::operator()<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'(), (void*)0>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 32
23 swift-frontend           0x0000000103e3c5bc swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest) + 32
24 swift-frontend           0x0000000103e3c590 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 124
25 swift-frontend           0x0000000103e911a8 swift::runSILOptimizationPasses(swift::SILModule&) + 196
26 swift-frontend           0x0000000102ba4214 performSILOptimizations(swift::CompilerInvocation&, swift::SILModule*) + 208
27 swift-frontend           0x0000000102ba3ff0 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 184
28 swift-frontend           0x00000001026c2630 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*) + 768
29 swift-frontend           0x00000001026c1ee0 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 672
30 swift-frontend           0x00000001026e455c performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_27::operator()(swift::CompilerInstance&) const + 140
31 swift-frontend           0x00000001026e44c0 bool llvm::function_ref<bool (swift::CompilerInstance&)>::callback_fn<performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*)::$_27>(long, swift::CompilerInstance&) + 32
32 swift-frontend           0x00000001026e3870 llvm::function_ref<bool (swift::CompilerInstance&)>::operator()(swift::CompilerInstance&) const + 40
33 swift-frontend           0x00000001026e2748 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 452
34 swift-frontend           0x00000001026dceb4 performAction(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1268
35 swift-frontend           0x00000001026c41f8 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 256
36 swift-frontend           0x00000001026c3630 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 1876
37 swift-frontend           0x00000001023409c8 run_driver(llvm::StringRef, llvm::ArrayRef<char const*>, llvm::ArrayRef<char const*>) + 324
38 swift-frontend           0x000000010233fddc swift::mainEntry(int, char const**) + 1160
39 swift-frontend           0x000000010233f560 main + 36
40 dyld                     0x000000018bdff154 start + 2476
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: compile command failed due to signal 6 (use -v to see invocation)