Skip to content

Commit ac3e9d5

Browse files
committed
update lazy instantiation processing
1 parent 93d8dff commit ac3e9d5

27 files changed

+839
-503
lines changed

integration-tests/c-example/lib/structures/structs/structs_with_pointers.c

+34-1
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,37 @@ struct StructWithPointerInField some_calc(int a, int b) {
7878
st.a.str = "DDD";
7979
return st;
8080
}
81-
}
81+
}
82+
83+
int sumStructWithPointer(struct StructWithPointer par) {
84+
return par.x + *par.y;
85+
}
86+
87+
int sumStructWithPointerAsPointer(struct StructWithPointer* par) {
88+
return par->x + *par->y;
89+
}
90+
91+
int sumStructWithDoublePointer(struct StructWithDoublePointer par) {
92+
return par.x + **par.y;
93+
}
94+
95+
int sumStructWithArrayOfPointer(struct StructWithArrayOfPointer par) {
96+
return par.x + *(par.y[0]) + *(par.y[1]);
97+
}
98+
99+
int sumStructWithStructWithPointer(struct StructWithStructWithPointer par) {
100+
int sswp = sumStructWithPointer(par.swp);
101+
int sswdp = sumStructWithDoublePointer(*par.swdp);
102+
return sswp + sswdp;
103+
}
104+
105+
int sumStructManyPointers(struct StructManyPointers par) {
106+
return par.a + *par.b + **par.c + ***par.d;
107+
}
108+
109+
int sumStructComplex(struct StructComplex par) {
110+
int sswp = sumStructWithPointer(*par.swp);
111+
int sswdp = sumStructWithDoublePointer(**par.swdp);
112+
int ssmp = sumStructManyPointers(par.smp);
113+
return par.x + *par.y + **par.z + sswp + sswdp + ssmp;
114+
}

integration-tests/c-example/lib/structures/structs/structs_with_pointers.h

+45-1
Original file line numberDiff line numberDiff line change
@@ -34,4 +34,48 @@ int unsafe_next_value(struct List *node);
3434
long long sum_of_all_fields_or_mult(struct StructWithPointerInField st, int a);
3535

3636
struct StructWithPointerInField some_calc(int a, int b);
37-
#endif // SIMPLE_TEST_PROJECT_STRUCTS_WITH_POINTERS_H
37+
38+
struct StructWithPointer {
39+
int x;
40+
int* y;
41+
};
42+
43+
struct StructWithDoublePointer {
44+
int x;
45+
int** y;
46+
};
47+
48+
struct StructWithArrayOfPointer {
49+
int x;
50+
int* y[2];
51+
};
52+
53+
struct StructWithStructWithPointer {
54+
struct StructWithPointer swp;
55+
struct StructWithDoublePointer* swdp;
56+
};
57+
58+
struct StructManyPointers {
59+
int a;
60+
int* b;
61+
int** c;
62+
int*** d;
63+
};
64+
65+
struct StructComplex {
66+
int x;
67+
int* y;
68+
int** z;
69+
struct StructWithPointer* swp;
70+
struct StructWithDoublePointer** swdp;
71+
struct StructManyPointers smp;
72+
};
73+
74+
int sumStructWithPointer(struct StructWithPointer par);
75+
int sumStructWithPointerAsPointer(struct StructWithPointer* par);
76+
int sumStructWithDoublePointer(struct StructWithDoublePointer par);
77+
int sumStructWithArrayOfPointer(struct StructWithArrayOfPointer par);
78+
int sumStructWithStructWithPointer(struct StructWithStructWithPointer par);
79+
int sumStructManyPointers(struct StructManyPointers par);
80+
int sumStructComplex(struct StructComplex par);
81+
#endif // SIMPLE_TEST_PROJECT_STRUCTS_WITH_POINTERS_H

server/src/Tests.cpp

+130-111
Large diffs are not rendered by default.

server/src/Tests.h

+40-21
Original file line numberDiff line numberDiff line change
@@ -285,8 +285,9 @@ namespace tests {
285285
struct InitReference {
286286
std::string varName;
287287
std::string refName;
288-
InitReference(std::string varName, std::string refName)
289-
: varName(std::move(varName)), refName(std::move(refName)) {
288+
std::string typeName;
289+
InitReference(std::string varName, std::string refName, std::string typeName)
290+
: varName(std::move(varName)), refName(std::move(refName)), typeName(std::move(typeName)) {
290291
}
291292
};
292293

@@ -300,6 +301,7 @@ namespace tests {
300301
: type(std::move(type)), varName(std::move(varName)) {
301302
}
302303
};
304+
303305
struct MethodParam {
304306
types::Type type;
305307
string name;
@@ -340,6 +342,8 @@ namespace tests {
340342
string name;
341343
std::optional<uint64_t> alignment;
342344
shared_ptr<AbstractValueView> view;
345+
vector<MethodParam> lazyParams;
346+
vector<TestCaseParamValue> lazyValues;
343347
TestCaseParamValue() = default;
344348
TestCaseParamValue(string name,
345349
std::optional<uint64_t> alignment,
@@ -357,7 +361,7 @@ namespace tests {
357361
vector<MethodParam> stubValuesTypes;
358362
vector<TestCaseParamValue> stubValues;
359363

360-
MapAddressName fromAddressToName;
364+
MapAddressName lazyAddressToName;
361365
vector<InitReference> lazyReferences;
362366

363367
vector<TestCaseParamValue> funcParamValues;
@@ -376,25 +380,23 @@ namespace tests {
376380
vector<TestCaseParamValue> globalPreValues;
377381
vector<TestCaseParamValue> globalPostValues;
378382
std::optional <TestCaseParamValue> stdinValue;
379-
vector<TypeAndVarName> lazyVariables;
380383
vector<InitReference> lazyReferences;
381384
vector<UTBotKTestObject> objects;
382385

383-
MapAddressName fromAddressToName;
386+
MapAddressName lazyAddressToName;
384387

385388
vector<MethodParam> stubValuesTypes;
386389
vector<TestCaseParamValue> stubValues;
387390

388391
vector<TestCaseParamValue> paramValues;
389392
vector<TestCaseParamValue> paramPostValues;
390-
vector<TestCaseParamValue> lazyValues;
391393
vector<TestCaseParamValue> stubParamValues;
392394
vector<MethodParam> stubParamTypes;
393-
shared_ptr<AbstractValueView> returnValueView;
395+
TestCaseParamValue returnValue;
394396
std::optional<TestCaseParamValue> classPreValues;
395397
std::optional<TestCaseParamValue> classPostValues;
396398

397-
bool isError() const;
399+
[[nodiscard]] bool isError() const;
398400
};
399401

400402
struct Modifiers {
@@ -463,7 +465,7 @@ namespace tests {
463465
return method;
464466
}
465467

466-
bool hasChangeable() const {
468+
[[nodiscard]] bool hasChangeable() const {
467469
for(const auto& i : params) {
468470
if (i.isChangeable()) {
469471
return true;
@@ -472,18 +474,18 @@ namespace tests {
472474
return false;
473475
}
474476

475-
bool isClassMethod() const {
477+
[[nodiscard]] bool isClassMethod() const {
476478
return classObj.has_value();
477479
}
478480

479-
std::optional<std::string> getClassName() const {
481+
[[nodiscard]] std::optional<std::string> getClassName() const {
480482
if (isClassMethod()) {
481483
return std::make_optional(classObj->name);
482484
}
483485
return std::nullopt;
484486
}
485487

486-
std::optional<std::string> getClassTypeName() const {
488+
[[nodiscard]] std::optional<std::string> getClassTypeName() const {
487489
if (isClassMethod()) {
488490
return std::make_optional(classObj->type.typeName());
489491
}
@@ -579,9 +581,14 @@ namespace tests {
579581
}
580582
};
581583

582-
struct JsonNumAndType {
583-
int num;
584-
types::Type type;
584+
struct JsonIndAndParam {
585+
size_t jsonInd;
586+
Tests::MethodParam param;
587+
Tests::TestCaseParamValue& paramValue;
588+
JsonIndAndParam(size_t jsonInd, Tests::MethodParam param,
589+
Tests::TestCaseParamValue& paramValue) : jsonInd(jsonInd),
590+
param(std::move(param)), paramValue(paramValue) {
591+
}
585592
};
586593

587594
/**
@@ -714,20 +721,32 @@ namespace tests {
714721
const std::unordered_map<string, types::Type>& methodNameToReturnTypeMap,
715722
vector<RawKleeParam> &rawKleeParams);
716723

724+
static void addToOrder(const vector<UTBotKTestObject> &objects,
725+
const std::string &paramName,
726+
const types::Type &paramType,
727+
Tests::TestCaseParamValue &paramValue,
728+
std::vector<bool> &visited,
729+
std::queue<JsonIndAndParam>& order);
730+
717731
void assignTypeUnnamedVar(Tests::MethodTestCase &testCase,
718732
const Tests::MethodDescription &methodDescription);
719733

720734
void assignTypeStubVar(Tests::MethodTestCase &testCase,
721735
const Tests::MethodDescription &methodDescription);
722736

723-
void workWithStructInBFS(std::queue<JsonNumAndType> &order, std::vector<bool> &visited,
724-
const Offset &off, std::vector<UTBotKTestObject> &objects, const types::StructInfo &structInfo);
725-
726-
int findFieldIndex(const types::StructInfo &structInfo, size_t offset);
737+
size_t findFieldIndex(const types::StructInfo &structInfo, size_t offset);
727738

728-
int findObjectIndex(const std::vector<UTBotKTestObject> &objects, const std::string &name);
739+
types::Type traverseLazyInStruct(vector<bool> &visited,
740+
const types::Type &curVarType,
741+
size_t offset,
742+
const Tests::MethodTestCase &testCase,
743+
const Tests::MethodDescription &methodDescription);
729744

730-
types::Type traverseStruct(const types::StructInfo &structInfo, size_t offset);
745+
shared_ptr<AbstractValueView> getLazyPointerView(const MapAddressName &fromAddressToName,
746+
vector<InitReference> &initReferences,
747+
const string &name,
748+
std::string res,
749+
const types::Type &paramType) const;
731750
};
732751
/**
733752
* @brief This function is used for converting primiive value of a specific type

server/src/printers/Printer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ namespace printer {
515515
return ss;
516516
}
517517

518-
size_t pointerSize = types::TypesHandler::getElementsNumberInPointerMultiDim();
518+
size_t pointerSize = types::TypesHandler::getElementsNumberInPointerMultiDim(types::PointerUsage::PARAMETER);
519519
auto typeObject = types::TypesHandler::isVoid(param.type.baseTypeObj())
520520
? types::Type::minimalScalarPointerType(2)
521521
: param.type;

0 commit comments

Comments
 (0)