Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Modernize UninitializedVariables Analysis #616

Draft
wants to merge 8 commits into
base: development
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@

#include "phasar/DataFlow/IfdsIde/IFDSTabulationProblem.h"
#include "phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h"
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"

#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/Support/raw_ostream.h"

#include <map>
#include <memory>
Expand All @@ -29,16 +34,23 @@ class IFDSUninitializedVariables
std::string FilePath;
std::string SrcCode;
std::vector<std::string> VarNames;
std::map<IFDSUninitializedVariables::n_t,
std::set<IFDSUninitializedVariables::d_t>>
IRTrace;
std::vector<std::pair<n_t, llvm::SmallDenseSet<d_t>>> IRTrace;

[[nodiscard]] bool empty() const;
void print(llvm::raw_ostream &OS);
void print(llvm::raw_ostream &OS) const;

friend inline llvm::raw_ostream &operator<<(llvm::raw_ostream &OS,
const UninitResult &UR) {
UR.print(OS);
return OS;
}
};

public:
IFDSUninitializedVariables(const LLVMProjectIRDB *IRDB,
std::vector<std::string> EntryPoints = {"main"});
explicit IFDSUninitializedVariables(const LLVMProjectIRDB *IRDB,
LLVMAliasInfoRef PT,
std::vector<std::string> EntryPoints = {
"main"});

~IFDSUninitializedVariables() override = default;

Expand All @@ -65,12 +77,15 @@ class IFDSUninitializedVariables
void emitTextReport(const SolverResults<n_t, d_t, l_t> &Results,
llvm::raw_ostream &OS = llvm::outs()) override;

[[nodiscard]] const std::map<n_t, std::set<d_t>> &getAllUndefUses() const;
[[nodiscard]] const auto &getAllUndefUses() const noexcept {
return UndefValueUses;
}

std::vector<UninitResult> aggregateResults();
[[nodiscard]] std::vector<UninitResult> aggregateResults();

private:
std::map<n_t, std::set<d_t>> UndefValueUses;
llvm::DenseMap<n_t, llvm::SmallDenseSet<d_t>> UndefValueUses{};
LLVMAliasInfoRef PT;
};

} // namespace psr
Expand Down
4 changes: 4 additions & 0 deletions include/phasar/PhasarLLVM/Utils/LLVMShorthands.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ class StoreInst;
class BranchInst;
class Module;
class CallInst;
class Use;
} // namespace llvm

namespace psr {
class LLVMProjectIRDB;

[[nodiscard]] bool isDefiniteLastUse(const llvm::Use &Use) noexcept;
[[nodiscard]] bool isDefiniteLastUse(const llvm::Value *Use) noexcept;

/**
* @brief Checks if the given LLVM Value is a LLVM Function Pointer.
* @param V LLVM Value.
Expand Down
Loading
Loading