Skip to content

Commit 9055dd7

Browse files
committed
[wip] AllocSource annotation support
1 parent 077b94e commit 9055dd7

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

include/klee/Module/Annotation.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ enum class Kind {
2525

2626
Deref,
2727
InitNull,
28+
AllocSource,
29+
};
30+
31+
enum class AllocSourceKind {
32+
MCREalloc = 1, // malloc, calloc, realloc
33+
New = 2, // operator new
34+
NewBrackets = 3, // operator new[]
35+
OpenFile = 4, // open file (fopen, open)
36+
MutexLock = 5 // mutex lock (pthread_mutex_lock)
2837
};
2938

3039
enum class Property {
@@ -60,6 +69,12 @@ struct InitNull final : public Unknown {
6069
[[nodiscard]] Kind getKind() const override;
6170
};
6271

72+
struct AllocSource final : public Unknown {
73+
explicit AllocSource(std::string str);
74+
75+
[[nodiscard]] Kind getKind() const override;
76+
};
77+
6378
using Ptr = std::shared_ptr<Unknown>;
6479
bool operator==(const Ptr &first, const Ptr &second);
6580
} // namespace Statement

lib/Core/MockBuilder.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,8 @@ inline bool isCorrectStatements(const std::vector<Statement::Ptr> &statements,
304304
case Statement::Kind::Deref:
305305
case Statement::Kind::InitNull:
306306
return argType->isPointerTy();
307+
case Statement::Kind::AllocSource:
308+
assert(false);
307309
case Statement::Kind::Unknown:
308310
default:
309311
return true;
@@ -395,6 +397,8 @@ void MockBuilder::buildAnnotationForExternalFunctionArgs(
395397

396398
break;
397399
}
400+
case Statement::Kind::AllocSource:
401+
assert(false);
398402
case Statement::Kind::InitNull:
399403
case Statement::Kind::Unknown:
400404
default:

lib/Module/Annotation.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,15 @@ InitNull::InitNull(std::string str) : Unknown(std::move(str)) {}
8686

8787
Kind InitNull::getKind() const { return Kind::InitNull; }
8888

89+
AllocSource::AllocSource(std::string str) : Unknown(std::move(str)) {}
90+
91+
Kind AllocSource::getKind() const { return Kind::AllocSource; }
92+
8993
const std::map<std::string, Statement::Kind> StringToKindMap = {
90-
{"deref", Statement::Kind::Deref}, {"initnull", Statement::Kind::InitNull}};
94+
{"deref", Statement::Kind::Deref},
95+
{"initnull", Statement::Kind::InitNull},
96+
{"allocsource", Statement::Kind::AllocSource}
97+
};
9198

9299
inline Statement::Kind stringToKind(const std::string &str) {
93100
auto it = StringToKindMap.find(toLower(str));
@@ -106,6 +113,8 @@ Ptr stringToKindPtr(const std::string &str) {
106113
return std::make_shared<Deref>(str);
107114
case Statement::Kind::InitNull:
108115
return std::make_shared<InitNull>(str);
116+
case Statement::Kind::AllocSource:
117+
return std::make_shared<AllocSource>(str);
109118
}
110119
}
111120

@@ -268,6 +277,9 @@ AnnotationsMap parseAnnotationsXml(const pugi::xml_document &annotationsXml,
268277
}
269278
break;
270279
}
280+
case Statement::Kind::AllocSource: {
281+
assert(false);
282+
}
271283
case Statement::Kind::Unknown:
272284
break;
273285
}

0 commit comments

Comments
 (0)