Skip to content

Commit

Permalink
fix(devirt): resolve only if type-compatible callee
Browse files Browse the repository at this point in the history
  • Loading branch information
caballa committed Oct 25, 2022
1 parent ed76603 commit 156e5f1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions lib/seadsa/DsaCompleteCallGraph.cc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "llvm/Pass.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Transforms/Utils/CallPromotionUtils.h"

#include "seadsa/AllocWrapInfo.hh"
#include "seadsa/CallGraphUtils.hh"
Expand Down Expand Up @@ -534,15 +535,18 @@ bool CompleteCallGraphAnalysis::runOnModule(Module &M) {
for (const Value *v : alloc_sites) {
if (const Function *fn =
dyn_cast<Function>(v->stripPointerCastsAndAliases())) {
foundAtLeastOneCallee = true;
CallGraphNode *CGNCallee = (*m_complete_cg)[fn];
assert(CGNCallee);
if (!hasEdge(CGNCaller, CGNCallee, CGNCB)) {
assert(cb);
CGNCaller->addCalledFunction(cb, CGNCallee);
m_callees[cs.getInstruction()].push_back(fn);
change = true;
}
// Check that the callbase and the callee are type-compatible
if (isLegalToPromote(*cb, const_cast<Function*>(fn))) {
foundAtLeastOneCallee = true;
CallGraphNode *CGNCallee = (*m_complete_cg)[fn];
assert(CGNCallee);
if (!hasEdge(CGNCaller, CGNCallee, CGNCB)) {
assert(cb);
CGNCaller->addCalledFunction(cb, CGNCallee);
m_callees[cs.getInstruction()].push_back(fn);
change = true;
}
}
}
}

Expand Down

0 comments on commit 156e5f1

Please sign in to comment.