From 2e77ea0f447b4749a49aa763cde244494ed75e67 Mon Sep 17 00:00:00 2001 From: mxHuber Date: Thu, 6 Nov 2025 14:02:23 +0100 Subject: [PATCH 1/4] fixed warnings coming from phasar code --- .../DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h | 2 +- .../phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h | 2 +- lib/PhasarLLVM/ControlFlow/GlobalCtorsDtorsModel.cpp | 3 +-- lib/PhasarLLVM/ControlFlow/SVFGCache.cpp | 2 +- .../Problems/IDEGeneralizedLCA/ConstantHelper.cpp | 3 +-- .../Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp | 5 +++-- .../IfdsIde/Problems/IDEInstInteractionAnalysis.cpp | 2 +- .../IfdsIde/Problems/IDELinearConstantAnalysis.cpp | 3 +-- lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp | 3 +-- lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h | 2 +- lib/PhasarLLVM/Utils/Annotation.cpp | 2 +- lib/Utils/PAMM.cpp | 9 +++++---- tools/example-tool/myphasartool.cpp | 2 +- 13 files changed, 19 insertions(+), 21 deletions(-) diff --git a/include/phasar/DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h b/include/phasar/DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h index e78af20707..5bba997606 100644 --- a/include/phasar/DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h +++ b/include/phasar/DataFlow/IfdsIde/DefaultEdgeFunctionSingletonCache.h @@ -46,7 +46,7 @@ class DefaultEdgeFunctionSingletonCacheImpl void insert(const EdgeFunctionTy *EF, const void *Mem) override { assert(EF != nullptr); - auto [It, Inserted] = Cache.try_emplace(EF, Mem); + [[maybe_unused]] auto [It, Inserted] = Cache.try_emplace(EF, Mem); assert(Inserted); } diff --git a/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h b/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h index 9ae1b0a2db..0635bee19d 100644 --- a/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h +++ b/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h @@ -569,7 +569,7 @@ class IterativeIDESolver auto AtInstruction = NodeCompressor[AtInstructionId]; - auto FunId = [=] { + auto FunId = [this] { if constexpr (EnableJumpFunctionGC != JumpFunctionGCMode::Disabled) { auto Ret = FunCompressor.getOrInsert(ICFG.getFunctionOf(AtInstruction)); diff --git a/lib/PhasarLLVM/ControlFlow/GlobalCtorsDtorsModel.cpp b/lib/PhasarLLVM/ControlFlow/GlobalCtorsDtorsModel.cpp index cffe27cb89..be92564c4f 100644 --- a/lib/PhasarLLVM/ControlFlow/GlobalCtorsDtorsModel.cpp +++ b/lib/PhasarLLVM/ControlFlow/GlobalCtorsDtorsModel.cpp @@ -30,8 +30,7 @@ static void insertGlobalCtorsDtorsImpl(MapTy &Into, const llvm::Module &M, return; } - if (const auto *FunArray = - llvm::dyn_cast(Gtors->getValueType())) { + if (llvm::isa(Gtors->getValueType())) { if (const auto *ConstFunArray = llvm::dyn_cast(Gtors->getInitializer())) { for (const auto &Op : ConstFunArray->operands()) { diff --git a/lib/PhasarLLVM/ControlFlow/SVFGCache.cpp b/lib/PhasarLLVM/ControlFlow/SVFGCache.cpp index c7a49c7ac4..97b98e93d9 100644 --- a/lib/PhasarLLVM/ControlFlow/SVFGCache.cpp +++ b/lib/PhasarLLVM/ControlFlow/SVFGCache.cpp @@ -94,7 +94,7 @@ static bool shouldKeepInst(const llvm::Instruction *Inst, const auto *ValTy = Val->getType(); bool ValPtr = ValTy->isPointerTy(); - if (const auto *Call = llvm::dyn_cast(Inst)) { + if (llvm::isa(Inst)) { if (llvm::isa(Val)) { return true; } diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/ConstantHelper.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/ConstantHelper.cpp index 587a3bb2ac..81d4290d5d 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/ConstantHelper.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/ConstantHelper.cpp @@ -32,8 +32,7 @@ bool psr::glca::isConstant(const llvm::Value *Val) { auto *Op1 = Gep->getOperand(0); // op1 is pointer-operand if (auto *Glob = llvm::dyn_cast(Op1); Glob && Glob->hasInitializer()) { - if (auto *Cdat = - llvm::dyn_cast(Glob->getInitializer())) { + if (llvm::isa(Glob->getInitializer())) { return true; // it is definitely a const string } } diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp index 9ca21c73c5..5395cda525 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp @@ -61,7 +61,7 @@ IDEGeneralizedLCA::getNormalFlowFunction(IDEGeneralizedLCA::n_t Curr, const auto *ValueOp = Store->getValueOperand(); if (isConstant(ValueOp)) { // llvm::outs() << "==> constant store" << std::endl; - return lambdaFlow([=](IDEGeneralizedLCA::d_t Source) + return lambdaFlow([this, PointerOp](IDEGeneralizedLCA::d_t Source) -> std::set { // llvm::outs() << "##> normal lambdaFlow for: " << // llvmIRToString(curr) @@ -131,7 +131,8 @@ IDEGeneralizedLCA::getNormalFlowFunction(IDEGeneralizedLCA::n_t Curr, bool NoneConst = !LeftConst && !RightConst; return lambdaFlow( - [=](IDEGeneralizedLCA::d_t Source) -> std::set { + [this, Lhs, Rhs, BothConst, NoneConst, Curr]( + IDEGeneralizedLCA::d_t Source) -> std::set { if (Source == Lhs || Source == Rhs || ((BothConst || NoneConst) && isZeroValue(Source))) { return {Source, Curr}; diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp index 2952fc354f..8cb3908fa0 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDEInstInteractionAnalysis.cpp @@ -35,7 +35,7 @@ IDEIIAFlowFact::IDEIIAFlowFact( } IDEIIAFlowFact IDEIIAFlowFact::create(const llvm::Value *BaseVal) { - if (const auto *Alloca = llvm::dyn_cast(BaseVal)) { + if (llvm::isa(BaseVal)) { return {BaseVal}; } if (const auto *Gep = llvm::dyn_cast(BaseVal)) { diff --git a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp index 107694bd90..465239ef73 100644 --- a/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp +++ b/lib/PhasarLLVM/DataFlow/IfdsIde/Problems/IDELinearConstantAnalysis.cpp @@ -347,8 +347,7 @@ IDELinearConstantAnalysis::getNormalFlowFunction(n_t Curr, n_t /*Succ*/) { /// We are extracting the result of a BinaryOpIntrinsic /// The first parameter holds the resulting integer if /// no error occured during the operation - if (const auto *BinIntrinsic = - llvm::dyn_cast(Agg)) { + if (llvm::isa(Agg)) { if (Extract->getType()->isIntegerTy()) { return generateFlow(Curr, Agg); } diff --git a/lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp b/lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp index c18afd258b..991d9b5b5a 100644 --- a/lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp +++ b/lib/PhasarLLVM/Passes/GeneralStatisticsAnalysis.cpp @@ -105,8 +105,7 @@ GeneralStatistics GeneralStatisticsAnalysis::runOnModule(llvm::Module &M) { } // check for alloca instruction for possible types - if (const llvm::AllocaInst *Alloc = - llvm::dyn_cast(&I)) { + if (llvm::isa(&I)) { // do not add allocas from llvm internal functions Stats.AllocaInstructions.insert(&I); ++Stats.AllocationSites; diff --git a/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h b/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h index 79a6d4574d..47e64f7cae 100644 --- a/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h +++ b/lib/PhasarLLVM/Pointer/FilteredAliasesUtils.h @@ -57,7 +57,7 @@ inline LLVM_LIBRARY_VISIBILITY bool mustNoalias(const llvm::Value *P1, if (llvm::isa(P2) || isConstantGlobalValue(Glob1)) { return true; } - if (const auto *Glob2 = llvm::dyn_cast(P2)) { + if (llvm::isa(P2)) { return true; // approximation } } else if (const auto *Glob2 = llvm::dyn_cast(P2)) { diff --git a/lib/PhasarLLVM/Utils/Annotation.cpp b/lib/PhasarLLVM/Utils/Annotation.cpp index b97f2429a7..0883217d98 100644 --- a/lib/PhasarLLVM/Utils/Annotation.cpp +++ b/lib/PhasarLLVM/Utils/Annotation.cpp @@ -29,7 +29,7 @@ namespace psr { VarAnnotation::VarAnnotation(const llvm::CallBase *AnnotationCall) noexcept : AnnotationCall(AnnotationCall) { - auto *Callee = AnnotationCall->getCalledFunction(); + [[maybe_unused]] auto *Callee = AnnotationCall->getCalledFunction(); assert(Callee && Callee->hasName() && (Callee->getName() == "llvm.var.annotation" || Callee->getName().startswith("llvm.ptr.annotation"))); diff --git a/lib/Utils/PAMM.cpp b/lib/Utils/PAMM.cpp index b1ea931ac2..7d51f7defc 100644 --- a/lib/Utils/PAMM.cpp +++ b/lib/Utils/PAMM.cpp @@ -62,8 +62,8 @@ void PAMM::startTimer(llvm::StringRef TimerId) { } void PAMM::resetTimer(llvm::StringRef TimerId) { - bool InRunningTimers = RunningTimer.erase(TimerId); - bool InStoppedTimers = StoppedTimer.erase(TimerId); + [[maybe_unused]] bool InRunningTimers = RunningTimer.erase(TimerId); + [[maybe_unused]] bool InStoppedTimers = StoppedTimer.erase(TimerId); assert((InRunningTimers && !InStoppedTimers) || (!InRunningTimers && InStoppedTimers) && @@ -149,7 +149,8 @@ std::string PAMM::getPrintableDuration(uint64_t Duration) { } void PAMM::regCounter(llvm::StringRef CounterId, unsigned IntialValue) { - auto [It, Inserted] = Counter.try_emplace(CounterId, IntialValue); + [[maybe_unused]] auto [It, Inserted] = + Counter.try_emplace(CounterId, IntialValue); assert(Inserted && "regCounter failed due to an invalid counter id"); } @@ -214,7 +215,7 @@ PAMM::getSumCount(std::initializer_list CounterIds) { } void PAMM::regHistogram(llvm::StringRef HistogramId) { - auto [It, Inserted] = Histogram.try_emplace(HistogramId); + [[maybe_unused]] auto [It, Inserted] = Histogram.try_emplace(HistogramId); assert(Inserted && "failed to register new histogram due to an invalid id"); } diff --git a/tools/example-tool/myphasartool.cpp b/tools/example-tool/myphasartool.cpp index 8080dabbe1..d8eccad7d1 100644 --- a/tools/example-tool/myphasartool.cpp +++ b/tools/example-tool/myphasartool.cpp @@ -32,7 +32,7 @@ int main(int Argc, const char **Argv) { return 1; } - if (const auto *F = HA.getProjectIRDB().getFunctionDefinition("main")) { + if (HA.getProjectIRDB().getFunctionDefinition("main")) { // print type hierarchy HA.getTypeHierarchy().print(); // print points-to information From 99503430bb0c37fe8ef878f28e4e20dadd405a17 Mon Sep 17 00:00:00 2001 From: mxHuber Date: Thu, 6 Nov 2025 14:25:56 +0100 Subject: [PATCH 2/4] Fixed error + missed Z3 warnings --- .../phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h | 2 +- .../DataFlow/PathSensitivity/LLVMPathConstraints.cpp | 3 +-- .../PathSensitivity/Z3BasedPathSensitivityManager.cpp | 8 ++++---- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h b/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h index 0635bee19d..2fab0ac482 100644 --- a/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h +++ b/include/phasar/DataFlow/IfdsIde/Solver/IterativeIDESolver.h @@ -569,7 +569,7 @@ class IterativeIDESolver auto AtInstruction = NodeCompressor[AtInstructionId]; - auto FunId = [this] { + auto FunId = [&] { if constexpr (EnableJumpFunctionGC != JumpFunctionGCMode::Disabled) { auto Ret = FunCompressor.getOrInsert(ICFG.getFunctionOf(AtInstruction)); diff --git a/lib/PhasarLLVM/DataFlow/PathSensitivity/LLVMPathConstraints.cpp b/lib/PhasarLLVM/DataFlow/PathSensitivity/LLVMPathConstraints.cpp index 9ea5c94fcc..f1ef9ee1c3 100644 --- a/lib/PhasarLLVM/DataFlow/PathSensitivity/LLVMPathConstraints.cpp +++ b/lib/PhasarLLVM/DataFlow/PathSensitivity/LLVMPathConstraints.cpp @@ -609,8 +609,7 @@ auto LLVMPathConstraints::getGEPInstAsZ3(const llvm::GetElementPtrInst *GEP) .first->second; } // some other pointer, we can treat those as integers - if (const auto *PointerTy = - llvm::dyn_cast(GEP->getPointerOperandType())) { + if (llvm::isa(GEP->getPointerOperandType())) { auto PointerConst = Z3Ctx->bv_const(Name.c_str(), 64); return Z3Expr.try_emplace(GEP, ConstraintAndVariables{PointerConst, {GEP}}) .first->second; diff --git a/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp b/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp index 801a8e10f1..f9b002df47 100644 --- a/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp +++ b/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp @@ -55,7 +55,7 @@ z3::expr Z3BasedPathSensitivityManagerBase::filterOutUnreachableNodes( llvm::SmallVector Ys; - for (auto Iter = graph_traits_t::outEdges(RevDAG, Vtx).begin(); + for (const auto *Iter = graph_traits_t::outEdges(RevDAG, Vtx).begin(); Iter != graph_traits_t::outEdges(RevDAG, Vtx).end();) { // NOLINTNEXTLINE(readability-qualified-auto, llvm-qualified-auto) auto It = Iter++; @@ -103,7 +103,7 @@ z3::expr Z3BasedPathSensitivityManagerBase::filterOutUnreachableNodes( z3::expr Ret = LPC.getContext().bool_val(false); - for (auto Iter = graph_traits_t::roots(RevDAG).begin(); + for (const auto *Iter = graph_traits_t::roots(RevDAG).begin(); Iter != graph_traits_t::roots(RevDAG).end();) { // NOLINTNEXTLINE(readability-qualified-auto, llvm-qualified-auto) auto It = Iter++; @@ -322,7 +322,7 @@ class ConstraintPathFilter { ConstraintPathFilter(LLVMPathConstraints &LPC, const z3::expr &AdditionalConstraint, - size_t *CompletedCtr) noexcept + const size_t *CompletedCtr) noexcept : LPC(LPC), Solver(LPC.getContext()), CompletedCtr(*CompletedCtr) { Solver.add(AdditionalConstraint); Solver.push(); @@ -450,7 +450,7 @@ class ConstraintPathFilter { size_t Ctr = 0; size_t RejectedCtr = 0; size_t IsValidCalls = 0; - size_t &CompletedCtr; + const size_t &CompletedCtr; }; auto Z3BasedPathSensitivityManagerBase::filterAndFlattenRevDag( From 5379d8a5d211585535d54127edfa7840b9855569 Mon Sep 17 00:00:00 2001 From: mxHuber Date: Thu, 6 Nov 2025 14:55:02 +0100 Subject: [PATCH 3/4] changed tmpnam for mkstemp + maybe unused flags --- .../PathSensitivity/PathSensitivityManagerMixin.h | 10 +++++++++- .../PathSensitivity/Z3BasedPathSensitivityManager.cpp | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h b/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h index 74ed9e1c51..34a007e6fb 100644 --- a/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h +++ b/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h @@ -92,7 +92,15 @@ class PathSensitivityManagerMixin { llvm::errs() << "Fatal error occurred. Writing ESG to temp file...\n"; llvm::errs().flush(); - auto FileName = std::string(tmpnam(nullptr)) + "-explicitesg-err.dot"; + char FileName[] = "/tmp/explicitesg-err.dot.XXXXXX"; + int FileStatus = mkstemp(FileName); + + if (FileStatus == -1) { + llvm::errs() << "Fatal error occurred. Temp file for ESG could not " + "be openend...\n"; + llvm::errs().flush(); + abort(); + } { std::error_code EC; diff --git a/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp b/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp index f9b002df47..65c121163c 100644 --- a/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp +++ b/lib/PhasarLLVM/DataFlow/PathSensitivity/Z3BasedPathSensitivityManager.cpp @@ -29,7 +29,7 @@ z3::expr Z3BasedPathSensitivityManagerBase::filterOutUnreachableNodes( Ctx.Visited.resize(graph_traits_t::size(RevDAG)); Ctx.NodeConstraints.resize(graph_traits_t::size(RevDAG), Ctx.True); - size_t TotalNumEdges = 0; + [[maybe_unused]] size_t TotalNumEdges = 0; for (auto I : graph_traits_t::vertices(RevDAG)) { TotalNumEdges += graph_traits_t::outDegree(RevDAG, I); } @@ -450,7 +450,7 @@ class ConstraintPathFilter { size_t Ctr = 0; size_t RejectedCtr = 0; size_t IsValidCalls = 0; - const size_t &CompletedCtr; + [[maybe_unused]] const size_t &CompletedCtr; }; auto Z3BasedPathSensitivityManagerBase::filterAndFlattenRevDag( From c6d3e0469a75d9512b23b6c2ac9da95522b323c3 Mon Sep 17 00:00:00 2001 From: mxHuber Date: Fri, 7 Nov 2025 16:05:51 +0100 Subject: [PATCH 4/4] removed mkstemp, print ESG to llvm::errs() --- .../PathSensitivityManagerMixin.h | 21 ++----------------- 1 file changed, 2 insertions(+), 19 deletions(-) diff --git a/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h b/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h index 34a007e6fb..761d7a88de 100644 --- a/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h +++ b/include/phasar/DataFlow/PathSensitivity/PathSensitivityManagerMixin.h @@ -89,26 +89,9 @@ class PathSensitivityManagerMixin { if (LLVM_UNLIKELY(!Nod)) { llvm::errs() << "Invalid Instruction-FlowFact pair. Only use those " "pairs that are part of the IDE analysis results!\n"; - llvm::errs() << "Fatal error occurred. Writing ESG to temp file...\n"; - llvm::errs().flush(); - - char FileName[] = "/tmp/explicitesg-err.dot.XXXXXX"; - int FileStatus = mkstemp(FileName); - - if (FileStatus == -1) { - llvm::errs() << "Fatal error occurred. Temp file for ESG could not " - "be openend...\n"; - llvm::errs().flush(); - abort(); - } - - { - std::error_code EC; - llvm::raw_fd_ostream ROS(FileName, EC); - ESG.printAsDot(ROS); - } + llvm::errs() << "Fatal error occurred. Printing ESG ...\n"; - llvm::errs() << "> ESG written to " << FileName << '\n'; + ESG.printAsDot(llvm::errs()); llvm::errs().flush(); abort();