Skip to content

Commit 05c17ea

Browse files
Alexey Utkinalexey-utkin
authored andcommitted
#246 Support (or ignore) gcc-specific switches while analyzing in clang toolchain
1 parent 941011d commit 05c17ea

File tree

4 files changed

+64
-45
lines changed

4 files changed

+64
-45
lines changed

server/src/KleeGenerator.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,28 @@ static std::string getUTBotClangCompilerPath(fs::path clientCompilerPath) {
101101
}
102102
}
103103

104+
static const std::unordered_set<std::string> UNSUPPORTED_FLAGS_AND_OPTIONS_KLEE = {
105+
"--coverage",
106+
"-fbranch-target-load-optimize",
107+
"-fcx-fortran-rules",
108+
"-fipa-cp-clone",
109+
"-fipa-cp-cloneclang-10",
110+
"-fira-loop-pressure",
111+
"-fno-forward-propagate",
112+
"-fno-if-conversion",
113+
"-fno-sched-interblock",
114+
"-fno-sched-spec-insn-heuristic",
115+
"-fno-tree-dominator-opts",
116+
"-fno-tree-sink",
117+
"-fno-tree-sinkclang-10",
118+
"-fpredictive-commoning",
119+
"-fprofile-dir",
120+
"-freschedule-modulo-scheduled-loops",
121+
"-fsched2-use-superblocks",
122+
"-fsel-sched-reschedule-pipelined",
123+
"-ftree-loop-distribute-patterns",
124+
};
125+
104126
std::optional<utbot::CompileCommand>
105127
KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
106128
const CollectionUtils::FileSet &stubSources,
@@ -121,7 +143,7 @@ KleeGenerator::getCompileCommandForKlee(const fs::path &hintPath,
121143
fs::create_directories(outFilePath.parent_path());
122144
command.setOutput(outFilePath);
123145
command.setOptimizationLevel("-O0");
124-
command.removeGccFlags();
146+
command.removeCompilerFlagsAndOptions(UNSUPPORTED_FLAGS_AND_OPTIONS_KLEE);
125147
std::vector<std::string> extraFlags{ "-emit-llvm",
126148
"-c",
127149
"-Xclang",

server/src/building/CompileCommand.cpp

Lines changed: 9 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,16 @@
11
#include "CompileCommand.h"
22

3-
#include "BaseCommand.h"
43
#include "Paths.h"
54
#include "printers/CCJsonPrinter.h"
65
#include "utils/StringUtils.h"
76

87
#include "loguru.h"
98

109
#include <algorithm>
11-
#include <iterator>
1210
#include <set>
1311
#include <utility>
1412

1513
namespace utbot {
16-
// See https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
17-
static const std::unordered_set<std::string> gccSpecificOptions = {
18-
"-std", "-fpermitted-flt-eval-methods", "-fopenacc-dim", "-fopenacc-kernels", "-fsso-struct"
19-
};
20-
21-
static const std::unordered_set<std::string> gccSpecificFlags = {
22-
"-ansi", "-fgnu89-inline",
23-
"-fpermitted-flt-eval-methods",
24-
"-fallow-parameterless-variadic-functions",
25-
"-fno-asm",
26-
"-fno-builtin",
27-
"-fno-builtin-function", "-fgimple",
28-
"-fhosted",
29-
"-ffreestanding",
30-
"-fopenacc",
31-
"-fopenmp", "-fopenmp-simd",
32-
"-fms-extensions", "-fplan9-extensions",
33-
"-fallow-single-precision", "-fcond-mismatch", "-flax-vector-conversions",
34-
"-fsigned-bitfields", "-fsigned-char",
35-
"-funsigned-bitfields", "-funsigned-char"
36-
};
37-
3814
CompileCommand::CompileCommand(CompileCommand const &other) : BaseCommand(other) {
3915
compiler = commandLine.begin();
4016
sourcePath =
@@ -131,20 +107,15 @@ namespace utbot {
131107
*(this->output) = std::move(output);
132108
}
133109

134-
void CompileCommand::removeGccFlags() {
135-
CollectionUtils::erase(commandLine, "--coverage");
136-
CollectionUtils::erase(commandLine, "-fprofile-dir=.");
137-
}
138-
139-
void CompileCommand::filterCFlags() {
140-
size_t erased = CollectionUtils::erase_if(commandLine, [](std::string const &arg) {
141-
size_t pos = arg.find('=');
142-
if (pos != std::string::npos) {
143-
return CollectionUtils::contains(gccSpecificOptions, arg.substr(0, pos));
144-
}
145-
return CollectionUtils::contains(gccSpecificFlags, arg);
146-
});
147-
LOG_S(DEBUG) << erased << " C specific flags erased from compile arguments";
110+
void CompileCommand::removeCompilerFlagsAndOptions(
111+
const std::unordered_set<std::string> &switchesToRemove) {
112+
size_t erased =
113+
CollectionUtils::erase_if(commandLine, [&switchesToRemove](std::string const &arg) {
114+
size_t pos = arg.find('=');
115+
const std::string &toFind = pos == std::string::npos ? arg : arg.substr(0, pos);
116+
return CollectionUtils::contains(switchesToRemove, toFind);
117+
});
118+
LOG_S(DEBUG) << erased << " Compiler specific switches erased from compile arguments";
148119
}
149120

150121
void CompileCommand::removeIncludeFlags() {

server/src/building/CompileCommand.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,7 @@ namespace utbot {
4747

4848
void setOutput(fs::path output);
4949

50-
void removeGccFlags();
51-
52-
void filterCFlags();
50+
void removeCompilerFlagsAndOptions(const std::unordered_set<std::string> &switchesToRemove);
5351

5452
void removeIncludeFlags();
5553

server/src/printers/NativeMakefilePrinter.cpp

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,35 @@ namespace printer {
2929
static const std::string SHARED_FLAG = "-shared";
3030
static const std::string RELOCATE_FLAG = "-r";
3131
static const std::string OPTIMIZATION_FLAG = "-O0";
32-
33-
32+
static const std::unordered_set<std::string> UNSUPPORTED_FLAGS_AND_OPTIONS_TEST_MAKE = {
33+
// See https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html
34+
"-ansi",
35+
"-fallow-parameterless-variadic-functions",
36+
"-fallow-single-precision",
37+
"-fcond-mismatch",
38+
"-ffreestanding",
39+
"-fgnu89-inline",
40+
"-fhosted",
41+
"-flax-vector-conversions",
42+
"-fms-extensions",
43+
"-fno-asm",
44+
"-fno-builtin",
45+
"-fno-builtin-function",
46+
"-fgimple",
47+
"-fopenacc",
48+
"-fopenacc-dim",
49+
"-fopenacc-kernels",
50+
"-fopenmp",
51+
"-fopenmp-simd",
52+
"-fpermitted-flt-eval-methods",
53+
"-fplan9-extensions",
54+
"-fsigned-bitfields",
55+
"-fsigned-char",
56+
"-fsso-struct",
57+
"-funsigned-bitfields",
58+
"-funsigned-char",
59+
"-std",
60+
};
3461

3562
static void eraseIfWlOnly(std::string &argument) {
3663
if (argument == "-Wl") {
@@ -257,7 +284,8 @@ namespace printer {
257284
auto testCompilationCommand = compilationUnitInfo->command;
258285
testCompilationCommand.setCompiler(primaryCxxCompiler);
259286
testCompilationCommand.setOptimizationLevel(OPTIMIZATION_FLAG);
260-
testCompilationCommand.filterCFlags();
287+
testCompilationCommand.removeCompilerFlagsAndOptions(
288+
UNSUPPORTED_FLAGS_AND_OPTIONS_TEST_MAKE);
261289
testCompilationCommand.removeIncludeFlags();
262290
testCompilationCommand.addFlagToBegin(stringFormat("-I%s", Paths::getGtestLibPath() / "googletest/include"));
263291
if (Paths::isCXXFile(sourcePath)) {

0 commit comments

Comments
 (0)