@@ -232,8 +232,16 @@ struct MacroInfo {
232
232
};
233
233
}
234
234
235
+ static DeclContext *getInnermostFunctionContext (DeclContext *DC) {
236
+ for (; DC; DC = DC->getParent ())
237
+ if (DC->getContextKind () == DeclContextKind::AbstractFunctionDecl)
238
+ return DC;
239
+ return nullptr ;
240
+ }
241
+
235
242
// / Return location of the macro expansion and the macro name.
236
- static MacroInfo getMacroInfo (GeneratedSourceInfo &Info) {
243
+ static MacroInfo getMacroInfo (GeneratedSourceInfo &Info,
244
+ DeclContext *FunctionDC) {
237
245
MacroInfo Result (Info.generatedSourceRange .getStart (),
238
246
Info.originalSourceRange .getStart ());
239
247
if (!Info.astNode )
@@ -252,6 +260,13 @@ static MacroInfo getMacroInfo(GeneratedSourceInfo &Info) {
252
260
Result.ExpansionLoc = RegularLocation (decl);
253
261
Result.Name = mangler.mangleMacroExpansion (decl);
254
262
}
263
+ // If the parent function of the macro expansion expression is not the
264
+ // current function, then the macro expanded to a closure or nested
265
+ // function. As far as the generated SIL is concerned this is the same as a
266
+ // function generated from a freestanding macro expansion.
267
+ DeclContext *MacroContext = getInnermostFunctionContext (Info.declContext );
268
+ if (MacroContext != FunctionDC)
269
+ Result.Freestanding = true ;
255
270
break ;
256
271
}
257
272
case GeneratedSourceInfo::FreestandingDeclMacroExpansion: {
@@ -295,7 +310,7 @@ const SILDebugScope *SILGenFunction::getMacroScope(SourceLoc SLoc) {
295
310
// declaration that isn't part of a real function. By not handling them here,
296
311
// source locations will still point into the macro expansion buffer, but
297
312
// debug info doesn't know what macro that buffer was expanded from.
298
- auto Macro = getMacroInfo (*GeneratedSourceInfo);
313
+ auto Macro = getMacroInfo (*GeneratedSourceInfo, FunctionDC );
299
314
if (Macro.Freestanding )
300
315
return nullptr ;
301
316
0 commit comments