From ad688ef611beb3572facac6d1578dd0d2c7e6dca Mon Sep 17 00:00:00 2001 From: caballa Date: Thu, 14 Sep 2023 21:14:34 -0600 Subject: [PATCH] fix(complete-cg): strip bitcasts We need to strip bitcasts in order to resolve trivial indirect calls. We modified the code that strips bitcasts to catch all patterns from the test suite. --- lib/seadsa/DsaCompleteCallGraph.cc | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/lib/seadsa/DsaCompleteCallGraph.cc b/lib/seadsa/DsaCompleteCallGraph.cc index 7673a7b..7bdbbce 100644 --- a/lib/seadsa/DsaCompleteCallGraph.cc +++ b/lib/seadsa/DsaCompleteCallGraph.cc @@ -65,28 +65,25 @@ static const Value *findUniqueReturnValue(const Function &F) { return onlyRetVal; } -static Value *stripBitCast(Value *V) { - if (ConstantExpr *CE = dyn_cast(V)) { - if (CE->isCast()) { - return CE->getOperand(0); - } - } - if (BitCastInst *BC = dyn_cast(V)) { - return BC->getOperand(0); - } - return V; -} - - static void resolveIndirectCallsThroughBitCast(Function &F, CallGraph &seaCg) { // Resolve trivial indirect calls through bitcasts: // call void (...) bitcast (void ()* @parse_dir_colors to void (...)*)() + // call i32 bitcast (i32 (...)* @nd_uint to i32 ()*)() + // call i32 (i32, i32)* bitcast (i32 (i32, i32)* (...)* @nd_binfptr to i32 (i32, i32)* ()*)() // // This is important because our top-down/bottom-up analyses // traverse the call graph in a particular order (topological or // reverse topological). If these edges are missing then the // propagation can be done "too early" without analyzing the caller // or callee yet. + auto stripBitCast = [](Value *V) { + if (BitCastInst *BC = dyn_cast(V)) { + return BC->getOperand(0); + } else { + return V->stripPointerCasts(); + } + }; + for (auto &I : llvm::make_range(inst_begin(&F), inst_end(&F))) { if (!(isa(I) || isa(I))) continue; CallBase &CB = *dyn_cast(&I);