Skip to content

Commit

Permalink
Merge branch 'development' into f-GetAsJsonRefactor
Browse files Browse the repository at this point in the history
  • Loading branch information
fabianbs96 authored Oct 4, 2024
2 parents a38035f + c1a75ed commit 3c4b8b2
Show file tree
Hide file tree
Showing 12 changed files with 2,316 additions and 89 deletions.
164 changes: 82 additions & 82 deletions config/glibc_function_list_v1-04.05.17.conf

Large diffs are not rendered by default.

76 changes: 76 additions & 0 deletions include/phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#include "phasar/Utils/DefaultValue.h"

#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"

#include <cstdint>
#include <unordered_map>
#include <variant>
#include <vector>

namespace psr::library_summary {

struct Parameter {
uint16_t Index{};
};

struct ReturnValue {};

struct DataFlowFact {
DataFlowFact(Parameter Param) noexcept : Fact(Param) {}
DataFlowFact(ReturnValue Ret) noexcept : Fact(Ret) {}

std::variant<Parameter, ReturnValue> Fact;
};

class FunctionDataFlowFacts {
public:
using ParamaterMappingTy =
std::unordered_map<uint32_t, std::vector<DataFlowFact>>;

FunctionDataFlowFacts() noexcept = default;

// insert a set of data flow facts
void insertSet(llvm::StringRef FuncKey, uint32_t Index,
std::vector<DataFlowFact> OutSet) {
Fdff[FuncKey].try_emplace(Index, std::move(OutSet));
}

// insert a single data flow fact
void addElement(llvm::StringRef FuncKey, uint32_t Index, DataFlowFact Out) {
Fdff[FuncKey][Index].emplace_back(Out);
}

// get outset for a function an the parameter index
[[nodiscard]] const std::vector<DataFlowFact> &
getDataFlowFacts(llvm::StringRef FuncKey, uint32_t Index) const {
auto It = Fdff.find(FuncKey);
if (It != Fdff.end()) {
auto Itt = It->second.find(Index);
return Itt->second;
}

return getDefaultValue<std::vector<DataFlowFact>>();
}

[[nodiscard]] auto begin() const noexcept { return Fdff.begin(); }
[[nodiscard]] auto end() const noexcept { return Fdff.end(); }

[[nodiscard]] size_t size() const noexcept { return Fdff.size(); }
[[nodiscard]] bool empty() const noexcept { return size() == 0; }

private:
[[nodiscard]] const auto &
getDataFlowFactsOrEmpty(llvm::StringRef FuncKey) const {
auto It = Fdff.find(FuncKey);
if (It != Fdff.end()) {
return It->second;
}

return getDefaultValue<ParamaterMappingTy>();
}

llvm::StringMap<ParamaterMappingTy> Fdff;
};

} // namespace psr::library_summary
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h"
#include "phasar/Utils/DefaultValue.h"

#include "llvm/IR/Argument.h"
#include "llvm/IR/Function.h"

#include <unordered_map>
#include <vector>

namespace psr::library_summary {

class LLVMFunctionDataFlowFacts;
[[nodiscard]] LLVMFunctionDataFlowFacts
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb);

class LLVMFunctionDataFlowFacts {
public:
LLVMFunctionDataFlowFacts() noexcept = default;
using ParamaterMappingTy = FunctionDataFlowFacts::ParamaterMappingTy;

/// insert a set of data flow facts
void insertSet(const llvm::Function *Fun, uint32_t Index,
std::vector<DataFlowFact> OutSet) {

LLVMFdff[Fun].try_emplace(Index, std::move(OutSet));
}
void insertSet(const llvm::Function *Fun, const llvm::Argument *Arg,
std::vector<DataFlowFact> OutSet) {

insertSet(Fun, Arg->getArgNo(), std::move(OutSet));
}

void addElement(const llvm::Function *Fun, uint32_t Index, DataFlowFact Out) {
LLVMFdff[Fun][Index].emplace_back(Out);
}
void addElement(const llvm::Function *Fun, const llvm::Argument *Arg,
DataFlowFact Out) {
addElement(Fun, Arg->getArgNo(), Out);
}

[[nodiscard]] bool contains(const llvm::Function *Fn) {
return LLVMFdff.count(Fn);
}

[[nodiscard]] const std::vector<DataFlowFact> &
getFacts(const llvm::Function *Fun, uint32_t Index) {
auto Iter = LLVMFdff.find(Fun);
if (Iter != LLVMFdff.end()) {
return Iter->second[Index];
}
return getDefaultValue<std::vector<DataFlowFact>>();
}
[[nodiscard]] const std::vector<DataFlowFact> &
getFacts(const llvm::Function *Fun, const llvm::Argument *Arg) {
return getFacts(Fun, Arg->getArgNo());
}

[[nodiscard]] const ParamaterMappingTy &
getFactsForFunction(const llvm::Function *Fun) {
auto Iter = LLVMFdff.find(Fun);
if (Iter != LLVMFdff.end()) {
return Iter->second;
}
return getDefaultValue<ParamaterMappingTy>();
}

friend LLVMFunctionDataFlowFacts
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb);

private:
std::unordered_map<const llvm::Function *, ParamaterMappingTy> LLVMFdff;
};
} // namespace psr::library_summary
9 changes: 9 additions & 0 deletions include/phasar/PhasarLLVM/DataFlow/IfdsIde/LibCSummary.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

namespace psr {
namespace library_summary {
class FunctionDataFlowFacts;
} // namespace library_summary

[[nodiscard]] const library_summary::FunctionDataFlowFacts &getLibCSummary();
} // namespace psr
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IFDSTAINTANALYSIS_H

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

#include <map>
#include <memory>
#include <set>
#include <string>

Expand Down Expand Up @@ -87,6 +87,7 @@ class IFDSTaintAnalysis
const LLVMTaintConfig *Config{};
LLVMAliasInfoRef PT{};
bool TaintMainArgs{};
library_summary::LLVMFunctionDataFlowFacts Llvmfdff;

bool isSourceCall(const llvm::CallBase *CB,
const llvm::Function *Callee) const;
Expand Down
9 changes: 7 additions & 2 deletions lib/Config/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,13 @@ bool PhasarConfig::loadConfigFileInto(llvm::StringRef FileName,
llvm::SmallVector<llvm::StringRef, 0> ConfigLines;
llvm::SplitString(*ConfigFile, ConfigLines, "\n");

llvm::transform(ConfigLines, std::inserter(Lines, Lines.end()),
[](llvm::StringRef Str) { return Str.trim().str(); });
llvm::transform(
ConfigLines, std::inserter(Lines, Lines.end()), [](llvm::StringRef Str) {
if (auto Comment = Str.find("//"); Comment != llvm::StringRef::npos) {
Str = Str.slice(0, Comment);
}
return Str.trim().str();
});
return true;
}

Expand Down
18 changes: 18 additions & 0 deletions lib/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h"

using namespace psr;
using namespace psr::library_summary;

LLVMFunctionDataFlowFacts
library_summary::readFromFDFF(const FunctionDataFlowFacts &Fdff,
const LLVMProjectIRDB &Irdb) {
LLVMFunctionDataFlowFacts Llvmfdff;
Llvmfdff.LLVMFdff.reserve(Fdff.size());

for (const auto &It : Fdff) {
if (const llvm::Function *Fun = Irdb.getFunction(It.first())) {
Llvmfdff.LLVMFdff.try_emplace(Fun, It.second);
}
}
return Llvmfdff;
}
Loading

0 comments on commit 3c4b8b2

Please sign in to comment.