Skip to content

Commit 73cd88f

Browse files
authored
Generate correct stub names for inner function pointers of structs (#612)
* Replace "::" with "_" in stub name * Delete getStubSymbolicVarName duplicate
1 parent 03d7cf2 commit 73cd88f

File tree

13 files changed

+69
-14
lines changed

13 files changed

+69
-14
lines changed

server/src/printers/Printer.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,9 +393,9 @@ namespace printer {
393393
auto methodCopy = method;
394394
methodCopy.name = method.name;
395395

396-
std::string stubSymbolicVarName = getStubSymbolicVarName(nameForStub);
396+
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(nameForStub);
397397
if (!types::TypesHandler::omitMakeSymbolic(method.returnType)) {
398-
stubSymbolicVarName = getStubSymbolicVarName(methodName + "_" + nameForStub);
398+
stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(methodName + "_" + nameForStub);
399399
strDeclareArrayVar(types::Type::createArray(method.returnType), stubSymbolicVarName,
400400
types::PointerUsage::PARAMETER);
401401
}
@@ -447,10 +447,6 @@ namespace printer {
447447
return ss;
448448
}
449449

450-
std::string Printer::getStubSymbolicVarName(const std::string &methodName) {
451-
return methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
452-
}
453-
454450
Printer::Stream Printer::strKleeMakeSymbolic(const std::string &varName, bool needAmpersand, SRef pseudoName) {
455451
auto pointer = (needAmpersand ? "&" : "") + varName;
456452
auto size = "sizeof(" + varName + ")";

server/src/printers/Printer.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,8 +182,6 @@ namespace printer {
182182
const std::string &nameForStub,
183183
bool makeStatic = false);
184184

185-
static std::string getStubSymbolicVarName(const std::string &methodName);
186-
187185
Stream strKleeMakeSymbolic(SRef varName, bool needAmpersand, SRef pseudoName);
188186

189187
static inline std::string getTypedefFunctionPointer(const std::string &parentFunctionName,

server/src/printers/StubsPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ Stubs printer::StubsPrinter::genStubFile(const tests::Tests &tests,
5353
}
5454

5555
if (!typesHandler.omitMakeSymbolic(methodCopy.returnType)) {
56-
std::string stubSymbolicVarName = getStubSymbolicVarName(method.name);
56+
std::string stubSymbolicVarName = StubsUtils::getStubSymbolicVarName(method.name);
5757
strDeclareArrayVar(types::Type::createArray(method.returnType), stubSymbolicVarName,
5858
types::PointerUsage::PARAMETER);
5959
}

server/src/printers/StubsPrinter.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "ProjectContext.h"
66
#include "stubs/Stubs.h"
77
#include "types/Types.h"
8+
#include "utils/StubsUtils.h"
89

910
namespace printer {
1011
class StubsPrinter : Printer {

server/src/printers/TestsPrinter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ void TestsPrinter::genCode(Tests::MethodDescription &methodDescription,
194194

195195
static std::string getTestName(const Tests::MethodDescription &methodDescription, int testNum) {
196196
std::string renamedMethodDescription = KleeUtils::getRenamedOperator(methodDescription.name);
197-
StringUtils::replaceAll(renamedMethodDescription, ':', '_');
197+
StringUtils::replaceColon(renamedMethodDescription);
198198
std::string testBaseName = methodDescription.isClassMethod()
199199
? StringUtils::stringFormat("%s_%s",
200200
methodDescription.classObj->type.typeName(),

server/src/types/TypesResolver.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ std::string TypesResolver::getFullname(const clang::TagDecl *TD, const clang::Qu
7575
if (!fullname[parentID].empty()) {
7676
fullname[id] = fullname[parentID] + "::" + fullname[id];
7777
if (typeDeclNeeded) {
78-
StringUtils::replaceAll(fullname[id], "::", "_");
78+
StringUtils::replaceColon(fullname[id]);
7979
}
8080
}
8181
}

server/src/utils/KleeUtils.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ namespace KleeUtils {
8484
bool needToMangle,
8585
bool isWrapped) {
8686
std::string methodNewName = methodName;
87-
StringUtils::replaceAll(methodNewName, ':', '_');
87+
StringUtils::replaceColon(methodNewName);
8888
methodNewName = getRenamedOperator(methodNewName);
8989
if (isWrapped) {
9090
methodNewName += PrinterUtils::WRAPPED_SUFFIX;

server/src/utils/StringUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ namespace StringUtils {
8484
}
8585
}
8686

87+
void replaceColon(std::string &str) {
88+
replaceAll(str, "::", "_");
89+
}
90+
8791
bool isPrintable(int code) {
8892
if (std::numeric_limits<char>::is_signed && code < 0) {
8993
code += 256;

server/src/utils/StringUtils.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ namespace StringUtils {
5353

5454
void replaceAll(std::string &str, const std::string &from, const std::string &to);
5555

56+
void replaceColon(std::string &str);
57+
5658
/**
5759
* Returns true if char literal can be printed to .cpp file as is, false otherwise.
5860
* @param value - given character code

server/src/utils/StubsUtils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ namespace StubsUtils {
1616
}
1717

1818
std::string getStubSymbolicVarName(const std::string &methodName) {
19-
return methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
19+
std::string stubName = methodName + PrinterUtils::KLEE_SYMBOLIC_SUFFIX;
20+
StringUtils::replaceColon(stubName);
21+
return stubName;
2022
}
2123

2224
std::string getFunctionPointerAsStructFieldStubName(const std::string &structName,
@@ -28,6 +30,7 @@ namespace StubsUtils {
2830
} else {
2931
stubName = stubName.substr(1);
3032
}
33+
StringUtils::replaceColon(stubName);
3134
return stubName;
3235
}
3336
}

0 commit comments

Comments
 (0)