Skip to content

Commit f9a2e90

Browse files
authored
Add skip duplicate compile commands (#660)
1 parent 4ce4ada commit f9a2e90

File tree

4 files changed

+36
-22
lines changed

4 files changed

+36
-22
lines changed

server/src/KleeGenerator.cpp

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
153153
}
154154
command.setSourcePath(srcFilePath);
155155

156-
auto outFilePath = (forStub ? testGen->getProjectBuildDatabase()->getBitcodeFile(compilationUnitInfo->getOutputFile())
157-
: testGen->getTargetBuildDatabase()->getBitcodeFile(compilationUnitInfo->getOutputFile()));
156+
auto outFilePath = (forStub ? testGen->getProjectBuildDatabase()->getBitcodeFile(
157+
compilationUnitInfo->getOutputFile())
158+
: testGen->getTargetBuildDatabase()->getBitcodeFile(
159+
compilationUnitInfo->getOutputFile()));
158160
fs::create_directories(outFilePath.parent_path());
159161
command.setOutput(outFilePath);
160162
command.setOptimizationLevel("-O0");
@@ -227,7 +229,7 @@ Result<fs::path> KleeGenerator::defaultBuild(const fs::path &hintPath,
227229

228230
auto makefileCommand = MakefileUtils::MakefileCommand(testGen->projectContext, makefile,
229231
printer::DefaultMakefilePrinter::TARGET_BUILD);
230-
auto[out, status, _] = makefileCommand.run();
232+
auto [out, status, _] = makefileCommand.run();
231233
if (status != 0) {
232234
LOG_S(ERROR) << "Compilation for " << sourceFilePath << " failed.\n"
233235
<< "Command: \"" << commandWithChangingDirectory.toString() << "\"\n"
@@ -264,7 +266,8 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
264266
const std::shared_ptr<LineInfo> &lineInfo) {
265267
std::vector<fs::path> outFiles;
266268
LOG_S(DEBUG) << "Building generated klee files...";
267-
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN, testGen);
269+
printer::KleePrinter kleePrinter(&typesHandler, testGen->getTargetBuildDatabase(), utbot::Language::UNKNOWN,
270+
testGen);
268271
ExecUtils::doWorkWithProgress(
269272
testsMap, testGen->progressWriter, "Building generated klee files",
270273
[&](auto const &it) {
@@ -344,14 +347,14 @@ std::vector<fs::path> KleeGenerator::buildKleeFiles(const tests::TestsMap &tests
344347
}
345348

346349
void KleeGenerator::parseKTestsToFinalCode(
347-
const utbot::ProjectContext &projectContext,
348-
tests::Tests &tests,
349-
const std::unordered_map<std::string, types::Type> &methodNameToReturnTypeMap,
350-
const std::vector<MethodKtests> &kleeOutput,
351-
const std::shared_ptr<LineInfo> &lineInfo,
352-
bool verbose,
353-
ErrorMode errorMode) {
354-
for (const auto &batch : kleeOutput) {
350+
const utbot::ProjectContext &projectContext,
351+
tests::Tests &tests,
352+
const std::unordered_map<std::string, types::Type> &methodNameToReturnTypeMap,
353+
const std::vector<MethodKtests> &kleeOutput,
354+
const std::shared_ptr<LineInfo> &lineInfo,
355+
bool verbose,
356+
ErrorMode errorMode) {
357+
for (const auto &batch: kleeOutput) {
355358
bool filterByFlag = (lineInfo != nullptr && !lineInfo->forMethod && !lineInfo->forClass &&
356359
!lineInfo->predicateInfo.has_value());
357360
tests::KTestObjectParser KTestObjectParser(typesHandler);
@@ -375,12 +378,12 @@ void KleeGenerator::parseKTestsToFinalCode(
375378
continue;
376379
}
377380
auto predicate =
378-
lineInfo ? lineInfo->predicateInfo : std::optional<LineInfo::PredicateInfo>{};
381+
lineInfo ? lineInfo->predicateInfo : std::optional<LineInfo::PredicateInfo>{};
379382
testsPrinter.genCode(methodDescription, predicate, verbose, errorMode);
380383
}
381384

382385
printer::HeaderPrinter(Paths::getSourceLanguage(tests.sourceFilePath))
383-
.print(tests.testHeaderFilePath, tests.sourceFilePath, tests.headerCode);
386+
.print(tests.testHeaderFilePath, tests.sourceFilePath, tests.headerCode);
384387
testsPrinter.joinToFinalCode(tests, tests.testHeaderFilePath);
385388
LOG_S(DEBUG) << "Generated code for " << tests.methods.size() << " tests";
386389
}

server/src/building/ProjectBuildDatabse.cpp

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,23 @@ void ProjectBuildDatabase::initObjects(const nlohmann::json &compileCommandsJson
103103
LOG_S(WARNING)
104104
<< "Source file " << sourceFile << " outside of project root " << projectContext.projectPath;
105105
kleeFilePathTemplate = Paths::createNewDirForFile(sourceFile, fs::path("/"),
106-
Paths::getUTBotFiles(projectContext) / "outside_of_project");
106+
Paths::getUTBotFiles(projectContext) /
107+
"outside_of_project");
107108
}
108109

109110
fs::path kleeFile = Paths::addSuffix(kleeFilePathTemplate, "_klee");
110111
objectInfo->kleeFilesInfo = std::make_shared<KleeFilesInfo>(kleeFile);
111112

113+
if (CollectionUtils::containsKey(objectFileInfos, outputFile) && Paths::isObjectFile(outputFile)) {
114+
auto previusInfo = objectFileInfos[outputFile];
115+
if (previusInfo->command.getCommandLine() == objectInfo->command.getCommandLine()) {
116+
LOG_S(WARNING) << "Skip duplicate compile command for object file: " << outputFile;
117+
} else {
118+
LOG_S(WARNING) << "Skip second compile command for object file: " << outputFile;
119+
}
120+
continue;
121+
}
122+
112123
if (CollectionUtils::containsKey(objectFileInfos, outputFile) ||
113124
CollectionUtils::containsKey(targetInfos, outputFile)) {
114125
/*

server/src/fetchers/GlobalVariableUsageMatchCallback.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ void GlobalVariableUsageMatchCallback::run(const MatchFinder::MatchResult &Resul
1313
checkUsage(Result);
1414
}
1515

16-
static std::unordered_set<std::string> BLACK_LIST = { "stdin", "stdout", "stderr" };
16+
static std::unordered_set<std::string> BLACK_LIST = {"stdin", "stdout", "stderr"};
1717

1818
void GlobalVariableUsageMatchCallback::checkUsage(const MatchFinder::MatchResult &Result) {
1919
if (const auto *pVarDecl =
@@ -50,7 +50,7 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
5050
clang::SourceManager &sourceManager = functionDecl->getASTContext().getSourceManager();
5151
fs::path sourceFilePath = ClangUtils::getSourceFilePath(sourceManager);
5252
auto const &[iterator, inserted] =
53-
usages.emplace(varDecl->getNameAsString(), functionDecl->getNameAsString());
53+
usages.emplace(varDecl->getNameAsString(), functionDecl->getNameAsString());
5454
auto const &usage = *iterator;
5555

5656
LOG_S(MAX) << "Found usage of global variable \'" << usage.variableName << "\' in function \'"
@@ -73,21 +73,21 @@ void GlobalVariableUsageMatchCallback::handleUsage(const clang::FunctionDecl *fu
7373
}
7474

7575
GlobalVariableUsageMatchCallback::Usage::Usage(std::string variableName, std::string functionName)
76-
: variableName(std::move(variableName)), functionName(std::move(functionName)) {
76+
: variableName(std::move(variableName)), functionName(std::move(functionName)) {
7777
}
7878

7979
bool GlobalVariableUsageMatchCallback::Usage::operator==(
80-
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
80+
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
8181
return variableName == rhs.variableName && functionName == rhs.functionName;
8282
}
8383

8484
bool GlobalVariableUsageMatchCallback::Usage::operator!=(
85-
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
85+
const GlobalVariableUsageMatchCallback::Usage &rhs) const {
8686
return !(rhs == *this);
8787
}
8888

8989
std::size_t GlobalVariableUsageMatchCallback::UsageHash::operator()(
90-
const GlobalVariableUsageMatchCallback::Usage &usage) const {
90+
const GlobalVariableUsageMatchCallback::Usage &usage) const {
9191
size_t seed = 0;
9292
HashUtils::hashCombine(seed, usage.variableName, usage.functionName);
9393
return seed;

server/src/printers/Printer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ namespace printer {
2929
typedef const std::vector<std::string> &VSRef;
3030
typedef std::stringstream &Stream;
3131

32-
std::stringstream ss;
32+
std::stringstream ss{};
3333
int tabsDepth = 0;
3434
int commentDepth = 0;
3535
utbot::Language srcLanguage = utbot::Language::UNKNOWN;

0 commit comments

Comments
 (0)