Skip to content

Commit 61f82f5

Browse files
committed
add target subjects
1 parent fd86777 commit 61f82f5

5 files changed

Lines changed: 144 additions & 0 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
/******************************************************************************
2+
* Copyright (c) 2019 Philipp Schubert, Richard Leer, and Florian Sattler.
3+
* All rights reserved. This program and the accompanying materials are made
4+
* available under the terms of LICENSE.txt.
5+
*
6+
* Contributors:
7+
* Philipp Schubert and others
8+
*****************************************************************************/
9+
10+
#include "phasar/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysis.h"
11+
12+
#include "llvm/IR/Instructions.h"
13+
#include "llvm/IR/Value.h"
14+
#include "llvm/Support/Casting.h"
15+
#include "llvm/Support/ErrorHandling.h"
16+
17+
#include <memory>
18+
#include <tuple>
19+
20+
using namespace psr;
21+
22+
IDEIIAFlowFact::IDEIIAFlowFact(const llvm::Value *BaseVal) : Base(BaseVal) {}
23+
24+
IDEIIAFlowFact::IDEIIAFlowFact(
25+
const llvm::Value *BaseVal,
26+
llvm::SmallVector<const llvm::GetElementPtrInst *, Depth> FieldDesc)
27+
: Base(BaseVal), Field(std::move(FieldDesc)) {}
28+
29+
IDEIIAFlowFact IDEIIAFlowFact::create(const llvm::Value *BaseVal) {
30+
if (const auto *Alloca = llvm::dyn_cast<llvm::AllocaInst>(BaseVal)) {
31+
return {BaseVal};
32+
}
33+
if (const auto *Gep = llvm::dyn_cast<llvm::GetElementPtrInst>(BaseVal)) {
34+
llvm::SmallVector<const llvm::GetElementPtrInst *, Depth> Field;
35+
Field.push_back(Gep);
36+
const llvm::Value *Base = Gep->getPointerOperand();
37+
while (const auto *NextGep = llvm::dyn_cast<llvm::GetElementPtrInst>(Base)
38+
->getPointerOperand()) {
39+
Field.push_back(NextGep);
40+
Base = NextGep;
41+
}
42+
return {Base, Field};
43+
}
44+
llvm::report_fatal_error("Unexpected instruction!");
45+
}
46+
47+
bool IDEIIAFlowFact::flowFactEqual(const IDEIIAFlowFact &Other) const {
48+
return false;
49+
}
50+
51+
void IDEIIAFlowFact::print(llvm::raw_ostream &OS, bool IsForDebug) const {
52+
OS << "IDEIIAFlowFact { " << *Base;
53+
if (Field.empty()) {
54+
OS << " }";
55+
} else {
56+
OS << ", [";
57+
for (const auto *Gep : Field) {
58+
OS << *Gep;
59+
if (Gep != Field.back()) {
60+
OS << ", ";
61+
}
62+
}
63+
OS << "] }";
64+
}
65+
}
66+
67+
bool IDEIIAFlowFact::operator==(const IDEIIAFlowFact &Other) const {
68+
if (Base != Other.Base) {
69+
return false;
70+
}
71+
for (unsigned Idx = 0; Idx < Field.size(); ++Idx) {
72+
if (Field[Idx] != Other.Field[Idx]) {
73+
return false;
74+
}
75+
}
76+
return true;
77+
}
78+
79+
bool IDEIIAFlowFact::operator!=(const IDEIIAFlowFact &Other) const {
80+
return !(*this == Other);
81+
}
82+
83+
bool IDEIIAFlowFact::operator<(const IDEIIAFlowFact &Other) const {
84+
return std::tie(Base, Field) < std::tie(Other.Base, Other.Field);
85+
}
86+
87+
bool IDEIIAFlowFact::operator==(const llvm::Value *V) const {
88+
return Base == V;
89+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
int main() {
2+
int i = 13;
3+
int j = 42;
4+
int buffer[16] = {0};
5+
buffer[0] = i;
6+
buffer[10] = j;
7+
int x = buffer[0];
8+
int y = buffer[10];
9+
int z = buffer[1];
10+
return 0;
11+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
int main() {
2+
int buffer[10][10];
3+
buffer[0][0] = 1;
4+
int i = buffer[0][0];
5+
return i;
6+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2+
struct X {
3+
int i;
4+
};
5+
6+
struct Y {
7+
X x;
8+
int j;
9+
};
10+
11+
int main() {
12+
Y b;
13+
b.x.i = 1000;
14+
b.j = 2000;
15+
int k = b.x.i;
16+
int l = b.j;
17+
return 0;
18+
}

unittests/PhasarLLVM/DataFlowSolver/IfdsIde/Problems/IDEInstInteractionAnalysisTest.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,26 @@ class IDEInstInteractionAnalysisTest : public ::testing::Test {
208208
// }
209209

210210
/* ============== BASIC TESTS ============== */
211+
TEST_F(IDEInstInteractionAnalysisTest, HandleArrayFieldSensTest_01) {
212+
std::set<IIACompactResult_t> GroundTruth;
213+
doAnalysisAndCompareResults("array_01_cpp.ll", GroundTruth, true);
214+
}
215+
216+
TEST_F(IDEInstInteractionAnalysisTest, HandleArrayFieldSensTest_02) {
217+
std::set<IIACompactResult_t> GroundTruth;
218+
doAnalysisAndCompareResults("array_02_cpp.ll", GroundTruth, true);
219+
}
220+
221+
TEST_F(IDEInstInteractionAnalysisTest, HandleStructFieldSensTest_01) {
222+
std::set<IIACompactResult_t> GroundTruth;
223+
doAnalysisAndCompareResults("struct_01_cpp.ll", GroundTruth, true);
224+
}
225+
226+
TEST_F(IDEInstInteractionAnalysisTest, HandleStructFieldSensTest_02) {
227+
std::set<IIACompactResult_t> GroundTruth;
228+
doAnalysisAndCompareResults("struct_02_cpp.ll", GroundTruth, true);
229+
}
230+
211231
TEST_F(IDEInstInteractionAnalysisTest, HandleBasicTest_01) {
212232
std::set<IIACompactResult_t> GroundTruth;
213233
GroundTruth.emplace(

0 commit comments

Comments
 (0)