Skip to content

Commit

Permalink
[Coverage] Do not map function decls with no body
Browse files Browse the repository at this point in the history
We can't place counters on function decls with no bodies. The old
behavior was to map a fresh counter to a null AST node, which is highly
suspicious at best.
  • Loading branch information
vedantk committed Sep 12, 2016
1 parent bf82df6 commit 9c44714
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/SILGen/SILGenProfiling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ using namespace swift;
using namespace Lowering;

static bool isUnmappedDecl(Decl *D) {
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(D))
if (!AFD->getBody())
return true;

if (isa<ConstructorDecl>(D) || isa<DestructorDecl>(D))
return false;

Expand Down
6 changes: 6 additions & 0 deletions test/SILGen/coverage_closures.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,11 @@ func foo() {
f1 { left, right in left == 0 || right == 1 }
}

// SR-2615: Implicit constructor decl has no body, and shouldn't be mapped
struct C1 {
// CHECK-NOT: sil_coverage_map{{.*}}errors
private var errors = [String]()
}

bar(arr: [{ x in x }])
foo()

0 comments on commit 9c44714

Please sign in to comment.