diff --git a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h index 52f71a91a1..08c6ae19dd 100644 --- a/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h +++ b/include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.h @@ -42,9 +42,9 @@ class IDELinearConstantAnalysis : public IDETabulationProblem { private: // For debug purpose only - static unsigned CurrGenConstantId; - static unsigned CurrLCAIDId; - static unsigned CurrBinaryId; + static unsigned CurrGenConstantId; // NOLINT + static unsigned CurrLCAIDId; // NOLINT + static unsigned CurrBinaryId; // NOLINT public: using IDETabProblemType = @@ -66,34 +66,37 @@ class IDELinearConstantAnalysis std::set EntryPoints = {"main"}); ~IDELinearConstantAnalysis() override; + IDELinearConstantAnalysis(const IDELinearConstantAnalysis &) = delete; + IDELinearConstantAnalysis & + operator=(const IDELinearConstantAnalysis &) = delete; IDELinearConstantAnalysis & operator=(const IDELinearConstantAnalysis &) = delete; struct LCAResult { LCAResult() = default; - unsigned line_nr = 0; - std::string src_code; - std::map variableToValue; - std::vector ir_trace; - void print(std::ostream &os); - inline bool operator==(const LCAResult &rhs) const { - return src_code == rhs.src_code && - variableToValue == rhs.variableToValue && ir_trace == rhs.ir_trace; + unsigned LineNr = 0; + std::string SrcNode; + std::map VariableToValue; + std::vector IRTrace; + void print(std::ostream &OS); + inline bool operator==(const LCAResult &Rhs) const { + return SrcNode == Rhs.SrcNode && VariableToValue == Rhs.VariableToValue && + IRTrace == Rhs.IRTrace; } operator std::string() const { std::stringstream OS; - OS << "Line " << line_nr << ": " << src_code << '\n'; + OS << "Line " << LineNr << ": " << SrcNode << '\n'; OS << "Var(s): "; - for (auto It = variableToValue.begin(); It != variableToValue.end(); + for (auto It = VariableToValue.begin(); It != VariableToValue.end(); ++It) { - if (It != variableToValue.begin()) { + if (It != VariableToValue.begin()) { OS << ", "; } OS << It->first << " = " << It->second; } OS << "\nCorresponding IR Instructions:\n"; - for (const auto *Ir : ir_trace) { + for (const auto *Ir : IRTrace) { OS << " " << llvmIRToString(Ir) << '\n'; } return OS.str(); @@ -106,52 +109,52 @@ class IDELinearConstantAnalysis // start formulating our analysis by specifying the parts required for IFDS - FlowFunctionPtrType getNormalFlowFunction(n_t curr, n_t succ) override; + FlowFunctionPtrType getNormalFlowFunction(n_t Curr, n_t Succ) override; - FlowFunctionPtrType getCallFlowFunction(n_t callSite, f_t destFun) override; + FlowFunctionPtrType getCallFlowFunction(n_t CallSite, f_t DestFun) override; - FlowFunctionPtrType getRetFlowFunction(n_t callSite, f_t calleeFun, - n_t exitInst, n_t retSite) override; + FlowFunctionPtrType getRetFlowFunction(n_t CallSite, f_t CalleeFun, + n_t ExitInst, n_t RetSite) override; - FlowFunctionPtrType getCallToRetFlowFunction(n_t callSite, n_t retSite, - std::set callees) override; + FlowFunctionPtrType getCallToRetFlowFunction(n_t CallSite, n_t RetSite, + std::set Callees) override; - FlowFunctionPtrType getSummaryFlowFunction(n_t callSite, - f_t destFun) override; + FlowFunctionPtrType getSummaryFlowFunction(n_t CallSite, + f_t DestFun) override; [[nodiscard]] InitialSeeds initialSeeds() override; [[nodiscard]] d_t createZeroValue() const override; - bool isZeroValue(d_t d) const override; + [[nodiscard]] bool isZeroValue(d_t Fact) const override; // in addition provide specifications for the IDE parts std::shared_ptr> - getNormalEdgeFunction(n_t curr, d_t currNode, n_t succ, - d_t succNode) override; + getNormalEdgeFunction(n_t Curr, d_t CurrNode, n_t Succ, + d_t SuccNode) override; std::shared_ptr> - getCallEdgeFunction(n_t callSite, d_t srcNode, f_t destinationFunction, - d_t destNode) override; + getCallEdgeFunction(n_t CallSite, d_t SrcNode, f_t DestinationFunction, + d_t DestNode) override; std::shared_ptr> - getReturnEdgeFunction(n_t callSite, f_t calleeFunction, n_t exitInst, - d_t exitNode, n_t reSite, d_t retNode) override; + getReturnEdgeFunction(n_t CallSite, f_t CalleeFunction, n_t ExitStmt, + d_t ExitNode, n_t RetSite, d_t RetNode) override; std::shared_ptr> - getCallToRetEdgeFunction(n_t callSite, d_t callNode, n_t retSite, - d_t retSiteNode, std::set callees) override; + getCallToRetEdgeFunction(n_t CallSite, d_t CallNode, n_t RetSite, + d_t RetSiteNode, std::set Callees) override; std::shared_ptr> - getSummaryEdgeFunction(n_t callSite, d_t callNode, n_t retSite, - d_t retSiteNode) override; + getSummaryEdgeFunction(n_t CallSite, d_t CallNode, n_t RetSite, + d_t RetSiteNode) override; l_t topElement() override; l_t bottomElement() override; - l_t join(l_t lhs, l_t rhs) override; + l_t join(l_t Lhs, l_t Rhs) override; std::shared_ptr> allTopFunction() override; @@ -164,75 +167,75 @@ class IDELinearConstantAnalysis : EdgeFunctionComposer(F, G){}; std::shared_ptr> - composeWith(std::shared_ptr> secondFunction) override; + composeWith(std::shared_ptr> SecondFunction) override; std::shared_ptr> - joinWith(std::shared_ptr> otherFunction) override; + joinWith(std::shared_ptr> OtherFunction) override; }; class GenConstant : public EdgeFunction, public std::enable_shared_from_this { private: - const unsigned GenConstant_Id; + const unsigned GenConstantId; const l_t IntConst; public: explicit GenConstant(l_t IntConst); - l_t computeTarget(l_t source) override; + l_t computeTarget(l_t Source) override; std::shared_ptr> - composeWith(std::shared_ptr> secondFunction) override; + composeWith(std::shared_ptr> SecondFunction) override; std::shared_ptr> - joinWith(std::shared_ptr> otherFunction) override; + joinWith(std::shared_ptr> OtherFunction) override; - bool equal_to(std::shared_ptr> other) const override; + bool equal_to(std::shared_ptr> Other) const override; - void print(std::ostream &OS, bool isForDebug = false) const override; + void print(std::ostream &OS, bool IsForDebug = false) const override; }; class LCAIdentity : public EdgeFunction, public std::enable_shared_from_this { private: - const unsigned LCAID_Id; + const unsigned LCAIDId; public: explicit LCAIdentity(); - l_t computeTarget(l_t source) override; + l_t computeTarget(l_t Source) override; std::shared_ptr> - composeWith(std::shared_ptr> secondFunction) override; + composeWith(std::shared_ptr> SecondFunction) override; std::shared_ptr> - joinWith(std::shared_ptr> otherFunction) override; + joinWith(std::shared_ptr> OtherFunction) override; - bool equal_to(std::shared_ptr> other) const override; + bool equal_to(std::shared_ptr> Other) const override; - void print(std::ostream &OS, bool isForDebug = false) const override; + void print(std::ostream &OS, bool IsForDebug = false) const override; }; class BinOp : public EdgeFunction, public std::enable_shared_from_this { private: const unsigned EdgeFunctionID, Op; - d_t lop, rop, currNode; + d_t Lop, Rop, CurrNode; public: - BinOp(const unsigned Op, d_t lop, d_t rop, d_t currNode); + BinOp(unsigned Op, d_t Lop, d_t Rop, d_t CurrNode); - l_t computeTarget(l_t source) override; + l_t computeTarget(l_t Source) override; std::shared_ptr> - composeWith(std::shared_ptr> secondFunction) override; + composeWith(std::shared_ptr> SecondFunction) override; std::shared_ptr> - joinWith(std::shared_ptr> otherFunction) override; + joinWith(std::shared_ptr> OtherFunction) override; - bool equal_to(std::shared_ptr> other) const override; + bool equal_to(std::shared_ptr> Other) const override; - void print(std::ostream &OS, bool isForDebug = false) const override; + void print(std::ostream &OS, bool IsForDebug = false) const override; }; // Helper functions @@ -251,19 +254,19 @@ class IDELinearConstantAnalysis * @param rop right operand * @return Result of binary operation */ - static l_t executeBinOperation(const unsigned op, l_t lop, l_t rop); + static l_t executeBinOperation(unsigned Op, l_t Lop, l_t Rop); - static char opToChar(const unsigned op); + static char opToChar(unsigned Op); [[nodiscard]] bool isEntryPoint(const std::string &FunctionName) const; - void printNode(std::ostream &os, n_t n) const override; + void printNode(std::ostream &OS, n_t Stmt) const override; - void printDataFlowFact(std::ostream &os, d_t d) const override; + void printDataFlowFact(std::ostream &OS, d_t Fact) const override; - void printFunction(std::ostream &os, f_t m) const override; + void printFunction(std::ostream &OS, f_t Func) const override; - void printEdgeFact(std::ostream &os, l_t l) const override; + void printEdgeFact(std::ostream &OS, l_t L) const override; [[nodiscard]] lca_results_t getLCAResults(SolverResults SR); diff --git a/lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.cpp b/lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.cpp index a55a26b86a..41faaef951 100644 --- a/lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis.cpp @@ -40,9 +40,9 @@ using namespace psr; namespace psr { // Initialize debug counter for edge functions -unsigned IDELinearConstantAnalysis::CurrGenConstantId = 0; -unsigned IDELinearConstantAnalysis::CurrLCAIDId = 0; -unsigned IDELinearConstantAnalysis::CurrBinaryId = 0; +unsigned IDELinearConstantAnalysis::CurrGenConstantId = 0; // NOLINT +unsigned IDELinearConstantAnalysis::CurrLCAIDId = 0; // NOLINT +unsigned IDELinearConstantAnalysis::CurrBinaryId = 0; // NOLINT const IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::TOP = numeric_limits::min(); @@ -55,7 +55,8 @@ IDELinearConstantAnalysis::IDELinearConstantAnalysis( const LLVMBasedICFG *ICF, LLVMPointsToInfo *PT, std::set EntryPoints) : IDETabulationProblem(IRDB, TH, ICF, PT, std::move(EntryPoints)) { - IDETabulationProblem::ZeroValue = createZeroValue(); + IDETabulationProblem::ZeroValue = + IDELinearConstantAnalysis::createZeroValue(); } IDELinearConstantAnalysis::~IDELinearConstantAnalysis() { @@ -68,7 +69,8 @@ IDELinearConstantAnalysis::~IDELinearConstantAnalysis() { IDELinearConstantAnalysis::FlowFunctionPtrType IDELinearConstantAnalysis::getNormalFlowFunction( - IDELinearConstantAnalysis::n_t Curr, IDELinearConstantAnalysis::n_t Succ) { + IDELinearConstantAnalysis::n_t Curr, + IDELinearConstantAnalysis::n_t /*Succ*/) { if (const auto *Alloca = llvm::dyn_cast(Curr)) { if (Alloca->getAllocatedType()->isIntegerTy()) { return make_shared>(Alloca, @@ -129,7 +131,7 @@ IDELinearConstantAnalysis::getCallFlowFunction( // std::cout << "found call at: " << llvmIRToString(CallSite) << '\n'; // Map the actual parameters into the formal parameters - if (auto *CS = llvm::dyn_cast(CallSite)) { + if (const auto *CS = llvm::dyn_cast(CallSite)) { struct LCAFF : FlowFunction { vector Actuals; @@ -197,8 +199,9 @@ IDELinearConstantAnalysis::getCallFlowFunction( } }; - if (!DestFun->isDeclaration()) + if (!DestFun->isDeclaration()) { return make_shared(CS, DestFun); + } } // Pass everything else as identity return Identity::getInstance(); @@ -207,13 +210,13 @@ IDELinearConstantAnalysis::getCallFlowFunction( IDELinearConstantAnalysis::FlowFunctionPtrType IDELinearConstantAnalysis::getRetFlowFunction( IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::f_t CalleeFun, - IDELinearConstantAnalysis::n_t ExitSite, - IDELinearConstantAnalysis::n_t RetSite) { + IDELinearConstantAnalysis::f_t /*CalleeFun*/, + IDELinearConstantAnalysis::n_t ExitInst, + IDELinearConstantAnalysis::n_t /*RetSite*/) { // Handle the case: %x = call i32 ... if (CallSite->getType()->isIntegerTy()) { - const auto *Return = llvm::dyn_cast(ExitSite); - auto *ReturnValue = Return->getReturnValue(); + const auto *Return = llvm::dyn_cast(ExitInst); + auto *ReturnValue = Return ? Return->getReturnValue() : nullptr; if (ReturnValue) { struct LCAFF : FlowFunction { @@ -253,8 +256,8 @@ IDELinearConstantAnalysis::getRetFlowFunction( IDELinearConstantAnalysis::FlowFunctionPtrType IDELinearConstantAnalysis::getCallToRetFlowFunction( - IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::n_t RetSite, set Callees) { + IDELinearConstantAnalysis::n_t /*CallSite*/, + IDELinearConstantAnalysis::n_t /*RetSite*/, set Callees) { for (const auto *Callee : Callees) { if (!ICF->getStartPointsOf(Callee).empty()) { return make_shared>( @@ -269,8 +272,8 @@ IDELinearConstantAnalysis::getCallToRetFlowFunction( IDELinearConstantAnalysis::FlowFunctionPtrType IDELinearConstantAnalysis::getSummaryFlowFunction( - IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::f_t DestFun) { + IDELinearConstantAnalysis::n_t /*CallSite*/, + IDELinearConstantAnalysis::f_t /*DestFun*/) { return nullptr; } @@ -319,8 +322,8 @@ IDELinearConstantAnalysis::createZeroValue() const { } bool IDELinearConstantAnalysis::isZeroValue( - IDELinearConstantAnalysis::d_t D) const { - return LLVMZeroValue::getInstance()->isLLVMZeroValue(D); + IDELinearConstantAnalysis::d_t Fact) const { + return LLVMZeroValue::getInstance()->isLLVMZeroValue(Fact); } // In addition provide specifications for the IDE parts @@ -329,7 +332,7 @@ shared_ptr> IDELinearConstantAnalysis::getNormalEdgeFunction( IDELinearConstantAnalysis::n_t Curr, IDELinearConstantAnalysis::d_t CurrNode, - IDELinearConstantAnalysis::n_t Succ, + IDELinearConstantAnalysis::n_t /*Succ*/, IDELinearConstantAnalysis::d_t SuccNode) { // ALL_BOTTOM for zero value if ((isZeroValue(CurrNode) && isZeroValue(SuccNode)) || @@ -386,10 +389,9 @@ IDELinearConstantAnalysis::getNormalEdgeFunction( !llvm::isa(Rop)) { return make_shared>( IDELinearConstantAnalysis::BOTTOM); - } else { - return make_shared(OP, Lop, Rop, - CurrNode); } + return make_shared(OP, Lop, Rop, + CurrNode); } LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << "Case: Edge identity."); @@ -401,12 +403,12 @@ shared_ptr> IDELinearConstantAnalysis::getCallEdgeFunction( IDELinearConstantAnalysis::n_t CallSite, IDELinearConstantAnalysis::d_t SrcNode, - IDELinearConstantAnalysis::f_t DestinationFunction, + IDELinearConstantAnalysis::f_t /*DestinationFunction*/, IDELinearConstantAnalysis::d_t DestNode) { // Case: Passing constant integer as parameter if (isZeroValue(SrcNode) && !isZeroValue(DestNode)) { if (const auto *A = llvm::dyn_cast(DestNode)) { - const llvm::CallBase *CS = llvm::cast(CallSite); + const auto *CS = llvm::cast(CallSite); const auto *Actual = CS->getArgOperand(getFunctionArgumentNr(A)); if (const auto *CI = llvm::dyn_cast(Actual)) { auto IntConst = CI->getSExtValue(); @@ -419,15 +421,15 @@ IDELinearConstantAnalysis::getCallEdgeFunction( shared_ptr> IDELinearConstantAnalysis::getReturnEdgeFunction( - IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::f_t CalleeFunction, - IDELinearConstantAnalysis::n_t ExitSite, + IDELinearConstantAnalysis::n_t /*CallSite*/, + IDELinearConstantAnalysis::f_t /*CalleeFunction*/, + IDELinearConstantAnalysis::n_t ExitStmt, IDELinearConstantAnalysis::d_t ExitNode, - IDELinearConstantAnalysis::n_t ReSite, + IDELinearConstantAnalysis::n_t /*RetSite*/, IDELinearConstantAnalysis::d_t RetNode) { // Case: Returning constant integer if (isZeroValue(ExitNode) && !isZeroValue(RetNode)) { - const auto *Return = llvm::cast(ExitSite); + const auto *Return = llvm::cast(ExitStmt); auto *ReturnValue = Return->getReturnValue(); if (auto *CI = llvm::dyn_cast_or_null(ReturnValue)) { auto IntConst = CI->getSExtValue(); @@ -439,20 +441,20 @@ IDELinearConstantAnalysis::getReturnEdgeFunction( shared_ptr> IDELinearConstantAnalysis::getCallToRetEdgeFunction( - IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::d_t CallNode, - IDELinearConstantAnalysis::n_t RetSite, - IDELinearConstantAnalysis::d_t RetSiteNode, - set Callees) { + IDELinearConstantAnalysis::n_t /*CallSite*/, + IDELinearConstantAnalysis::d_t /*CallNode*/, + IDELinearConstantAnalysis::n_t /*RetSite*/, + IDELinearConstantAnalysis::d_t /*RetSiteNode*/, + set /*Callees*/) { return EdgeIdentity::getInstance(); } shared_ptr> IDELinearConstantAnalysis::getSummaryEdgeFunction( - IDELinearConstantAnalysis::n_t CallSite, - IDELinearConstantAnalysis::d_t CallNode, - IDELinearConstantAnalysis::n_t RetSite, - IDELinearConstantAnalysis::d_t RetSiteNode) { + IDELinearConstantAnalysis::n_t /*CallSite*/, + IDELinearConstantAnalysis::d_t /*CallNode*/, + IDELinearConstantAnalysis::n_t /*RetSite*/, + IDELinearConstantAnalysis::d_t /*RetSiteNode*/) { return nullptr; } @@ -467,15 +469,13 @@ IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::bottomElement() { IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::join(IDELinearConstantAnalysis::l_t Lhs, IDELinearConstantAnalysis::l_t Rhs) { - if (Lhs == TOP && Rhs != BOTTOM) { + if ((Rhs == Lhs) || (Lhs == TOP && Rhs != BOTTOM)) { return Rhs; - } else if (Rhs == TOP && Lhs != BOTTOM) { + } + if (Rhs == TOP && Lhs != BOTTOM) { return Lhs; - } else if (Rhs == Lhs) { - return Rhs; - } else { - return BOTTOM; } + return BOTTOM; } shared_ptr> @@ -517,12 +517,12 @@ IDELinearConstantAnalysis::LCAEdgeFunctionComposer::joinWith( IDELinearConstantAnalysis::GenConstant::GenConstant( IDELinearConstantAnalysis::l_t IntConst) - : GenConstant_Id(++IDELinearConstantAnalysis::CurrGenConstantId), + : GenConstantId(++IDELinearConstantAnalysis::CurrGenConstantId), IntConst(IntConst) {} IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::GenConstant::computeTarget( - IDELinearConstantAnalysis::l_t Source) { + IDELinearConstantAnalysis::l_t /*Source*/) { return IntConst; } @@ -569,12 +569,12 @@ bool IDELinearConstantAnalysis::GenConstant::equal_to( } void IDELinearConstantAnalysis::GenConstant::print(ostream &OS, - bool IsForDebug) const { - OS << IntConst << " (EF:" << GenConstant_Id << ')'; + bool /*IsForDebug*/) const { + OS << IntConst << " (EF:" << GenConstantId << ')'; } IDELinearConstantAnalysis::LCAIdentity::LCAIdentity() - : LCAID_Id(++IDELinearConstantAnalysis::CurrLCAIDId) {} + : LCAIDId(++IDELinearConstantAnalysis::CurrLCAIDId) {} IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::LCAIdentity::computeTarget( @@ -609,8 +609,8 @@ bool IDELinearConstantAnalysis::LCAIdentity::equal_to( } void IDELinearConstantAnalysis::LCAIdentity::print(ostream &OS, - bool IsForDebug) const { - OS << "Id (EF:" << LCAID_Id << ')'; + bool /*IsForDebug*/) const { + OS << "Id (EF:" << LCAIDId << ')'; } IDELinearConstantAnalysis::BinOp::BinOp(const unsigned Op, @@ -618,32 +618,35 @@ IDELinearConstantAnalysis::BinOp::BinOp(const unsigned Op, IDELinearConstantAnalysis::d_t Rop, IDELinearConstantAnalysis::d_t CurrNode) : EdgeFunctionID(++IDELinearConstantAnalysis::CurrBinaryId), Op(Op), - lop(Lop), rop(Rop), currNode(CurrNode) {} + Lop(Lop), Rop(Rop), CurrNode(CurrNode) {} IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::BinOp::computeTarget( IDELinearConstantAnalysis::l_t Source) { LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Left Op : " << llvmIRToString(lop)); + << "Left Op : " << llvmIRToString(Lop)); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Right Op : " << llvmIRToString(rop)); + << "Right Op : " << llvmIRToString(Rop)); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) - << "Curr Node : " << llvmIRToString(currNode)); + << "Curr Node : " << llvmIRToString(CurrNode)); LOG_IF_ENABLE(BOOST_LOG_SEV(lg::get(), DEBUG) << ' '); - if (LLVMZeroValue::getInstance()->isLLVMZeroValue(currNode) && - llvm::isa(lop) && llvm::isa(rop)) { - const auto *Lic = llvm::dyn_cast(lop); - const auto *Ric = llvm::dyn_cast(rop); + if (LLVMZeroValue::getInstance()->isLLVMZeroValue(CurrNode) && + llvm::isa(Lop) && llvm::isa(Rop)) { + const auto *Lic = llvm::dyn_cast(Lop); + const auto *Ric = llvm::dyn_cast(Rop); return IDELinearConstantAnalysis::executeBinOperation( Op, Lic->getSExtValue(), Ric->getSExtValue()); - } else if (Source == BOTTOM) { + } + if (Source == BOTTOM) { return BOTTOM; - } else if (lop == currNode && llvm::isa(rop)) { - const auto *Ric = llvm::dyn_cast(rop); + } + if (Lop == CurrNode && llvm::isa(Rop)) { + const auto *Ric = llvm::dyn_cast(Rop); return IDELinearConstantAnalysis::executeBinOperation(Op, Source, Ric->getSExtValue()); - } else if (rop == currNode && llvm::isa(lop)) { - const auto *Lic = llvm::dyn_cast(lop); + } + if (Rop == CurrNode && llvm::isa(Lop)) { + const auto *Lic = llvm::dyn_cast(Lop); return IDELinearConstantAnalysis::executeBinOperation( Op, Lic->getSExtValue(), Source); } @@ -688,24 +691,24 @@ bool IDELinearConstantAnalysis::BinOp::equal_to( shared_ptr> Other) const { if (auto *BOP = dynamic_cast(Other.get())) { - return BOP->Op == this->Op && BOP->lop == this->lop && - BOP->rop == this->rop; + return BOP->Op == this->Op && BOP->Lop == this->Lop && + BOP->Rop == this->Rop; } return this == Other.get(); } void IDELinearConstantAnalysis::BinOp::print(ostream &OS, - bool IsForDebug) const { - if (const auto *LIC = llvm::dyn_cast(lop)) { + bool /*IsForDebug*/) const { + if (const auto *LIC = llvm::dyn_cast(Lop)) { OS << LIC->getSExtValue(); } else { - OS << "ID:" << getMetaDataID(lop); + OS << "ID:" << getMetaDataID(Lop); } OS << ' ' << opToChar(Op) << ' '; - if (const auto *RIC = llvm::dyn_cast(rop)) { + if (const auto *RIC = llvm::dyn_cast(Rop)) { OS << RIC->getSExtValue(); } else { - OS << "ID:" << getMetaDataID(rop); + OS << "ID:" << getMetaDataID(Rop); } } @@ -799,18 +802,18 @@ IDELinearConstantAnalysis::l_t IDELinearConstantAnalysis::executeBinOperation( } void IDELinearConstantAnalysis::printNode( - ostream &OS, IDELinearConstantAnalysis::n_t N) const { - OS << llvmIRToString(N); + ostream &OS, IDELinearConstantAnalysis::n_t Stmt) const { + OS << llvmIRToString(Stmt); } void IDELinearConstantAnalysis::printDataFlowFact( - ostream &OS, IDELinearConstantAnalysis::d_t D) const { - OS << llvmIRToShortString(D); + ostream &OS, IDELinearConstantAnalysis::d_t Fact) const { + OS << llvmIRToShortString(Fact); } void IDELinearConstantAnalysis::printFunction( - ostream &OS, IDELinearConstantAnalysis::f_t M) const { - OS << M->getName().str(); + ostream &OS, IDELinearConstantAnalysis::f_t Func) const { + OS << Func->getName().str(); } void IDELinearConstantAnalysis::printEdgeFact( @@ -904,7 +907,7 @@ IDELinearConstantAnalysis::getLCAResults( } LCAResult *LcaRes = &FResults[Lnr]; // Check if it is a new result - if (LcaRes->src_code.empty()) { + if (LcaRes->SrcNode.empty()) { std::string SourceCode = getSrcCodeFromIR(Stmt); // Skip results for line containing only closed braces which is the // case for functions with void return value @@ -912,10 +915,10 @@ IDELinearConstantAnalysis::getLCAResults( FResults.erase(Lnr); continue; } - LcaRes->src_code = SourceCode; - LcaRes->line_nr = Lnr; + LcaRes->SrcNode = SourceCode; + LcaRes->LineNr = Lnr; } - LcaRes->ir_trace.push_back(Stmt); + LcaRes->IRTrace.push_back(Stmt); if (Stmt->isTerminator() && !ICF->isExitInst(Stmt)) { std::cout << "Delete result since stmt is Terminator or Exit!\n"; FResults.erase(Lnr); @@ -946,19 +949,19 @@ IDELinearConstantAnalysis::getLCAResults( // lcaRes->variableToValue.end()) { ValidVarsAtStmt.insert(VarName); AllocatedVars.insert(VarName); - LcaRes->variableToValue[VarName] = Res.second; + LcaRes->VariableToValue[VarName] = Res.second; } else if (AllocatedVars.find(VarName) == AllocatedVars.end()) { ValidVarsAtStmt.insert(VarName); - LcaRes->variableToValue[VarName] = Res.second; + LcaRes->VariableToValue[VarName] = Res.second; } } } // remove no longer valid variables at current IR stmt - for (auto It = LcaRes->variableToValue.begin(); - It != LcaRes->variableToValue.end();) { + for (auto It = LcaRes->VariableToValue.begin(); + It != LcaRes->VariableToValue.end();) { if (ValidVarsAtStmt.find(It->first) == ValidVarsAtStmt.end()) { std::cout << "Erase var: " << It->first << '\n'; - It = LcaRes->variableToValue.erase(It); + It = LcaRes->VariableToValue.erase(It); } else { ++It; } @@ -967,7 +970,7 @@ IDELinearConstantAnalysis::getLCAResults( } // delete entries with no result for (auto It = FResults.begin(); It != FResults.end();) { - if (It->second.variableToValue.empty()) { + if (It->second.VariableToValue.empty()) { It = FResults.erase(It); } else { ++It; diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysisTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysisTest.cpp index 8db8227140..44af1ab3d7 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysisTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysisTest.cpp @@ -31,19 +31,19 @@ class IDELinearConstantAnalysisTest : public ::testing::Test { IDELinearConstantAnalysis::lca_results_t doAnalysis(const std::string &LlvmFilePath, bool PrintDump = false) { - auto IR_Files = {PathToLlFiles + LlvmFilePath}; - IRDB = std::make_unique(IR_Files, IRDBOptions::WPA); + auto IRFiles = {PathToLlFiles + LlvmFilePath}; + IRDB = std::make_unique(IRFiles, IRDBOptions::WPA); ValueAnnotationPass::resetValueID(); LLVMTypeHierarchy TH(*IRDB); LLVMPointsToSet PT(*IRDB); LLVMBasedICFG ICFG(*IRDB, CallGraphAnalysisType::OTF, {"main"}, &TH, &PT, Soundness::Soundy, /*IncludeGlobals*/ true); - auto hasGlobalCtor = IRDB->getFunctionDefinition( + auto HasGlobalCtor = IRDB->getFunctionDefinition( LLVMBasedICFG::GlobalCRuntimeModelName) != nullptr; IDELinearConstantAnalysis LCAProblem( IRDB.get(), &TH, &ICFG, &PT, - {hasGlobalCtor ? LLVMBasedICFG::GlobalCRuntimeModelName.str() + {HasGlobalCtor ? LLVMBasedICFG::GlobalCRuntimeModelName.str() : "main"}); IDESolver_P LCASolver(LCAProblem); LCASolver.solve(); @@ -71,7 +71,7 @@ class IDELinearConstantAnalysisTest : public ::testing::Test { unsigned Line = std::get<1>(G); if (Results.find(FName) != Results.end()) { if (auto It = Results[FName].find(Line); It != Results[FName].end()) { - for (const auto &VarToVal : It->second.variableToValue) { + for (const auto &VarToVal : It->second.VariableToValue) { RelevantResults.emplace(FName, Line, VarToVal.first, VarToVal.second); } diff --git a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp index 7ecbb11698..f882fd3b30 100644 --- a/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp +++ b/unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDELinearConstantAnalysis_DotTest.cpp @@ -32,9 +32,9 @@ class IDELinearConstantAnalysisTest : public ::testing::Test { IDELinearConstantAnalysis::lca_results_t doAnalysis(const std::string &LlvmFilePath, bool PrintDump = false, - bool emitESG = false) { - auto IR_Files = {PathToLlFiles + LlvmFilePath}; - IRDB = std::make_unique(IR_Files, IRDBOptions::WPA); + bool EmitESG = false) { + auto IRFiles = {PathToLlFiles + LlvmFilePath}; + IRDB = std::make_unique(IRFiles, IRDBOptions::WPA); ValueAnnotationPass::resetValueID(); LLVMTypeHierarchy TH(*IRDB); LLVMPointsToSet PT(*IRDB); @@ -44,7 +44,7 @@ class IDELinearConstantAnalysisTest : public ::testing::Test { EntryPoints); IDESolver_P LCASolver(LCAProblem); LCASolver.solve(); - if (emitESG) { + if (EmitESG) { boost::log::core::get()->set_logging_enabled(true); const std::string PhasarRootPath = "./"; LCASolver.emitESGAsDot(std::cout, PhasarRootPath); @@ -72,7 +72,7 @@ class IDELinearConstantAnalysisTest : public ::testing::Test { unsigned Line = std::get<1>(G); if (Results.find(FName) != Results.end()) { if (auto It = Results[FName].find(Line); It != Results[FName].end()) { - for (const auto &VarToVal : It->second.variableToValue) { + for (const auto &VarToVal : It->second.VariableToValue) { RelevantResults.emplace(FName, Line, VarToVal.first, VarToVal.second); }