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

F model dataflow for libraries #731

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
05c9888
new data structure
bulletSpace Jun 10, 2024
e2b9645
data structure update
bulletSpace Jun 14, 2024
38deabf
data structure update
bulletSpace Jun 14, 2024
99cf4b4
data structur update
bulletSpace Jun 17, 2024
c5416e7
warning fixed
bulletSpace Jun 17, 2024
469ef99
update from call
fabianbs96 Jun 17, 2024
ba6b480
Sample use
fabianbs96 Jun 17, 2024
c7474ac
data structure updated and LibCSummary updated
bulletSpace Jun 23, 2024
91a646a
update summary
bulletSpace Jun 24, 2024
8bb3feb
Data Structure updated
bulletSpace Jun 28, 2024
80d3734
new function summaries
bulletSpace Jun 28, 2024
58a7305
function summaries updated
bulletSpace Jun 28, 2024
03a51ea
function summaries updated
bulletSpace Jun 28, 2024
446badb
function summaries updated
bulletSpace Jun 28, 2024
bcb9720
new function summaries
bulletSpace Jul 1, 2024
fbebec7
new function summaries
bulletSpace Jul 1, 2024
b8db96c
LLVMDataFlowFacts updated and new function summaries
bulletSpace Jul 8, 2024
8588c2d
new Function Summaries
bulletSpace Jul 12, 2024
ceac20b
new function summaries
bulletSpace Jul 15, 2024
4ab8013
Summarie functions finished
bulletSpace Jul 16, 2024
509e0e6
lambdaFlow flow function finished
bulletSpace Aug 12, 2024
a02ddb8
new unit test
bulletSpace Aug 17, 2024
fe2f54d
corrections for unit test
bulletSpace Aug 19, 2024
82d5a96
handle comments in config files
fabianbs96 Aug 25, 2024
0352353
Merge branch 'development' into f-model-dataflow-for-libraries
fabianbs96 Aug 25, 2024
eb9db08
updated pull request
bulletSpace Aug 28, 2024
853a491
pull request updated
bulletSpace Sep 1, 2024
0adb272
pull request updated
bulletSpace Sep 1, 2024
18a1d7e
FunctionDataFlowFactSerialization.cpp unfinished
bulletSpace Sep 2, 2024
1756599
make pr ready for merge
fabianbs96 Oct 4, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
164 changes: 82 additions & 82 deletions config/glibc_function_list_v1-04.05.17.conf

Large diffs are not rendered by default.

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
Loading