@@ -193,13 +193,21 @@ class FindAccessVisitorImpl : public AccessUseDefChainVisitor<Impl, SILValue> {
193193
194194 // Override AccessUseDefChainVisitor to ignore access markers and find the
195195 // outer access base.
196- SILValue visitNestedAccess (BeginAccessInst *access) {
196+ SILValue visitNestedAccessImpl (BeginAccessInst *access) {
197197 if (nestedAccessTy == NestedAccessType::IgnoreAccessBegin)
198198 return access->getSource ();
199199
200200 return SuperTy::visitNestedAccess (access);
201201 }
202202
203+ SILValue visitNestedAccess (BeginAccessInst *access) {
204+ auto value = visitNestedAccessImpl (access);
205+ if (value) {
206+ reenterUseDef (value);
207+ }
208+ return SILValue ();
209+ }
210+
203211 SILValue visitPhi (SILPhiArgument *phiArg) {
204212 // Cycles involving phis are only handled within AccessPhiVisitor.
205213 // Path components are not allowed in phi cycles.
@@ -362,6 +370,18 @@ SILValue swift::getTypedAccessAddress(SILValue address) {
362370 return accessAddress;
363371}
364372
373+ namespace swift ::test {
374+ static FunctionTest
375+ GetTypedAccessAddress (" get_typed_access_address" ,
376+ [](auto &function, auto &arguments, auto &test) {
377+ auto address = arguments.takeValue ();
378+ function.dump ();
379+ llvm::dbgs () << " Address: " << address;
380+ auto access = getTypedAccessAddress (address);
381+ llvm::dbgs () << " Access: " << access;
382+ });
383+ } // end namespace swift::test
384+
365385// TODO: When the optimizer stops stripping begin_access markers and SILGen
366386// protects all memory operations with at least an "unsafe" access scope, then
367387// we should be able to assert that this returns a BeginAccessInst.
@@ -379,6 +399,18 @@ SILValue swift::getAccessBase(SILValue address) {
379399 .findPossibleBaseAddress (address);
380400}
381401
402+ namespace swift ::test {
403+ static FunctionTest GetAccessBaseTest (" get_access_base" ,
404+ [](auto &function, auto &arguments,
405+ auto &test) {
406+ auto address = arguments.takeValue ();
407+ function.dump ();
408+ llvm::dbgs () << " Address: " << address;
409+ auto base = getAccessBase (address);
410+ llvm::dbgs () << " Base: " << base;
411+ });
412+ } // end namespace swift::test
413+
382414static bool isLetForBase (SILValue base) {
383415 // Is this an address of a "let" class member?
384416 if (auto *rea = dyn_cast<RefElementAddrInst>(base))
@@ -1156,6 +1188,18 @@ AccessStorage AccessStorage::compute(SILValue sourceAddress) {
11561188 return AccessStorageWithBase::compute (sourceAddress).storage ;
11571189}
11581190
1191+ namespace swift ::test {
1192+ static FunctionTest ComputeAccessStorage (" compute_access_storage" ,
1193+ [](auto &function, auto &arguments,
1194+ auto &test) {
1195+ auto address = arguments.takeValue ();
1196+ function.dump ();
1197+ llvm::dbgs () << " Address: " << address;
1198+ auto accessStorage = AccessStorage::compute (address);
1199+ accessStorage.dump ();
1200+ });
1201+ } // end namespace swift::test
1202+
11591203AccessStorage AccessStorage::computeInScope (SILValue sourceAddress) {
11601204 return AccessStorageWithBase::computeInScope (sourceAddress).storage ;
11611205}
0 commit comments