Skip to content

Commit 892c9b0

Browse files
committed
add annotation redefinitions
1 parent 307eb86 commit 892c9b0

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

lib/Core/Executor.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -577,10 +577,10 @@ llvm::Module *Executor::setModule(
577577
kmodule->instrument(opts);
578578
}
579579

580-
if (interpreterOpts.MockStrategy != MockStrategy::None) {
581-
MockBuilder mockBuilder(kmodule->module.get(), opts,
582-
ignoredExternals, redefinitions,
583-
interpreterHandler);
580+
if (interpreterOpts.MockStrategy != MockStrategy::None ||
581+
!opts.AnnotationsFile.empty()) {
582+
MockBuilder mockBuilder(kmodule->module.get(), opts, ignoredExternals,
583+
redefinitions, interpreterHandler);
584584
std::unique_ptr<llvm::Module> mockModule = mockBuilder.build();
585585

586586
std::vector<std::unique_ptr<llvm::Module>> mockModules;

lib/Core/MockBuilder.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ MockBuilder::getExternalFunctions() {
2929
std::map<std::string, llvm::FunctionType *> externals;
3030
for (const auto &f : userModule->functions()) {
3131
if (f.isDeclaration() && !f.use_empty() &&
32-
!ignoredExternals.count(f.getName().str())) {
32+
!ignoredExternals.count(f.getName().str())) {
3333
// NOTE: here we detect all the externals, even linked.
3434
externals.insert(std::make_pair(f.getName(), f.getFunctionType()));
3535
}
@@ -202,6 +202,14 @@ void MockBuilder::buildExternalFunctionsDefinitions() {
202202
if (nameToAnnotations != annotations.end()) {
203203
const auto &annotation = nameToAnnotations->second;
204204

205+
if (llvm::Function *f = userModule->getFunction(extName)) {
206+
std::string replacedName = extName + "_replaced_by_mock";
207+
klee_message("Renamed symbol %s to %s", f->getName().str().c_str(),
208+
replacedName.c_str());
209+
redefinitions.emplace_back(f->getName(), extName);
210+
f->setName(replacedName);
211+
}
212+
205213
buildAnnotationForExternalFunctionArgs(func, annotation.argsStatements);
206214
buildAnnotationForExternalFunctionReturn(func,
207215
annotation.returnStatements);

0 commit comments

Comments
 (0)