SILGen: Mark function escapes for script globals captured by closures.

We did this for func decls in script, so that DI can flag func decls that access script globals before they've been initialized, but we failed to do so for closures, causing us to miss DI violations when closures referenced script globals before their initialization. Fixes rdar://problem/24357063.
This commit is contained in:
Joe Groff
2016-04-28 11:28:20 -07:00
parent 16a875930b
commit df39c3e043
6 changed files with 91 additions and 22 deletions

View File

@@ -378,6 +378,14 @@ SILGenFunction::emitClosureValue(SILLocation loc, SILDeclRef constant,
wasSpecialized = true;
}
// If we're in top-level code, we don't need to physically capture script
// globals, but we still need to mark them as escaping so that DI can flag
// uninitialized uses.
if (this == SGM.TopLevelSGF) {
SGM.emitMarkFunctionEscapeForTopLevelCodeGlobals(loc,
TheClosure.getCaptureInfo());
}
if (!TheClosure.getCaptureInfo().hasLocalCaptures() && !wasSpecialized) {
auto result = ManagedValue::forUnmanaged(functionRef);
return emitOrigToSubstValue(loc, result,