diff --git a/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp b/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp index b96f862b23b63..923c19dad59c7 100644 --- a/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp +++ b/lib/SILOptimizer/Transforms/DeadObjectElimination.cpp @@ -351,6 +351,8 @@ static bool onlyStoresToTailObjects(BuiltinInst *destroyArray, // Check if the destroyArray destroys the tail elements of allocRef. auto destroyPath = AccessPath::compute(destroyArray->getArguments()[1]); + if (!destroyPath.isValid()) + return false; AccessStorage storage = destroyPath.getStorage(); if (auto *beginDealloc = dyn_cast(storage.getRoot())) { destroyPath = AccessPath( diff --git a/validation-test/SILOptimizer/rdar162237650.swift b/validation-test/SILOptimizer/rdar162237650.swift new file mode 100644 index 0000000000000..f15fab47c20ad --- /dev/null +++ b/validation-test/SILOptimizer/rdar162237650.swift @@ -0,0 +1,17 @@ +// RUN: %target-swift-frontend -c -O %s -target %target-swift-6.0-abi-triple + +// REQUIRES: synchronization + +import Synchronization + +class Locked { + let mutex: Mutex + + init(_ rawValue: T) { + mutex = Mutex(rawValue) + } +} + +class Foo {} + +_ = Locked(Foo())