@@ -91,7 +91,7 @@ static void getVariableNameForValue(SILValue value2,
9191 // operand.
9292 StackList<llvm::PointerUnion<SILInstruction *, SILValue>> variableNamePath (
9393 value2->getFunction ());
94- while (true ) {
94+ while (searchValue ) {
9595 if (auto *allocInst = dyn_cast<AllocationInst>(searchValue)) {
9696 // If the instruction itself doesn't carry any variable info, see whether
9797 // it's copied from another place that does.
@@ -130,18 +130,44 @@ static void getVariableNameForValue(SILValue value2,
130130 variableNamePath.push_back ({fArg });
131131 break ;
132132 }
133-
134- if ( auto bai = dyn_cast_or_null<BeginApplyInst>(searchValue-> getDefiningInstruction ())) {
133+
134+ auto getNamePathComponentFromCallee = [&](FullApplySite call) -> llvm::Optional<SILValue> {
135135 // Use the name of the property being accessed if we can get to it.
136- if (isa<FunctionRefBaseInst>(bai-> getCallee ())
137- || isa<MethodInst>(bai-> getCallee ())) {
138- variableNamePath.push_back (bai-> getCallee ()->getDefiningInstruction ());
136+ if (isa<FunctionRefBaseInst>(call. getCallee ())
137+ || isa<MethodInst>(call. getCallee ())) {
138+ variableNamePath.push_back (call. getCallee ()->getDefiningInstruction ());
139139 // Try to name the base of the property if this is a method.
140- if (bai->getSubstCalleeType ()->hasSelfParam ()) {
141- searchValue = bai->getSelfArgument ();
142- continue ;
140+ if (call.getSubstCalleeType ()->hasSelfParam ()) {
141+ return call.getSelfArgument ();
143142 } else {
144- break ;
143+ return SILValue ();
144+ }
145+ }
146+ return llvm::None;
147+ };
148+
149+ // Read or modify accessor.
150+ if (auto bai = dyn_cast_or_null<BeginApplyInst>(searchValue->getDefiningInstruction ())) {
151+ if (auto selfParam = getNamePathComponentFromCallee (bai)) {
152+ searchValue = *selfParam;
153+ continue ;
154+ }
155+ }
156+
157+ // Addressor accessor.
158+ if (auto ptrToAddr = dyn_cast<PointerToAddressInst>(stripAccessMarkers (searchValue))) {
159+ // The addressor can either produce the raw pointer itself or an `UnsafePointer` stdlib type wrapping it.
160+ ApplyInst *addressorInvocation;
161+ if (auto structExtract = dyn_cast<StructExtractInst>(ptrToAddr->getOperand ())) {
162+ addressorInvocation = dyn_cast<ApplyInst>(structExtract->getOperand ());
163+ } else {
164+ addressorInvocation = dyn_cast<ApplyInst>(ptrToAddr->getOperand ());
165+ }
166+
167+ if (addressorInvocation) {
168+ if (auto selfParam = getNamePathComponentFromCallee (addressorInvocation)) {
169+ searchValue = *selfParam;
170+ continue ;
145171 }
146172 }
147173 }
0 commit comments