Skip to content

[SILProfiler] Don't crash when coverage info for lazy getters is inco… #18744

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions lib/SIL/SILProfiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,16 @@ struct MapRegionCounters : public ASTWalker {
} else if (auto *ACE = dyn_cast<AbstractClosureExpr>(E)) {
return visitClosureExpr(*this, ACE, [&] { mapRegion(ACE); });
}

// rdar://42792053
// TODO: There's an outstanding issue here with LazyInitializerExpr. A LIE
// is copied into the body of a property getter after type-checking (before
// coverage). ASTWalker only visits this expression once via the property's
// VarDecl, and does not visit it again within the getter. This results in
// missing coverage. SILGen treats the init expr as part of the getter, but
// its SILProfiler has no information about the init because the LIE isn't
// visited here.

return {true, E};
}
};
Expand Down
6 changes: 4 additions & 2 deletions lib/SILGen/SILGenFunction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,10 @@ void SILGenFunction::emitProfilerIncrement(ASTNode N) {
auto &C = B.getASTContext();
const auto &RegionCounterMap = SP->getRegionCounterMap();
auto CounterIt = RegionCounterMap.find(N);
assert(CounterIt != RegionCounterMap.end() &&
"cannot increment non-existent counter");

// TODO: Assert that this cannot happen (rdar://42792053).
if (CounterIt == RegionCounterMap.end())
return;

auto Int32Ty = getLoweredType(BuiltinIntegerType::get(32, C));
auto Int64Ty = getLoweredType(BuiltinIntegerType::get(64, C));
Expand Down
8 changes: 8 additions & 0 deletions test/Profiler/coverage_class.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,11 @@ struct S2 {
// CHECK-NEXT: [[@LINE+1]]:26 -> [[@LINE+1]]:27 : (1 - 0)
var m1: Int = g1 ? 0 : 1
}

// Test that the crash from SR-8429 is avoided. Follow-up work is
// needed to generate the correct coverage mapping here. Coverage for
// `offset` should be associated with its getter, not the class
// constructor.
class C2 {
lazy var offset: Int = true ? 30 : 55
}