Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement code coverage transformation #179

Draft
wants to merge 97 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
97 commits
Select commit Hold shift + click to select a range
3af52dc
Implement code coverage transformation
JamesLee-Jones Nov 1, 2023
96c8f04
Formatting
JamesLee-Jones Nov 1, 2023
a67d4bf
Reduce the number of side-effects from assignment
JamesLee-Jones Nov 2, 2023
580530c
Formatting
JamesLee-Jones Nov 2, 2023
07ef7af
Check if divisor is 0 when replacing with div
JamesLee-Jones Nov 2, 2023
f19c09b
Replace assignment with arg2
JamesLee-Jones Nov 2, 2023
d254663
Fix error caused by \!(arg1())
JamesLee-Jones Nov 2, 2023
bd1d212
Remove side effects from L-Value Expr mutation
JamesLee-Jones Nov 3, 2023
9227e79
Merge main
JamesLee-Jones Nov 13, 2023
54a16d8
Merge main
JamesLee-Jones Nov 15, 2023
77cdd1e
Update mutation_coverage_expr
JamesLee-Jones Nov 15, 2023
5904772
Update coverage mutators
JamesLee-Jones Nov 15, 2023
33f82d6
Only add no_op when semantics-preserving
JamesLee-Jones Nov 15, 2023
22562a0
CI Fixes
JamesLee-Jones Nov 15, 2023
4760bcb
Remove const qualifier
JamesLee-Jones Nov 15, 2023
671e967
Compatibility improvements
JamesLee-Jones Nov 16, 2023
681a968
Avoid mutating NULL
JamesLee-Jones Nov 17, 2023
31cae02
Check if parent is a cast
JamesLee-Jones Nov 17, 2023
731d979
Experiments
JamesLee-Jones Nov 17, 2023
5a11123
Only avoid mutating if being cast to pointer type
JamesLee-Jones Nov 17, 2023
b979838
Add single file test cases
JamesLee-Jones Nov 17, 2023
1ce5acf
Merge branch 'avoid-mutating-null' into semantics-preserving-code-cov…
JamesLee-Jones Nov 17, 2023
a0f36f3
Maintain semantic equivalence
JamesLee-Jones Nov 17, 2023
bb2fb0a
Formatting
JamesLee-Jones Nov 17, 2023
5832572
Change actual_result type
JamesLee-Jones Nov 18, 2023
a0e0c42
Avoid lambdas as we don't need to worry about side-effects
JamesLee-Jones Nov 18, 2023
8553f5a
Refactor mutation_replace_binary_operator to use macros
JamesLee-Jones Nov 22, 2023
2222ccc
Replace mutations with single macro
JamesLee-Jones Nov 22, 2023
38f8a9f
Formatting
JamesLee-Jones Nov 22, 2023
1a3f841
Tidy up
JamesLee-Jones Nov 22, 2023
a8e10e6
Use individual mutator functions
JamesLee-Jones Nov 22, 2023
683b2e9
Add prelude and return macros
JamesLee-Jones Nov 22, 2023
9f97b3b
Add evaluation specifier
JamesLee-Jones Nov 22, 2023
521c35f
Fix macro name bug
JamesLee-Jones Nov 22, 2023
8250e11
Regenerate single_file tests
JamesLee-Jones Nov 22, 2023
9b0e9d3
Update unit tests
JamesLee-Jones Nov 22, 2023
c02999c
Formatting
JamesLee-Jones Nov 22, 2023
bc0665f
Add const
JamesLee-Jones Nov 22, 2023
4e8275e
Macro name bug fixes
JamesLee-Jones Nov 23, 2023
2f852e4
Formatting
JamesLee-Jones Nov 23, 2023
e1d07a0
Clang-tidy fixes
JamesLee-Jones Nov 23, 2023
db1d56a
Merge macro refactoring
JamesLee-Jones Nov 27, 2023
f0fc802
Make --mutation-info-file optional
JamesLee-Jones Nov 21, 2023
11fb091
Improve checks
JamesLee-Jones Nov 21, 2023
860076d
iwyu fix
JamesLee-Jones Nov 21, 2023
e4fa6d8
Make ApplyMutations return optional
JamesLee-Jones Nov 21, 2023
91f6213
Encapsulate whether to build tree in protobufs
JamesLee-Jones Nov 21, 2023
a08e960
Formatting
JamesLee-Jones Nov 21, 2023
b931425
Address review comments
JamesLee-Jones Jan 30, 2024
2102c2a
Fix formatting
JamesLee-Jones Jan 30, 2024
656c055
Bug fixes
JamesLee-Jones Jan 30, 2024
fa724bf
Combine coverage and semantics preserving into one file
JamesLee-Jones Feb 21, 2024
e6206f0
Make assign binary operators semantics preserving
JamesLee-Jones Feb 21, 2024
7bb7852
Merge branch 'make-mutation-info-file-optional' into semantics-preser…
JamesLee-Jones Feb 21, 2024
578ba4a
Make extra-code coverage preserve semantics
JamesLee-Jones Feb 21, 2024
2832db4
Fixes for CI
JamesLee-Jones Feb 21, 2024
467e844
Begin implementing safe math checks
JamesLee-Jones Mar 23, 2024
a814495
Insert Dredd declarations before first function
JamesLee-Jones Apr 11, 2024
233ff3f
IWYU fixes
JamesLee-Jones Apr 11, 2024
295b3b0
Add new test case
JamesLee-Jones Apr 11, 2024
a4ef4cd
Merge branch 'change-dredd-declaration-location' into semantics-prese…
JamesLee-Jones Apr 24, 2024
c5fe638
Ensure code coverage is semantics preserving
JamesLee-Jones May 12, 2024
f69073e
Finish binary safe math checks
JamesLee-Jones May 15, 2024
1bed2ed
Semantics fixes
JamesLee-Jones May 15, 2024
828a386
Fix safe math bugs
JamesLee-Jones May 16, 2024
a19ee02
Make logical operators semantics preserving
JamesLee-Jones May 17, 2024
43b5244
Check if the second argument is 0 for div and mod and ensure inc and …
JamesLee-Jones May 22, 2024
196b54d
Merge branch 'main' into semantics-preserving-code-coverage
JamesLee-Jones May 23, 2024
f5d2cbd
Fix macro + function name clashes and refactor
JamesLee-Jones May 25, 2024
755e9a6
Bug fixes and refactoring
JamesLee-Jones May 25, 2024
deee55d
Add cast to boolean expressions + refactor
JamesLee-Jones May 26, 2024
dd39fa7
Add semantics preserving CI tests
JamesLee-Jones May 26, 2024
bdbeee8
Merge branch 'main' into semantics-preserving-code-coverage
JamesLee-Jones May 26, 2024
74e858f
Update semantics preserving CI
JamesLee-Jones May 28, 2024
f2f104a
Fix semantics bugs
JamesLee-Jones Jun 5, 2024
e4cbdfe
Update mult safe math check
JamesLee-Jones Jun 6, 2024
b630f49
Make sure C changes preserve semantics
JamesLee-Jones Jun 9, 2024
aedc7b4
Bug fix & add tests for semantics preserving
JamesLee-Jones Jul 7, 2024
7f3e1ec
Use semantics-preserving on CI
JamesLee-Jones Jul 7, 2024
9da2f46
Merge main & fix checks
JamesLee-Jones Jul 7, 2024
a8506d7
Increase cognitive complexity threshold
JamesLee-Jones Jul 8, 2024
302e34b
Update single file tests
JamesLee-Jones Jul 8, 2024
27d319a
Update workflow files to remove semantics scripts
JamesLee-Jones Jul 8, 2024
0ee1b1f
Prevent UB when replaceing equals
JamesLee-Jones Jul 8, 2024
3575c37
Make semantics preserving thread safe
JamesLee-Jones Jul 8, 2024
f24a8d9
Merge branch 'main' into semantics-preserving-code-coverage
JamesLee-Jones Jul 8, 2024
70d0bb8
Update single file expectations
JamesLee-Jones Jul 8, 2024
a08de50
use const initialization
JamesLee-Jones Jul 11, 2024
246ad84
Bug fixes
JamesLee-Jones Jul 24, 2024
7879d2b
Make no_op volatile
JamesLee-Jones Jul 25, 2024
0f737b1
Fix bug when left hand side of assignment is side-effecting
JamesLee-Jones Jul 26, 2024
d78e065
Remove redundancy
JamesLee-Jones Jul 26, 2024
9bab88a
Add weak mutation score tracking
JamesLee-Jones Aug 31, 2024
9a9528e
Bug fix
JamesLee-Jones Aug 31, 2024
72a3159
mutation id bug fixes
JamesLee-Jones Aug 31, 2024
bcc5c36
bug fix
JamesLee-Jones Aug 31, 2024
ff6eb5e
Add weak mutation score tracking for C
JamesLee-Jones Sep 1, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
14 changes: 11 additions & 3 deletions .github/workflows/c_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ case "$(uname)" in
sudo rm -f /swapfile
sudo apt clean
# shellcheck disable=SC2046
docker rmi $(docker image ls -aq)
if [ -n "$(docker image ls -aq)" ]; then
docker rmi $(docker image ls -aq)
fi
df -h
;;

Expand Down Expand Up @@ -79,6 +81,12 @@ popd
# Check that dredd works on some projects
DREDD_EXECUTABLE="${DREDD_ROOT}/third_party/clang+llvm/bin/dredd"
cp "${DREDD_ROOT}/build/src/dredd/dredd" "${DREDD_EXECUTABLE}"
if [ "$SEMANTICS_PRESERVING" == "true" ]; then
DREDD_SEMANTICS_PRESERVING="--semantics-preserving-coverage-instrumentation"
else
DREDD_SEMANTICS_PRESERVING=""
fi


echo "Curl"
date
Expand All @@ -96,7 +104,7 @@ pushd curl
FILES+=("${f}")
done

"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "build/compile_commands.json" "${FILES[@]}"
"${DREDD_EXECUTABLE}" $DREDD_SEMANTICS_PRESERVING --mutation-info-file temp.json -p "build/compile_commands.json" "${FILES[@]}"
pushd build
ninja
# TODO: run some tests
Expand Down Expand Up @@ -125,7 +133,7 @@ pushd zstd
do
FILES+=("${f}")
done
"${DREDD_EXECUTABLE}" --mutation-info-file temp.json -p "temp/compile_commands.json" "${FILES[@]}"
"${DREDD_EXECUTABLE}" $DREDD_SEMANTICS_PRESERVING --mutation-info-file temp.json -p "temp/compile_commands.json" "${FILES[@]}"
# Build mutated zstd
make clean
CFLAGS=-O0 make zstd-release
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/c_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ jobs:
- ubuntu-22.04
config:
- Release
semantics-preserving: [true, false]

runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
CONFIG: ${{ matrix.config }}
SEMANTICS_PRESERVING: ${{ matrix.semantics-preserving }}
steps:

- name: cancel_previous
Expand Down
15 changes: 10 additions & 5 deletions .github/workflows/cxx_apps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,16 @@ cmake --build build --config Debug
# Check that dredd works on some projects
DREDD_EXECUTABLE="${DREDD_ROOT}/third_party/clang+llvm/bin/dredd"
cp "${DREDD_ROOT}/build/src/dredd/dredd" "${DREDD_EXECUTABLE}"
if [ "$SEMANTICS_PRESERVING" == "true" ]; then
DREDD_SEMANTICS_PRESERVING="--semantics-preserving-coverage-instrumentation"
else
DREDD_SEMANTICS_PRESERVING=""
fi

echo "examples/simple/pi.cc: check that we can build the simple example"
date

${DREDD_EXECUTABLE} --mutation-info-file temp.json examples/simple/pi.cc
${DREDD_EXECUTABLE} $DREDD_SEMANTICS_PRESERVING --mutation-info-file temp.json examples/simple/pi.cc
clang++ examples/simple/pi.cc -o examples/simple/pi
diff <(./examples/simple/pi) <(echo "3.14159")

Expand All @@ -91,7 +96,7 @@ pushd examples/math
cp -r math math-original
cmake -S . -B build -G Ninja -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
cmake --build build
${DREDD_EXECUTABLE} -p build/compile_commands.json --mutation-info-file mutation-info.json math/src/*.cc
${DREDD_EXECUTABLE} $DREDD_SEMANTICS_PRESERVING -p build/compile_commands.json --mutation-info-file mutation-info.json math/src/*.cc
./build/mathtest/mathtest
NUM_MUTANTS=`python3 ${DREDD_ROOT}/scripts/query_mutant_info.py mutation-info.json --largest-mutant-id`
EXPECTED_NUM_MUTANTS=1132
Expand Down Expand Up @@ -120,7 +125,7 @@ pushd examples/threaded
[[ -e "$f" ]] || break
FILES+=("${DREDD_ROOT}/examples/threaded/${f}")
done
${DREDD_EXECUTABLE} --mutation-info-file temp.json -p "${DREDD_ROOT}/examples/threaded/build/compile_commands.json" "${FILES[@]}"
${DREDD_EXECUTABLE} $DREDD_SEMANTICS_PRESERVING --mutation-info-file temp.json -p "${DREDD_ROOT}/examples/threaded/build/compile_commands.json" "${FILES[@]}"
cmake --build build
# Check that the application runs correctly and that there are no data races.
TSAN_OPTIONS=halt_on_error=1 ./build/threaded > threaded_output.txt
Expand Down Expand Up @@ -150,7 +155,7 @@ pushd SPIRV-Tools
[[ -e "$f" ]] || break
FILES+=("${DREDD_ROOT}/SPIRV-Tools/${f}")
done
${DREDD_EXECUTABLE} --mutation-info-file mutation-info.json -p "${DREDD_ROOT}/SPIRV-Tools/build/compile_commands.json" "${FILES[@]}"
${DREDD_EXECUTABLE} $DREDD_SEMANTICS_PRESERVING --mutation-info-file mutation-info.json -p "${DREDD_ROOT}/SPIRV-Tools/build/compile_commands.json" "${FILES[@]}"
cmake --build build --target test_val_abcde test_val_capability test_val_fghijklmnop test_val_limits test_val_rstuvw
./build/test/val/test_val_abcde
./build/test/val/test_val_capability
Expand Down Expand Up @@ -180,7 +185,7 @@ pushd llvm-project
[[ -e "$f" ]] || break
FILES+=("${DREDD_ROOT}/llvm-project/${f}")
done
${DREDD_EXECUTABLE} --mutation-info-file mutation-info.json -p "${DREDD_ROOT}/llvm-project/build/compile_commands.json" "${FILES[@]}"
${DREDD_EXECUTABLE} $DREDD_SEMANTICS_PRESERVING --mutation-info-file mutation-info.json -p "${DREDD_ROOT}/llvm-project/build/compile_commands.json" "${FILES[@]}"
cmake --build build --target LLVMInstCombine
NUM_MUTANTS=`python3 ${DREDD_ROOT}/scripts/query_mutant_info.py mutation-info.json --largest-mutant-id`
EXPECTED_NUM_MUTANTS=97675
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/cxx_apps.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ jobs:
- ubuntu-22.04
config:
- Release
semantics-preserving: [true, false]

runs-on: ${{ matrix.os }}
env:
OS: ${{ matrix.os }}
CONFIG: ${{ matrix.config }}
SEMANTICS_PRESERVING: ${{ matrix.semantics-preserving }}
steps:

- name: cancel_previous
Expand Down
6 changes: 1 addition & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ We first show how to apply Dredd to a simple stand-alone program. We will then s

```
# This will modify pi.cc in-place.
# The --mutation-info-file argument is used to specify a JSON file to
# which Dredd will output machine-readable information about the
# mutations it applied. For the purposes of this example, this file
# can be ignored.
${DREDD_EXECUTABLE} examples/simple/pi.cc --mutation-info-file temp.json
${DREDD_EXECUTABLE} examples/simple/pi.cc
# Now compile the mutated version of the example
${DREDD_CLANG_BIN_DIR}/clang++ examples/simple/pi.cc -o examples/simple/pi
```
Expand Down
124 changes: 64 additions & 60 deletions scripts/check_one_single_file_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,80 +23,84 @@ DREDD_INSTALLED_EXECUTABLE="${DREDD_REPO_ROOT}/third_party/clang+llvm/bin/dredd"
# Move to the temporary directory
pushd "${DREDD_REPO_ROOT}/temp"

if [ -z "${DREDD_SKIP_COPY_EXECUTABLE+x}" ]
if [ -z "${DREDD_SKIP_COPY_EXECUTABLE+x}" ]
then
# Ensure that Dredd is in its installed location. This depends on a
# debug build being available
cp build-Debug/src/dredd/dredd "${DREDD_INSTALLED_EXECUTABLE}"
fi

f="${DREDD_REPO_ROOT}/${1}"

for opt in "semantics_preserving" "opt" "noopt"
do
# Determine whether optimisations should be disabled or not, and whether the
# name of the expectation file should reflect this.
DREDD_EXTRA_ARGS=""
DREDD_EXPECTED_FILE=""
if [ ${opt} == "noopt" ]
then
# Ensure that Dredd is in its installed location. This depends on a
# debug build being available
cp build-Debug/src/dredd/dredd "${DREDD_INSTALLED_EXECUTABLE}"
DREDD_EXTRA_ARGS="--no-mutation-opts"
DREDD_EXPECTED_FILE="$f.noopt.expected"
elif [ ${opt} == "opt" ]
then
DREDD_EXPECTED_FILE="$f.expected"
else
DREDD_EXTRA_ARGS="--semantics-preserving-coverage-instrumentation"
DREDD_EXPECTED_FILE="$f.semantics_preserving.expected"
fi

f="${DREDD_REPO_ROOT}/${1}"

for opt in "opt" "noopt"
do
# Determine whether optimisations should be disabled or not, and whether the
# name of the expectation file should reflect this.
DREDD_EXTRA_ARGS=""
DREDD_EXPECTED_FILE=""
if [ ${opt} == "noopt" ]
then
DREDD_EXTRA_ARGS="--no-mutation-opts"
DREDD_EXPECTED_FILE="$f.noopt.expected"
else
DREDD_EXPECTED_FILE="$f.expected"
fi
# Copy the single-file test case to the temporary directory so
# that it can be mutated without affecting the original
cp "$f" .
copy_of_f=$(basename "$f")

# Copy the single-file test case to the temporary directory so
# that it can be mutated without affecting the original
cp "$f" .
copy_of_f=$(basename "$f")
# Mutate the test case using Dredd
${DREDD_INSTALLED_EXECUTABLE} ${DREDD_EXTRA_ARGS} --mutation-info-file temp.json "${copy_of_f}" --

# Mutate the test case using Dredd
${DREDD_INSTALLED_EXECUTABLE} ${DREDD_EXTRA_ARGS} --mutation-info-file temp.json "${copy_of_f}" --
# Check that the JSON generated by Dredd is valid
check_json.py temp.json

# Check that the JSON generated by Dredd is valid
check_json.py temp.json
if [ -z "${DREDD_REGENERATE_TEST_CASE+x}" ]
then
# Check that the mutated test case is as expected
diff --strip-trailing-cr "${copy_of_f}" "${DREDD_EXPECTED_FILE}"
fi

if [ -z "${DREDD_REGENERATE_TEST_CASE+x}" ]
# Check that the mutated file compiles
if [[ $f == *.cc ]]
then
# Extra C++ arguments can be passed;
# this is needed on OSX to set an appropriate C++ standard.
if [ -z "${DREDD_EXTRA_CXX_ARGS+x}" ]
then
# Check that the mutated test case is as expected
diff --strip-trailing-cr "${copy_of_f}" "${DREDD_EXPECTED_FILE}"
${CXX} -c "${copy_of_f}"
else
${CXX} "${DREDD_EXTRA_CXX_ARGS}" -c "${copy_of_f}"
fi

# Check that the mutated file compiles
if [[ $f == *.cc ]]
else
# Extra C arguments can be passed;
# this is needed on Windows to set an appropriate C standard.
if [ -z "${DREDD_EXTRA_C_ARGS+x}" ]
then
# Extra C++ arguments can be passed;
# this is needed on OSX to set an appropriate C++ standard.
if [ -z "${DREDD_EXTRA_CXX_ARGS+x}" ]
then
${CXX} -c "${copy_of_f}"
else
${CXX} "${DREDD_EXTRA_CXX_ARGS}" -c "${copy_of_f}"
fi
${CC} -c "${copy_of_f}"
else
# Extra C arguments can be passed;
# this is needed on Windows to set an appropriate C standard.
if [ -z "${DREDD_EXTRA_C_ARGS+x}" ]
then
${CC} -c "${copy_of_f}"
else
${CC} "${DREDD_EXTRA_C_ARGS}" -c "${copy_of_f}"
fi
${CC} "${DREDD_EXTRA_C_ARGS}" -c "${copy_of_f}"
fi
fi

if [ "${DREDD_REGENERATE_TEST_CASE+x}" ]
then
# Copy the mutated file so that it becomes the new test expectation
cp "${copy_of_f}" "${DREDD_EXPECTED_FILE}"
fi
if [ "${DREDD_REGENERATE_TEST_CASE+x}" ]
then
# Copy the mutated file so that it becomes the new test expectation
cp "${copy_of_f}" "${DREDD_EXPECTED_FILE}"
fi

# Clean up
rm "${copy_of_f}"
# Account for the fact that the script may be running under various OSes
rm -f "${copy_of_f%.*}".o
rm -f "${copy_of_f%.*}".obj
# Clean up
rm "${copy_of_f}"
# Account for the fact that the script may be running under various OSes
rm -f "${copy_of_f%.*}".o
rm -f "${copy_of_f%.*}".obj

done
done

popd
2 changes: 2 additions & 0 deletions src/.clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,6 @@ WarningsAsErrors: '*'
HeaderFilterRegex: '.*dredd.*'
AnalyzeTemporaryDtors: false
FormatStyle: file
CheckOptions:
readability-function-cognitive-complexity.Threshold: 70
...
28 changes: 21 additions & 7 deletions src/dredd/src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

#include <fstream>
#include <memory>
#include <optional>
#include <string>

#include "clang/Tooling/CommonOptionsParser.h"
Expand Down Expand Up @@ -55,13 +56,20 @@ static llvm::cl::opt<bool> only_track_mutant_coverage(
"an input, rather than actually applying any mutants."),
llvm::cl::cat(mutate_category));
// NOLINTNEXTLINE
static llvm::cl::opt<bool> semantics_preserving_coverage_instrumentation(
"semantics-preserving-coverage-instrumentation",
llvm::cl::desc(
"Apply a semantics preserving transformation to the source code "
"which adds extra code coverage points."),
llvm::cl::cat(mutate_category));
// NOLINTNEXTLINE
static llvm::cl::opt<bool> dump_asts(
"dump-asts",
llvm::cl::desc("Dump each AST that is processed; useful for debugging"),
llvm::cl::cat(mutate_category));
// NOLINTNEXTLINE
static llvm::cl::opt<std::string> mutation_info_file(
"mutation-info-file", llvm::cl::Required,
"mutation-info-file",
llvm::cl::desc(
".json file into which mutation information should be written"),
llvm::cl::cat(mutate_category));
Expand Down Expand Up @@ -94,24 +102,30 @@ int main(int argc, const char** argv) {

// Keeps track of the mutations that are applied to each source file,
// including their hierarchical structure.
dredd::protobufs::MutationInfo mutation_info;
std::optional<dredd::protobufs::MutationInfo> mutation_info;

if (mutation_info_file.empty()) {
mutation_info = std::nullopt;
} else {
mutation_info = dredd::protobufs::MutationInfo();
}

const std::unique_ptr<clang::tooling::FrontendActionFactory> factory =
dredd::NewMutateFrontendActionFactory(!no_mutation_opts, dump_asts,
only_track_mutant_coverage,
mutation_id, mutation_info);
dredd::NewMutateFrontendActionFactory(
!no_mutation_opts, semantics_preserving_coverage_instrumentation,
dump_asts, only_track_mutant_coverage, mutation_id, mutation_info);

const int return_code = Tool.run(factory.get());

if (return_code == 0) {
if (mutation_info.has_value() && return_code == 0) {
// Application of mutations was successful, so write out the mutation info
// in JSON format.
std::string json_string;
auto json_options = google::protobuf::util::JsonOptions();
json_options.add_whitespace = true;
json_options.always_print_primitive_fields = true;
auto json_generation_status = google::protobuf::util::MessageToJsonString(
mutation_info, &json_string, json_options);
mutation_info.value(), &json_string, json_options);
if (json_generation_status.ok()) {
std::ofstream transformations_json_file(mutation_info_file);
transformations_json_file << json_string;
Expand Down
9 changes: 5 additions & 4 deletions src/libdredd/include/libdredd/mutation.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,11 @@ class Mutation {
// avoiding redundant repeat declarations.
virtual protobufs::MutationGroup Apply(
clang::ASTContext& ast_context, const clang::Preprocessor& preprocessor,
bool optimise_mutations, bool only_track_mutant_coverage,
int first_mutation_id_in_file, int& mutation_id,
clang::Rewriter& rewriter,
std::unordered_set<std::string>& dredd_declarations) const = 0;
bool optimise_mutations, bool semantics_preserving_mutation,
bool only_track_mutant_coverage, int first_mutation_id_in_file,
int& mutation_id, clang::Rewriter& rewriter,
std::unordered_set<std::string>& dredd_declarations,
std::unordered_set<std::string>& dredd_macros) const = 0;
};

} // namespace dredd
Expand Down
9 changes: 5 additions & 4 deletions src/libdredd/include/libdredd/mutation_remove_stmt.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ class MutationRemoveStmt : public Mutation {

protobufs::MutationGroup Apply(
clang::ASTContext& ast_context, const clang::Preprocessor& preprocessor,
bool optimise_mutations, bool only_track_mutant_coverage,
int first_mutation_id_in_file, int& mutation_id,
clang::Rewriter& rewriter,
std::unordered_set<std::string>& dredd_declarations) const override;
bool optimise_mutations, bool semantics_preserving_mutation,
bool only_track_mutant_coverage, int first_mutation_id_in_file,
int& mutation_id, clang::Rewriter& rewriter,
std::unordered_set<std::string>& dredd_declarations,
std::unordered_set<std::string>& dredd_macros) const override;

private:
// Helper method to determine whether the token immediately following the
Expand Down
Loading