Skip to content

Commit b7dc060

Browse files
authored
Merge branch 'development' into f-IterativeIDESolver
2 parents aae2109 + c1a75ed commit b7dc060

File tree

12 files changed

+2316
-89
lines changed

12 files changed

+2316
-89
lines changed

config/glibc_function_list_v1-04.05.17.conf

Lines changed: 82 additions & 82 deletions
Large diffs are not rendered by default.
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#include "phasar/Utils/DefaultValue.h"
2+
3+
#include "llvm/ADT/StringMap.h"
4+
#include "llvm/ADT/StringRef.h"
5+
6+
#include <cstdint>
7+
#include <unordered_map>
8+
#include <variant>
9+
#include <vector>
10+
11+
namespace psr::library_summary {
12+
13+
struct Parameter {
14+
uint16_t Index{};
15+
};
16+
17+
struct ReturnValue {};
18+
19+
struct DataFlowFact {
20+
DataFlowFact(Parameter Param) noexcept : Fact(Param) {}
21+
DataFlowFact(ReturnValue Ret) noexcept : Fact(Ret) {}
22+
23+
std::variant<Parameter, ReturnValue> Fact;
24+
};
25+
26+
class FunctionDataFlowFacts {
27+
public:
28+
using ParamaterMappingTy =
29+
std::unordered_map<uint32_t, std::vector<DataFlowFact>>;
30+
31+
FunctionDataFlowFacts() noexcept = default;
32+
33+
// insert a set of data flow facts
34+
void insertSet(llvm::StringRef FuncKey, uint32_t Index,
35+
std::vector<DataFlowFact> OutSet) {
36+
Fdff[FuncKey].try_emplace(Index, std::move(OutSet));
37+
}
38+
39+
// insert a single data flow fact
40+
void addElement(llvm::StringRef FuncKey, uint32_t Index, DataFlowFact Out) {
41+
Fdff[FuncKey][Index].emplace_back(Out);
42+
}
43+
44+
// get outset for a function an the parameter index
45+
[[nodiscard]] const std::vector<DataFlowFact> &
46+
getDataFlowFacts(llvm::StringRef FuncKey, uint32_t Index) const {
47+
auto It = Fdff.find(FuncKey);
48+
if (It != Fdff.end()) {
49+
auto Itt = It->second.find(Index);
50+
return Itt->second;
51+
}
52+
53+
return getDefaultValue<std::vector<DataFlowFact>>();
54+
}
55+
56+
[[nodiscard]] auto begin() const noexcept { return Fdff.begin(); }
57+
[[nodiscard]] auto end() const noexcept { return Fdff.end(); }
58+
59+
[[nodiscard]] size_t size() const noexcept { return Fdff.size(); }
60+
[[nodiscard]] bool empty() const noexcept { return size() == 0; }
61+
62+
private:
63+
[[nodiscard]] const auto &
64+
getDataFlowFactsOrEmpty(llvm::StringRef FuncKey) const {
65+
auto It = Fdff.find(FuncKey);
66+
if (It != Fdff.end()) {
67+
return It->second;
68+
}
69+
70+
return getDefaultValue<ParamaterMappingTy>();
71+
}
72+
73+
llvm::StringMap<ParamaterMappingTy> Fdff;
74+
};
75+
76+
} // namespace psr::library_summary
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
#include "phasar/PhasarLLVM/DB/LLVMProjectIRDB.h"
2+
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/FunctionDataFlowFacts.h"
3+
#include "phasar/Utils/DefaultValue.h"
4+
5+
#include "llvm/IR/Argument.h"
6+
#include "llvm/IR/Function.h"
7+
8+
#include <unordered_map>
9+
#include <vector>
10+
11+
namespace psr::library_summary {
12+
13+
class LLVMFunctionDataFlowFacts;
14+
[[nodiscard]] LLVMFunctionDataFlowFacts
15+
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb);
16+
17+
class LLVMFunctionDataFlowFacts {
18+
public:
19+
LLVMFunctionDataFlowFacts() noexcept = default;
20+
using ParamaterMappingTy = FunctionDataFlowFacts::ParamaterMappingTy;
21+
22+
/// insert a set of data flow facts
23+
void insertSet(const llvm::Function *Fun, uint32_t Index,
24+
std::vector<DataFlowFact> OutSet) {
25+
26+
LLVMFdff[Fun].try_emplace(Index, std::move(OutSet));
27+
}
28+
void insertSet(const llvm::Function *Fun, const llvm::Argument *Arg,
29+
std::vector<DataFlowFact> OutSet) {
30+
31+
insertSet(Fun, Arg->getArgNo(), std::move(OutSet));
32+
}
33+
34+
void addElement(const llvm::Function *Fun, uint32_t Index, DataFlowFact Out) {
35+
LLVMFdff[Fun][Index].emplace_back(Out);
36+
}
37+
void addElement(const llvm::Function *Fun, const llvm::Argument *Arg,
38+
DataFlowFact Out) {
39+
addElement(Fun, Arg->getArgNo(), Out);
40+
}
41+
42+
[[nodiscard]] bool contains(const llvm::Function *Fn) {
43+
return LLVMFdff.count(Fn);
44+
}
45+
46+
[[nodiscard]] const std::vector<DataFlowFact> &
47+
getFacts(const llvm::Function *Fun, uint32_t Index) {
48+
auto Iter = LLVMFdff.find(Fun);
49+
if (Iter != LLVMFdff.end()) {
50+
return Iter->second[Index];
51+
}
52+
return getDefaultValue<std::vector<DataFlowFact>>();
53+
}
54+
[[nodiscard]] const std::vector<DataFlowFact> &
55+
getFacts(const llvm::Function *Fun, const llvm::Argument *Arg) {
56+
return getFacts(Fun, Arg->getArgNo());
57+
}
58+
59+
[[nodiscard]] const ParamaterMappingTy &
60+
getFactsForFunction(const llvm::Function *Fun) {
61+
auto Iter = LLVMFdff.find(Fun);
62+
if (Iter != LLVMFdff.end()) {
63+
return Iter->second;
64+
}
65+
return getDefaultValue<ParamaterMappingTy>();
66+
}
67+
68+
friend LLVMFunctionDataFlowFacts
69+
readFromFDFF(const FunctionDataFlowFacts &Fdff, const LLVMProjectIRDB &Irdb);
70+
71+
private:
72+
std::unordered_map<const llvm::Function *, ParamaterMappingTy> LLVMFdff;
73+
};
74+
} // namespace psr::library_summary
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#pragma once
2+
3+
namespace psr {
4+
namespace library_summary {
5+
class FunctionDataFlowFacts;
6+
} // namespace library_summary
7+
8+
[[nodiscard]] const library_summary::FunctionDataFlowFacts &getLibCSummary();
9+
} // namespace psr

include/phasar/PhasarLLVM/DataFlow/IfdsIde/Problems/IFDSTaintAnalysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#define PHASAR_PHASARLLVM_DATAFLOW_IFDSIDE_PROBLEMS_IFDSTAINTANALYSIS_H
1212

1313
#include "phasar/DataFlow/IfdsIde/IFDSTabulationProblem.h"
14+
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h"
1415
#include "phasar/PhasarLLVM/Domain/LLVMAnalysisDomain.h"
1516
#include "phasar/PhasarLLVM/Pointer/LLVMAliasInfo.h"
1617

1718
#include <map>
18-
#include <memory>
1919
#include <set>
2020
#include <string>
2121

@@ -90,6 +90,7 @@ class IFDSTaintAnalysis
9090
const LLVMTaintConfig *Config{};
9191
LLVMAliasInfoRef PT{};
9292
bool TaintMainArgs{};
93+
library_summary::LLVMFunctionDataFlowFacts Llvmfdff;
9394

9495
bool isSourceCall(const llvm::CallBase *CB,
9596
const llvm::Function *Callee) const;

lib/Config/Configuration.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,13 @@ bool PhasarConfig::loadConfigFileInto(llvm::StringRef FileName,
136136
llvm::SmallVector<llvm::StringRef, 0> ConfigLines;
137137
llvm::SplitString(*ConfigFile, ConfigLines, "\n");
138138

139-
llvm::transform(ConfigLines, std::inserter(Lines, Lines.end()),
140-
[](llvm::StringRef Str) { return Str.trim().str(); });
139+
llvm::transform(
140+
ConfigLines, std::inserter(Lines, Lines.end()), [](llvm::StringRef Str) {
141+
if (auto Comment = Str.find("//"); Comment != llvm::StringRef::npos) {
142+
Str = Str.slice(0, Comment);
143+
}
144+
return Str.trim().str();
145+
});
141146
return true;
142147
}
143148

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#include "phasar/PhasarLLVM/DataFlow/IfdsIde/LLVMFunctionDataFlowFacts.h"
2+
3+
using namespace psr;
4+
using namespace psr::library_summary;
5+
6+
LLVMFunctionDataFlowFacts
7+
library_summary::readFromFDFF(const FunctionDataFlowFacts &Fdff,
8+
const LLVMProjectIRDB &Irdb) {
9+
LLVMFunctionDataFlowFacts Llvmfdff;
10+
Llvmfdff.LLVMFdff.reserve(Fdff.size());
11+
12+
for (const auto &It : Fdff) {
13+
if (const llvm::Function *Fun = Irdb.getFunction(It.first())) {
14+
Llvmfdff.LLVMFdff.try_emplace(Fun, It.second);
15+
}
16+
}
17+
return Llvmfdff;
18+
}

0 commit comments

Comments
 (0)