Skip to content

Commit

Permalink
[PM] Add a small verification method to ensure that analysis run on f…
Browse files Browse the repository at this point in the history
…uncs with bodies.

Add a small verification method that checks that we run our function analysis
only on functions with bodies (not on external definitions). I ran into this bug
when working on the pass manager.
  • Loading branch information
nadavrot committed Nov 25, 2015
1 parent b2fd1ec commit 300ab4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/swift/SILAnalysis/Analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ namespace swift {
/// default so that only functions which are able to provide the function
/// specific verification will do so.
virtual void verify(SILFunction *F) const { verify(); }

/// Verify that the function \p F can be used by the analysis.
static void verifyFunction(SILFunction *F);
};

/// An abstract base class that implements the boiler plate of cacheing and
Expand All @@ -152,6 +155,10 @@ namespace swift {
public:
/// Returns an analysis provider for a specific function \p F.
AnalysisTy *get(SILFunction *F) {

// Check that the analysis can handle this function.
verifyFunction(F);

auto &it = Storage.FindAndConstruct(F);
if (!it.second)
it.second = newFunctionAnalysis(F);
Expand Down
5 changes: 5 additions & 0 deletions lib/SILAnalysis/Analysis.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@

using namespace swift;

void SILAnalysis::verifyFunction(SILFunction *F) {
// Only functions with bodies can be analyzed by the analysis.
assert(F->isDefinition() && "Can't analyze external functions");
}

SILAnalysis *swift::createCallGraphAnalysis(SILModule *M) {
return new CallGraphAnalysis(M);
}
Expand Down

0 comments on commit 300ab4d

Please sign in to comment.