Skip to content

Commit 7b7c8de

Browse files
authored
Merge pull request #528 from secure-software-engineering/f-FixIDEEdgeFunctions
Fix IDE edge functions
2 parents b361364 + 8ad50a1 commit 7b7c8de

20 files changed

Lines changed: 117 additions & 96 deletions

File tree

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/EdgeFunctions.h

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class AllTop : public EdgeFunction<L>,
119119
const L TopElement;
120120

121121
public:
122-
AllTop(const L TopElement) : TopElement(std::move(TopElement)) {}
122+
AllTop(L TopElement) : TopElement(std::move(TopElement)) {}
123123

124124
~AllTop() override = default;
125125

@@ -160,33 +160,18 @@ class AllBottom : public EdgeFunction<L>,
160160
const L BottomElement;
161161

162162
public:
163-
AllBottom(const L BottomElement) : BottomElement(std::move(BottomElement)) {}
163+
AllBottom(L BottomElement) : BottomElement(std::move(BottomElement)) {}
164164

165165
~AllBottom() override = default;
166166

167167
L computeTarget(L /*Source*/) override { return BottomElement; }
168168

169-
EdgeFunctionPtrType composeWith(EdgeFunctionPtrType SecondFunction) override {
170-
if (auto *AB = dynamic_cast<AllBottom<L> *>(SecondFunction.get())) {
171-
return this->shared_from_this();
172-
}
173-
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(SecondFunction.get())) {
174-
return this->shared_from_this();
175-
}
176-
return SecondFunction->composeWith(this->shared_from_this());
169+
EdgeFunctionPtrType
170+
composeWith(EdgeFunctionPtrType /*SecondFunction*/) override {
171+
return this->shared_from_this();
177172
}
178173

179-
EdgeFunctionPtrType joinWith(EdgeFunctionPtrType OtherFunction) override {
180-
if (OtherFunction.get() == this ||
181-
OtherFunction->equal_to(this->shared_from_this())) {
182-
return this->shared_from_this();
183-
}
184-
if (auto *Alltop = dynamic_cast<AllTop<L> *>(OtherFunction.get())) {
185-
return this->shared_from_this();
186-
}
187-
if (auto *EI = dynamic_cast<EdgeIdentity<L> *>(OtherFunction.get())) {
188-
return this->shared_from_this();
189-
}
174+
EdgeFunctionPtrType joinWith(EdgeFunctionPtrType /*OtherFunction*/) override {
190175
return this->shared_from_this();
191176
}
192177

include/phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysis.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -936,7 +936,7 @@ class IDEInstInteractionAnalysisT
936936
// 0
937937
//
938938
if (isZeroValue(CurrNode) && isZeroValue(SuccNode)) {
939-
return std::make_shared<AllBottom<l_t>>(bottomElement());
939+
return EdgeIdentity<l_t>::getInstance();
940940
}
941941
// check if the user has registered a fact generator function
942942
l_t UserEdgeFacts = BitVectorSet<e_t>();

include/phasar/PhasarLLVM/Utils/LLVMShorthands.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@
2424
#include "llvm/IR/Instructions.h"
2525
#include "llvm/IR/ModuleSlotTracker.h"
2626
#include "llvm/IR/Value.h"
27+
#include "llvm/Support/Compiler.h"
2728

2829
#include "phasar/Utils/Utilities.h"
2930

3031
namespace psr {
3132

32-
static inline void deleteValue(llvm::Value *V) { V->deleteValue(); }
33-
3433
/**
3534
* @brief Checks if the given LLVM Value is a LLVM Function Pointer.
3635
* @param V LLVM Value.
@@ -73,6 +72,9 @@ std::string llvmIRToStableString(const llvm::Value *V);
7372
*/
7473
std::string llvmIRToShortString(const llvm::Value *V);
7574

75+
LLVM_DUMP_METHOD void dumpIRValue(const llvm::Value *V);
76+
LLVM_DUMP_METHOD void dumpIRValue(const llvm::Instruction *V);
77+
7678
/**
7779
* @brief Returns all LLVM Global Values that are used in the given LLVM
7880
* Function.

lib/Controller/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ set(PHASAR_LINK_LIBS
1010
phasar_phasarllvm_utils
1111
phasar_utils
1212
phasar_analysis_strategy
13+
phasar_taintconfig
1314
)
1415

1516
set(LLVM_LINK_COMPONENTS

lib/PhasarClang/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ include_directories(${CLANG_INCLUDE_DIRS})
44

55
set(PHASAR_LINK_LIBS
66
phasar_utils
7+
phasar_taintconfig
78
)
89

910
set(LLVM_LINK_COMPONENTS

lib/PhasarLLVM/ControlFlow/Resolver/DTAResolver.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "llvm/IR/InstIterator.h"
2323
#include "llvm/IR/Instruction.h"
2424
#include "llvm/IR/Module.h"
25+
#include "llvm/IR/Operator.h"
2526

2627
#include "phasar/PhasarLLVM/ControlFlow/Resolver/DTAResolver.h"
2728
#include "phasar/PhasarLLVM/TypeHierarchy/LLVMTypeHierarchy.h"
@@ -113,10 +114,7 @@ bool DTAResolver::heuristicAntiConstructorVtablePos(
113114
if (BitcastExpr->isCast()) {
114115
if (auto *ConstGep = llvm::dyn_cast<llvm::ConstantExpr>(
115116
BitcastExpr->getOperand(0))) {
116-
std::unique_ptr<llvm::Instruction, decltype(&deleteValue)>
117-
GepAsInst(ConstGep->getAsInstruction(), &deleteValue);
118-
if (auto *Gep =
119-
llvm::dyn_cast<llvm::GetElementPtrInst>(GepAsInst.get())) {
117+
if (auto *Gep = llvm::dyn_cast<llvm::GEPOperator>(ConstGep)) {
120118
if (auto *Vtable = llvm::dyn_cast<llvm::Constant>(
121119
Gep->getPointerOperand())) {
122120
// We can here assume that we found a vtable

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/BinaryEdgeFunction.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ BinaryEdgeFunction::composeWith(
3535
if (dynamic_cast<AllBottom<IDEGeneralizedLCA::l_t> *>(SecondFunction.get())) {
3636
// print(std::cout << "Compose ");
3737
// std::cout << " with ALLBOT" << std::endl;
38-
return shared_from_this();
38+
return SecondFunction;
3939
}
4040
return std::make_shared<LCAEdgeFunctionComposer>(this->shared_from_this(),
4141
SecondFunction, MaxSize);

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/GenConstant.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,7 @@ std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> GenConstant::composeWith(
3939
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction) {
4040
// std::cout << "GenConstant composing" << std::endl;
4141
if (dynamic_cast<EdgeIdentity<IDEGeneralizedLCA::l_t> *>(
42-
SecondFunction.get()) ||
43-
dynamic_cast<AllBottom<IDEGeneralizedLCA::l_t> *>(SecondFunction.get())) {
42+
SecondFunction.get())) {
4443

4544
return shared_from_this();
4645
}

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/IDEGeneralizedLCA.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,7 @@ IDEGeneralizedLCA::getNormalEdgeFunction(IDEGeneralizedLCA::n_t Curr,
301301

302302
// All_Bottom for zero value
303303
if (isZeroValue(CurrNode) && isZeroValue(SuccNode)) {
304-
static auto AllBot = std::make_shared<AllBottom<l_t>>(bottomElement());
305-
return AllBot;
304+
return EdgeIdentity<l_t>::getInstance();
306305
}
307306
// Check store instruction
308307
if (const auto *Store = llvm::dyn_cast<llvm::StoreInst>(Curr)) {

lib/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEGeneralizedLCA/JoinEdgeFunction.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ JoinEdgeFunction::composeWith(
6363
std::shared_ptr<EdgeFunction<IDEGeneralizedLCA::l_t>> SecondFunction) {
6464
// std::cout << "JoinFn composing" << std::endl;
6565
// TODO be more precise here
66-
if (dynamic_cast<GenConstant *>(SecondFunction.get())) {
66+
if (dynamic_cast<GenConstant *>(SecondFunction.get()) ||
67+
AllBot::isBot(SecondFunction)) {
6768
return SecondFunction;
6869
}
6970
if (dynamic_cast<EdgeIdentity<IDEGeneralizedLCA::l_t> *>(
@@ -81,7 +82,7 @@ JoinEdgeFunction::joinWith(
8182
return shared_from_this();
8283
}
8384
if (AllBot::isBot(OtherFunction)) {
84-
return AllBot::getInstance();
85+
return OtherFunction;
8586
}
8687

8788
return std::make_shared<JoinEdgeFunction>(shared_from_this(), OtherFunction,

0 commit comments

Comments
 (0)