@@ -152,6 +152,8 @@ static SourceLoc inferOptRemarkSearchForwards(SILInstruction &i) {
152152 for (auto &inst :
153153 llvm::make_range (std::next (i.getIterator ()), i.getParent ()->end ())) {
154154 auto newLoc = inst.getLoc ().getSourceLoc ();
155+ if (auto inlinedLoc = inst.getDebugScope ()->getOutermostInlineLocation ())
156+ newLoc = inlinedLoc.getSourceLoc ();
155157 if (newLoc.isValid ())
156158 return newLoc;
157159 }
@@ -167,7 +169,9 @@ static SourceLoc inferOptRemarkSearchBackwards(SILInstruction &i) {
167169 for (auto &inst : llvm::make_range (std::next (i.getReverseIterator ()),
168170 i.getParent ()->rend ())) {
169171 auto loc = inst.getLoc ();
170- if (!bool (loc))
172+ if (auto inlinedLoc = inst.getDebugScope ()->getOutermostInlineLocation ())
173+ loc = inlinedLoc;
174+ if (!loc.getSourceLoc ().isValid ())
171175 continue ;
172176
173177 auto range = loc.getSourceRange ();
@@ -180,31 +184,35 @@ static SourceLoc inferOptRemarkSearchBackwards(SILInstruction &i) {
180184
181185SourceLoc swift::OptRemark::inferOptRemarkSourceLoc (
182186 SILInstruction &i, SourceLocInferenceBehavior inferBehavior) {
183- auto loc = i.getLoc ().getSourceLoc ();
184-
185- // Do a quick check if we already have a valid loc. In such a case, just
186- // return. Otherwise, we try to infer using one of our heuristics below.
187- if (loc.isValid ())
188- return loc;
187+ // Do a quick check if we already have a valid loc and it isnt an inline
188+ // loc. In such a case, just return. Otherwise, we try to infer using one of
189+ // our heuristics below.
190+ auto loc = i.getLoc ();
191+ if (loc.getSourceLoc ().isValid ()) {
192+ // Before we do anything, if we do not have an inlined call site, just
193+ // return our loc.
194+ if (!i.getDebugScope () || !i.getDebugScope ()->InlinedCallSite )
195+ return loc.getSourceLoc ();
196+ }
189197
190198 // Otherwise, try to handle the individual behavior cases, returning loc at
191199 // the end of each case (its invalid, so it will get ignored). If loc is not
192200 // returned, we hit an assert at the end to make it easy to identify a case
193201 // was missed.
194202 switch (inferBehavior) {
195203 case SourceLocInferenceBehavior::None:
196- return loc ;
204+ return SourceLoc () ;
197205 case SourceLocInferenceBehavior::ForwardScanOnly: {
198206 SourceLoc newLoc = inferOptRemarkSearchForwards (i);
199207 if (newLoc.isValid ())
200208 return newLoc;
201- return loc ;
209+ return SourceLoc () ;
202210 }
203211 case SourceLocInferenceBehavior::BackwardScanOnly: {
204212 SourceLoc newLoc = inferOptRemarkSearchBackwards (i);
205213 if (newLoc.isValid ())
206214 return newLoc;
207- return loc ;
215+ return SourceLoc () ;
208216 }
209217 case SourceLocInferenceBehavior::ForwardThenBackward: {
210218 SourceLoc newLoc = inferOptRemarkSearchForwards (i);
@@ -213,7 +221,7 @@ SourceLoc swift::OptRemark::inferOptRemarkSourceLoc(
213221 newLoc = inferOptRemarkSearchBackwards (i);
214222 if (newLoc.isValid ())
215223 return newLoc;
216- return loc ;
224+ return SourceLoc () ;
217225 }
218226 case SourceLocInferenceBehavior::BackwardThenForward: {
219227 SourceLoc newLoc = inferOptRemarkSearchBackwards (i);
@@ -222,7 +230,7 @@ SourceLoc swift::OptRemark::inferOptRemarkSourceLoc(
222230 newLoc = inferOptRemarkSearchForwards (i);
223231 if (newLoc.isValid ())
224232 return newLoc;
225- return loc ;
233+ return SourceLoc () ;
226234 }
227235 }
228236
0 commit comments