Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion server/src/KleeGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ static std::string getUTBotClangCompilerPath(fs::path clientCompilerPath) {
}
}

static const std::unordered_set<std::string> UNSUPPORTED_FLAGS_AND_OPTIONS_KLEE = {
"--coverage",
"-fbranch-target-load-optimize",
"-fcx-fortran-rules",
"-fipa-cp-clone",
"-fipa-cp-cloneclang-10",
"-fira-loop-pressure",
"-fno-forward-propagate",
"-fno-if-conversion",
"-fno-sched-interblock",
"-fno-sched-spec-insn-heuristic",
"-fno-tree-dominator-opts",
"-fno-tree-sink",
"-fno-tree-sinkclang-10",
"-fpredictive-commoning",
"-fprofile-dir",
"-freschedule-modulo-scheduled-loops",
"-fsched2-use-superblocks",
"-fsel-sched-reschedule-pipelined",
"-ftree-loop-distribute-patterns",
};

std::optional<utbot::CompileCommand>
KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
const CollectionUtils::FileSet &stubSources,
Expand All @@ -121,7 +143,7 @@ KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
fs::create_directories(outFilePath.parent_path());
command.setOutput(outFilePath);
command.setOptimizationLevel("-O0");
command.removeGccFlags();
command.removeCompilerFlagsAndOptions(UNSUPPORTED_FLAGS_AND_OPTIONS_KLEE);
std::vector<std::string> extraFlags{ "-emit-llvm",
"-c",
"-Xclang",
Expand Down
47 changes: 9 additions & 38 deletions server/src/building/CompileCommand.cpp
Original file line number Diff line number Diff line change
@@ -1,40 +1,16 @@
#include "CompileCommand.h"

#include "BaseCommand.h"
#include "Paths.h"
#include "printers/CCJsonPrinter.h"
#include "utils/StringUtils.h"

#include "loguru.h"

#include <algorithm>
#include <iterator>
#include <set>
#include <utility>

namespace utbot {
// See https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
static const std::unordered_set<std::string> gccSpecificOptions = {
"-std", "-fpermitted-flt-eval-methods", "-fopenacc-dim", "-fopenacc-kernels", "-fsso-struct"
};

static const std::unordered_set<std::string> gccSpecificFlags = {
"-ansi", "-fgnu89-inline",
"-fpermitted-flt-eval-methods",
"-fallow-parameterless-variadic-functions",
"-fno-asm",
"-fno-builtin",
"-fno-builtin-function", "-fgimple",
"-fhosted",
"-ffreestanding",
"-fopenacc",
"-fopenmp", "-fopenmp-simd",
"-fms-extensions", "-fplan9-extensions",
"-fallow-single-precision", "-fcond-mismatch", "-flax-vector-conversions",
"-fsigned-bitfields", "-fsigned-char",
"-funsigned-bitfields", "-funsigned-char"
};

CompileCommand::CompileCommand(CompileCommand const &other) : BaseCommand(other) {
compiler = commandLine.begin();
sourcePath =
Expand Down Expand Up @@ -131,20 +107,15 @@ namespace utbot {
*(this->output) = std::move(output);
}

void CompileCommand::removeGccFlags() {
CollectionUtils::erase(commandLine, "--coverage");
CollectionUtils::erase(commandLine, "-fprofile-dir=.");
}

void CompileCommand::filterCFlags() {
size_t erased = CollectionUtils::erase_if(commandLine, [](std::string const &arg) {
size_t pos = arg.find('=');
if (pos != std::string::npos) {
return CollectionUtils::contains(gccSpecificOptions, arg.substr(0, pos));
}
return CollectionUtils::contains(gccSpecificFlags, arg);
});
LOG_S(DEBUG) << erased << " C specific flags erased from compile arguments";
void CompileCommand::removeCompilerFlagsAndOptions(
const std::unordered_set<std::string> &switchesToRemove) {
size_t erased =
CollectionUtils::erase_if(commandLine, [&switchesToRemove](std::string const &arg) {
size_t pos = arg.find('=');
const std::string &toFind = pos == std::string::npos ? arg : arg.substr(0, pos);
return CollectionUtils::contains(switchesToRemove, toFind);
});
LOG_S(DEBUG) << erased << " Compiler specific switches erased from compile arguments";
}

void CompileCommand::removeIncludeFlags() {
Expand Down
4 changes: 1 addition & 3 deletions server/src/building/CompileCommand.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ namespace utbot {

void setOutput(fs::path output);

void removeGccFlags();

void filterCFlags();
void removeCompilerFlagsAndOptions(const std::unordered_set<std::string> &switchesToRemove);

void removeIncludeFlags();

Expand Down
34 changes: 31 additions & 3 deletions server/src/printers/NativeMakefilePrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,35 @@ namespace printer {
static const std::string SHARED_FLAG = "-shared";
static const std::string RELOCATE_FLAG = "-r";
static const std::string OPTIMIZATION_FLAG = "-O0";


static const std::unordered_set<std::string> UNSUPPORTED_FLAGS_AND_OPTIONS_TEST_MAKE = {
// See https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
"-ansi",
"-fallow-parameterless-variadic-functions",
"-fallow-single-precision",
"-fcond-mismatch",
"-ffreestanding",
"-fgnu89-inline",
"-fhosted",
"-flax-vector-conversions",
"-fms-extensions",
"-fno-asm",
"-fno-builtin",
"-fno-builtin-function",
"-fgimple",
"-fopenacc",
"-fopenacc-dim",
"-fopenacc-kernels",
"-fopenmp",
"-fopenmp-simd",
"-fpermitted-flt-eval-methods",
"-fplan9-extensions",
"-fsigned-bitfields",
"-fsigned-char",
"-fsso-struct",
"-funsigned-bitfields",
"-funsigned-char",
"-std",
};

static void eraseIfWlOnly(std::string &argument) {
if (argument == "-Wl") {
Expand Down Expand Up @@ -257,7 +284,8 @@ namespace printer {
auto testCompilationCommand = compilationUnitInfo->command;
testCompilationCommand.setCompiler(primaryCxxCompiler);
testCompilationCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
testCompilationCommand.filterCFlags();
testCompilationCommand.removeCompilerFlagsAndOptions(
UNSUPPORTED_FLAGS_AND_OPTIONS_TEST_MAKE);
testCompilationCommand.removeIncludeFlags();
testCompilationCommand.addFlagToBegin(stringFormat("-I%s", Paths::getGtestLibPath() / "googletest/include"));
if (Paths::isCXXFile(sourcePath)) {
Expand Down