diff --git a/src/libdredd/include_private/include/libdredd/mutate_visitor.h b/src/libdredd/include_private/include/libdredd/mutate_visitor.h index 716e1135..d4313d5c 100644 --- a/src/libdredd/include_private/include/libdredd/mutate_visitor.h +++ b/src/libdredd/include_private/include/libdredd/mutate_visitor.h @@ -33,6 +33,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/Basic/SourceLocation.h" #include "clang/Frontend/CompilerInstance.h" +#include "libdredd/mutation.h" #include "libdredd/mutation_tree_node.h" namespace dredd { @@ -108,6 +109,11 @@ class MutateVisitor : public clang::RecursiveASTVisitor { return constant_sized_arrays_to_rewrite_; } + [[nodiscard]] clang::SourceLocation + GetStartLocationOfFirstFunctionInSourceFile() const { + return start_location_of_first_function_in_source_file_; + } + private: // Helper class that uses the RAII pattern to support pushing a new mutation // tree node on to the stack of mutation tree nodes used during visitation, @@ -174,9 +180,21 @@ class MutateVisitor : public clang::RecursiveASTVisitor { // this special case, so that it can be ignored. bool IsConversionOfEnumToConstructor(const clang::Expr& expr) const; + // It is safe to put Dredd's prelude before the first function we encounter in + // a file as Dredd only makes source code modifications inside functions. + void UpdateStartLocationOfFirstFunctionInSourceFile(); + + // Adds details of a mutation that can be applied, and performs associated + // bookkeeping. + void AddMutation(std::unique_ptr mutation); + const clang::CompilerInstance* compiler_instance_; bool optimise_mutations_; + // Records the start location of the very first function definition in the + // source file, before which Dredd's prelude can be placed. + clang::SourceLocation start_location_of_first_function_in_source_file_; + // Tracks the nest of declarations currently being traversed. Any new Dredd // functions will be put before the start of the current nest, which avoids // e.g. putting a Dredd function inside a class or function. diff --git a/src/libdredd/src/mutate_ast_consumer.cc b/src/libdredd/src/mutate_ast_consumer.cc index 4d237e50..3b3a9a08 100644 --- a/src/libdredd/src/mutate_ast_consumer.cc +++ b/src/libdredd/src/mutate_ast_consumer.cc @@ -137,12 +137,11 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { *mutation_info_->add_info_for_files() = mutation_info_for_file; - auto& source_manager = ast_context.getSourceManager(); - const clang::SourceLocation start_of_source_file = - source_manager.translateLineCol(source_manager.getMainFileID(), 1, 1); - assert(start_of_source_file.isValid() && - "There is at least one mutation, therefore the file must have some " - "content."); + const clang::SourceLocation start_location_of_first_function_in_source_file = + visitor_->GetStartLocationOfFirstFunctionInSourceFile(); + assert(start_location_of_first_function_in_source_file.isValid() && + "There is at least one mutation, therefore there must be at least one " + "function."); // Convert the unordered set Dredd declarations into an ordered set and add // them to the source file before the first declaration. @@ -150,8 +149,8 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { sorted_dredd_declarations.insert(dredd_declarations.begin(), dredd_declarations.end()); for (const auto& decl : sorted_dredd_declarations) { - const bool rewriter_result = - rewriter_.InsertTextBefore(start_of_source_file, decl); + const bool rewriter_result = rewriter_.InsertTextBefore( + start_location_of_first_function_in_source_file, decl); (void)rewriter_result; // Keep release-mode compilers happy. assert(!rewriter_result && "Rewrite failed.\n"); } @@ -161,8 +160,8 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { ? GetDreddPreludeCpp(initial_mutation_id) : GetDreddPreludeC(initial_mutation_id); - bool rewriter_result = - rewriter_.InsertTextBefore(start_of_source_file, dredd_prelude); + bool rewriter_result = rewriter_.InsertTextBefore( + start_location_of_first_function_in_source_file, dredd_prelude); (void)rewriter_result; // Keep release-mode compilers happy. assert(!rewriter_result && "Rewrite failed.\n"); diff --git a/src/libdredd/src/mutate_visitor.cc b/src/libdredd/src/mutate_visitor.cc index c172fdfb..c1155f49 100644 --- a/src/libdredd/src/mutate_visitor.cc +++ b/src/libdredd/src/mutate_visitor.cc @@ -34,6 +34,7 @@ #include "clang/AST/TypeLoc.h" #include "clang/Basic/LangOptions.h" #include "clang/Basic/SourceLocation.h" +#include "clang/Basic/SourceManager.h" #include "clang/Basic/TypeTraits.h" #include "clang/Frontend/CompilerInstance.h" #include "libdredd/mutation.h" @@ -63,6 +64,21 @@ bool MutateVisitor::IsTypeSupported(const clang::QualType qual_type) { (builtin_type->isInteger() || builtin_type->isFloatingPoint()); } +void MutateVisitor::UpdateStartLocationOfFirstFunctionInSourceFile() { + if (IsInFunction()) { + const clang::BeforeThanCompare comparator( + compiler_instance_->getSourceManager()); + auto source_range_in_main_file = GetSourceRangeInMainFile( + compiler_instance_->getPreprocessor(), *enclosing_decls_[0]); + if (start_location_of_first_function_in_source_file_.isInvalid() || + comparator(source_range_in_main_file.getBegin(), + start_location_of_first_function_in_source_file_)) { + start_location_of_first_function_in_source_file_ = + source_range_in_main_file.getBegin(); + } + } +} + bool MutateVisitor::IsInFunction() { // Walk up the next of enclosing declarations for (int index = static_cast(enclosing_decls_.size()) - 1; index >= 0; @@ -352,10 +368,9 @@ void MutateVisitor::HandleUnaryOperator(clang::UnaryOperator* unary_operator) { } } - mutation_tree_path_.back()->AddMutation( - std::make_unique( - *unary_operator, compiler_instance_->getPreprocessor(), - compiler_instance_->getASTContext())); + AddMutation(std::make_unique( + *unary_operator, compiler_instance_->getPreprocessor(), + compiler_instance_->getASTContext())); } void MutateVisitor::HandleBinaryOperator( @@ -415,10 +430,9 @@ void MutateVisitor::HandleBinaryOperator( return; } - mutation_tree_path_.back()->AddMutation( - std::make_unique( - *binary_operator, compiler_instance_->getPreprocessor(), - compiler_instance_->getASTContext())); + AddMutation(std::make_unique( + *binary_operator, compiler_instance_->getPreprocessor(), + compiler_instance_->getASTContext())); } void MutateVisitor::HandleExpr(clang::Expr* expr) { @@ -508,7 +522,7 @@ void MutateVisitor::HandleExpr(clang::Expr* expr) { } } - mutation_tree_path_.back()->AddMutation(std::make_unique( + AddMutation(std::make_unique( *expr, compiler_instance_->getPreprocessor(), compiler_instance_->getASTContext())); } @@ -555,6 +569,7 @@ bool MutateVisitor::VisitExpr(clang::Expr* expr) { return true; } + UpdateStartLocationOfFirstFunctionInSourceFile(); if (auto* unary_operator = llvm::dyn_cast(expr)) { HandleUnaryOperator(unary_operator); } @@ -621,14 +636,18 @@ bool MutateVisitor::TraverseCompoundStmt(clang::CompoundStmt* compound_stmt) { assert(!enclosing_decls_.empty() && "Statements can only be removed if they are nested in some " "declaration."); - mutation_tree_path_.back()->AddMutation( - std::make_unique( - *target_stmt, compiler_instance_->getPreprocessor(), - compiler_instance_->getASTContext())); + AddMutation(std::make_unique( + *target_stmt, compiler_instance_->getPreprocessor(), + compiler_instance_->getASTContext())); } return true; } +void MutateVisitor::AddMutation(std::unique_ptr mutation) { + UpdateStartLocationOfFirstFunctionInSourceFile(); + mutation_tree_path_.back()->AddMutation(std::move(mutation)); +} + bool MutateVisitor::VisitVarDecl(clang::VarDecl* var_decl) { var_decl_source_locations_.insert(var_decl->getLocation()); return true; diff --git a/test/single_file/add_type_aliases.c.noopt.expected b/test/single_file/add_type_aliases.c.noopt.expected index 3faf287f..8638812e 100644 --- a/test/single_file/add_type_aliases.c.noopt.expected +++ b/test/single_file/add_type_aliases.c.noopt.expected @@ -1,3 +1,6 @@ +#include +#include + #include #include #include @@ -152,9 +155,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -#include -#include - int main() { unsigned a; uint32_t b; diff --git a/test/single_file/add_type_aliases.cc.noopt.expected b/test/single_file/add_type_aliases.cc.noopt.expected index b227f0b0..4c54400b 100644 --- a/test/single_file/add_type_aliases.cc.noopt.expected +++ b/test/single_file/add_type_aliases.cc.noopt.expected @@ -1,3 +1,6 @@ +#include +#include + #include #include #include @@ -154,9 +157,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -#include -#include - int main() { unsigned a; uint32_t b; diff --git a/test/single_file/bitfield.c.expected b/test/single_file/bitfield.c.expected index 91dd511e..5626020c 100644 --- a/test/single_file/bitfield.c.expected +++ b/test/single_file/bitfield.c.expected @@ -1,3 +1,8 @@ +struct S { + int a : 3; + int b : 3; +}; + #include #include #include @@ -58,11 +63,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -struct S { - int a : 3; - int b : 3; -}; - void foo() { struct S myS; if (!__dredd_enabled_mutation(6)) { myS.a = __dredd_replace_expr_int(myS.b, 0); } diff --git a/test/single_file/bitfield.c.noopt.expected b/test/single_file/bitfield.c.noopt.expected index 16bb947f..fe020fde 100644 --- a/test/single_file/bitfield.c.noopt.expected +++ b/test/single_file/bitfield.c.noopt.expected @@ -1,3 +1,8 @@ +struct S { + int a : 3; + int b : 3; +}; + #include #include #include @@ -59,11 +64,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -struct S { - int a : 3; - int b : 3; -}; - void foo() { struct S myS; if (!__dredd_enabled_mutation(12)) { __dredd_replace_expr_int(myS.a = __dredd_replace_expr_int(myS.b, 0), 6); } diff --git a/test/single_file/bitfield.cc.expected b/test/single_file/bitfield.cc.expected index 93026006..b289631f 100644 --- a/test/single_file/bitfield.cc.expected +++ b/test/single_file/bitfield.cc.expected @@ -1,3 +1,8 @@ +struct S { + int a : 3; + int b : 3; +}; + #include #include #include @@ -60,11 +65,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -struct S { - int a : 3; - int b : 3; -}; - void foo() { S myS; if (!__dredd_enabled_mutation(6)) { myS.a = __dredd_replace_expr_int(myS.b, 0); } diff --git a/test/single_file/bitfield.cc.noopt.expected b/test/single_file/bitfield.cc.noopt.expected index 027e52cc..307a28e6 100644 --- a/test/single_file/bitfield.cc.noopt.expected +++ b/test/single_file/bitfield.cc.noopt.expected @@ -1,3 +1,8 @@ +struct S { + int a : 3; + int b : 3; +}; + #include #include #include @@ -72,11 +77,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -struct S { - int a : 3; - int b : 3; -}; - void foo() { S myS; if (!__dredd_enabled_mutation(6)) { myS.a = __dredd_replace_expr_int(myS.b, 0); } diff --git a/test/single_file/bitfield_reference_passing.cc.expected b/test/single_file/bitfield_reference_passing.cc.expected index ada685ae..c74bfb9d 100644 --- a/test/single_file/bitfield_reference_passing.cc.expected +++ b/test/single_file/bitfield_reference_passing.cc.expected @@ -1,3 +1,9 @@ +template void bloop(T& x) { } + +struct foo { + int b : 2; +}; + #include #include #include @@ -42,12 +48,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -template void bloop(T& x) { } - -struct foo { - int b : 2; -}; - int main() { const foo d = foo(); if (!__dredd_enabled_mutation(0)) { bloop(d.b); } diff --git a/test/single_file/bitfield_reference_passing.cc.noopt.expected b/test/single_file/bitfield_reference_passing.cc.noopt.expected index ada685ae..c74bfb9d 100644 --- a/test/single_file/bitfield_reference_passing.cc.noopt.expected +++ b/test/single_file/bitfield_reference_passing.cc.noopt.expected @@ -1,3 +1,9 @@ +template void bloop(T& x) { } + +struct foo { + int b : 2; +}; + #include #include #include @@ -42,12 +48,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -template void bloop(T& x) { } - -struct foo { - int b : 2; -}; - int main() { const foo d = foo(); if (!__dredd_enabled_mutation(0)) { bloop(d.b); } diff --git a/test/single_file/boolean_not_insertion_optimisation.c.expected b/test/single_file/boolean_not_insertion_optimisation.c.expected index 57097292..7d24d8a9 100644 --- a/test/single_file/boolean_not_insertion_optimisation.c.expected +++ b/test/single_file/boolean_not_insertion_optimisation.c.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -71,8 +73,6 @@ static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs_zero_lhs_o if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1; return arg; } -#include - int main() { int x = __dredd_replace_expr_int_zero(__dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs_zero_lhs_one_outer(__dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs_zero_lhs_one_lhs(__dredd_replace_expr_int_one(1, 0), 5) && __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs_zero_lhs_one_rhs(__dredd_replace_expr_int_zero(0, 3), 5), 5), 8); } diff --git a/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected b/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected index ead86198..9e643830 100644 --- a/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected +++ b/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -67,8 +69,6 @@ static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_lhs(int arg, i if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1; return arg; } -#include - int main() { int x = __dredd_replace_expr_int(__dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_outer(__dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_lhs(__dredd_replace_expr_int(1, 0), 12) && __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs(__dredd_replace_expr_int(0, 6), 12), 12), 15); } diff --git a/test/single_file/comment.cc.expected b/test/single_file/comment.cc.expected index a73eb888..19a9681b 100644 --- a/test/single_file/comment.cc.expected +++ b/test/single_file/comment.cc.expected @@ -1,3 +1,5 @@ +void g(); + #include #include #include @@ -48,8 +50,6 @@ static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { return arg; } -void g(); - void f() { if (!__dredd_enabled_mutation(0)) { g() /* something */ ; } diff --git a/test/single_file/comment.cc.noopt.expected b/test/single_file/comment.cc.noopt.expected index ce5e7b68..6e5d6935 100644 --- a/test/single_file/comment.cc.noopt.expected +++ b/test/single_file/comment.cc.noopt.expected @@ -1,3 +1,5 @@ +void g(); + #include #include #include @@ -50,8 +52,6 @@ static bool __dredd_replace_expr_bool(bool arg, int local_mutation_id) { return arg; } -void g(); - void f() { if (!__dredd_enabled_mutation(0)) { g() /* something */ ; } diff --git a/test/single_file/comment_at_start_of_file.cc.expected b/test/single_file/comment_at_start_of_file.cc.expected index 903c91ac..550e08bd 100644 --- a/test/single_file/comment_at_start_of_file.cc.expected +++ b/test/single_file/comment_at_start_of_file.cc.expected @@ -1,3 +1,5 @@ +// Hello + #include #include #include @@ -52,8 +54,6 @@ static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { return arg; } -// Hello - int main() { if (!__dredd_enabled_mutation(5)) { return __dredd_replace_expr_int_constant(42, 0); } } diff --git a/test/single_file/comment_at_start_of_file.cc.noopt.expected b/test/single_file/comment_at_start_of_file.cc.noopt.expected index 1c530885..68d9502e 100644 --- a/test/single_file/comment_at_start_of_file.cc.noopt.expected +++ b/test/single_file/comment_at_start_of_file.cc.noopt.expected @@ -1,3 +1,5 @@ +// Hello + #include #include #include @@ -53,8 +55,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -// Hello - int main() { if (!__dredd_enabled_mutation(6)) { return __dredd_replace_expr_int(42, 0); } } diff --git a/test/single_file/const_expr_function.cc.expected b/test/single_file/const_expr_function.cc.expected index 9c2e5174..9b424ea0 100644 --- a/test/single_file/const_expr_function.cc.expected +++ b/test/single_file/const_expr_function.cc.expected @@ -1,3 +1,5 @@ +constexpr int Max(int a, int b) { return a > b ? a : b; } + #include #include #include @@ -52,8 +54,6 @@ static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { return arg; } -constexpr int Max(int a, int b) { return a > b ? a : b; } - int main() { if (!__dredd_enabled_mutation(10)) { Max(__dredd_replace_expr_int_constant(5, 0),__dredd_replace_expr_int_constant(4, 5)); } } diff --git a/test/single_file/const_expr_function.cc.noopt.expected b/test/single_file/const_expr_function.cc.noopt.expected index 2b4e1832..80c68a83 100644 --- a/test/single_file/const_expr_function.cc.noopt.expected +++ b/test/single_file/const_expr_function.cc.noopt.expected @@ -1,3 +1,5 @@ +constexpr int Max(int a, int b) { return a > b ? a : b; } + #include #include #include @@ -64,8 +66,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -constexpr int Max(int a, int b) { return a > b ? a : b; } - int main() { if (!__dredd_enabled_mutation(18)) { __dredd_replace_expr_int([&]() -> int { return Max(__dredd_replace_expr_int(5, 0),__dredd_replace_expr_int(4, 6)); }, 12); } } diff --git a/test/single_file/const_expr_function_call.cc.expected b/test/single_file/const_expr_function_call.cc.expected index 84deb5c0..cf11e652 100644 --- a/test/single_file/const_expr_function_call.cc.expected +++ b/test/single_file/const_expr_function_call.cc.expected @@ -1,3 +1,5 @@ +constexpr int Max(int a, int b) { return a > b ? a : b; } + #include #include #include @@ -62,8 +64,6 @@ static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { return arg; } -constexpr int Max(int a, int b) { return a > b ? a : b; } - int foo() { if (!__dredd_enabled_mutation(15)) { return __dredd_replace_expr_int_constant([&]() -> int { return Max(__dredd_replace_expr_int_constant(5, 0),__dredd_replace_expr_int_constant(4, 5)); }, 10); } } diff --git a/test/single_file/const_expr_function_call.cc.noopt.expected b/test/single_file/const_expr_function_call.cc.noopt.expected index 078ac89a..34a2606c 100644 --- a/test/single_file/const_expr_function_call.cc.noopt.expected +++ b/test/single_file/const_expr_function_call.cc.noopt.expected @@ -1,3 +1,5 @@ +constexpr int Max(int a, int b) { return a > b ? a : b; } + #include #include #include @@ -64,8 +66,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -constexpr int Max(int a, int b) { return a > b ? a : b; } - int foo() { if (!__dredd_enabled_mutation(18)) { return __dredd_replace_expr_int([&]() -> int { return Max(__dredd_replace_expr_int(5, 0),__dredd_replace_expr_int(4, 6)); }, 12); } } diff --git a/test/single_file/constexpr_if1.cc.expected b/test/single_file/constexpr_if1.cc.expected index 0116a359..0c1d025a 100644 --- a/test/single_file/constexpr_if1.cc.expected +++ b/test/single_file/constexpr_if1.cc.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -42,8 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#include - template void foo() { if (!__dredd_enabled_mutation(1)) { if constexpr (a) { if (!__dredd_enabled_mutation(0)) { std::cout << "Hi"; } diff --git a/test/single_file/constexpr_if1.cc.noopt.expected b/test/single_file/constexpr_if1.cc.noopt.expected index 2e7bbb30..4e0e6867 100644 --- a/test/single_file/constexpr_if1.cc.noopt.expected +++ b/test/single_file/constexpr_if1.cc.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -42,8 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#include - template void foo() { if (!__dredd_enabled_mutation(1)) { if constexpr (a) { if (!__dredd_enabled_mutation(0)) { std::cout << "Hi"; } diff --git a/test/single_file/construct_struct_from_enum_constant.cc.expected b/test/single_file/construct_struct_from_enum_constant.cc.expected index ebddef71..45d3b6b7 100644 --- a/test/single_file/construct_struct_from_enum_constant.cc.expected +++ b/test/single_file/construct_struct_from_enum_constant.cc.expected @@ -1,3 +1,10 @@ +struct foo { + foo(int) {}; + operator int(); +}; + +enum baz { bar }; + #include #include #include @@ -55,13 +62,6 @@ static bool __dredd_replace_expr_bool_false(bool arg, int local_mutation_id) { return arg; } -struct foo { - foo(int) {}; - operator int(); -}; - -enum baz { bar }; - int main() { if (!__dredd_enabled_mutation(3)) { __dredd_replace_expr_bool_false(0, 0) ? foo(__dredd_replace_expr_int_zero(0, 1)) : baz::bar; } } diff --git a/test/single_file/construct_struct_from_enum_constant.cc.noopt.expected b/test/single_file/construct_struct_from_enum_constant.cc.noopt.expected index f8834fd4..b390bea8 100644 --- a/test/single_file/construct_struct_from_enum_constant.cc.noopt.expected +++ b/test/single_file/construct_struct_from_enum_constant.cc.noopt.expected @@ -1,3 +1,10 @@ +struct foo { + foo(int) {}; + operator int(); +}; + +enum baz { bar }; + #include #include #include @@ -61,13 +68,6 @@ static bool __dredd_replace_expr_bool(bool arg, int local_mutation_id) { return arg; } -struct foo { - foo(int) {}; - operator int(); -}; - -enum baz { bar }; - int main() { if (!__dredd_enabled_mutation(15)) { __dredd_replace_expr_bool(__dredd_replace_expr_int(0, 0), 6) ? foo(__dredd_replace_expr_int(0, 9)) : baz::bar; } } diff --git a/test/single_file/define_at_start_of_file.c.expected b/test/single_file/define_at_start_of_file.c.expected index aa415de3..6ca5c388 100644 --- a/test/single_file/define_at_start_of_file.c.expected +++ b/test/single_file/define_at_start_of_file.c.expected @@ -1,3 +1,6 @@ +#define API +API int func1(); + #include #include #include @@ -48,7 +51,4 @@ static int __dredd_replace_expr_int_one(int arg, int local_mutation_id) { return arg; } -#define API -API int func1(); - int main() { int a = __dredd_replace_expr_int_one(1, 0); } diff --git a/test/single_file/define_at_start_of_file.c.noopt.expected b/test/single_file/define_at_start_of_file.c.noopt.expected index b47b64b8..69e3d2cd 100644 --- a/test/single_file/define_at_start_of_file.c.noopt.expected +++ b/test/single_file/define_at_start_of_file.c.noopt.expected @@ -1,3 +1,6 @@ +#define API +API int func1(); + #include #include #include @@ -51,7 +54,4 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#define API -API int func1(); - int main() { int a = __dredd_replace_expr_int(1, 0); } diff --git a/test/single_file/define_in_first_decl.c.expected b/test/single_file/define_in_first_decl.c.expected index 62165a5f..0f3b6528 100644 --- a/test/single_file/define_in_first_decl.c.expected +++ b/test/single_file/define_in_first_decl.c.expected @@ -1,3 +1,5 @@ +#define TYPE int + #include #include #include @@ -67,8 +69,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(int arg return arg1 + arg2; } -#define TYPE int - TYPE foo() { if (!__dredd_enabled_mutation(17)) { return __dredd_replace_expr_int_constant(__dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(__dredd_replace_expr_int_one(1, 0) , __dredd_replace_expr_int_constant(2, 3), 8), 12); } } diff --git a/test/single_file/define_in_first_decl.c.noopt.expected b/test/single_file/define_in_first_decl.c.noopt.expected index e87b6686..06d07f52 100644 --- a/test/single_file/define_in_first_decl.c.noopt.expected +++ b/test/single_file/define_in_first_decl.c.noopt.expected @@ -1,3 +1,5 @@ +#define TYPE int + #include #include #include @@ -62,8 +64,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -#define TYPE int - TYPE foo() { if (!__dredd_enabled_mutation(24)) { return __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); } } diff --git a/test/single_file/define_in_first_decl.cc.expected b/test/single_file/define_in_first_decl.cc.expected index ae5e1fba..fc982b8d 100644 --- a/test/single_file/define_in_first_decl.cc.expected +++ b/test/single_file/define_in_first_decl.cc.expected @@ -1,3 +1,5 @@ +#define TYPE int + #include #include #include @@ -69,8 +71,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(int arg return arg1 + arg2; } -#define TYPE int - TYPE foo() { if (!__dredd_enabled_mutation(17)) { return __dredd_replace_expr_int_constant(__dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(__dredd_replace_expr_int_one(1, 0) , __dredd_replace_expr_int_constant(2, 3), 8), 12); } } diff --git a/test/single_file/define_in_first_decl.cc.noopt.expected b/test/single_file/define_in_first_decl.cc.noopt.expected index 13600fc3..3122053e 100644 --- a/test/single_file/define_in_first_decl.cc.noopt.expected +++ b/test/single_file/define_in_first_decl.cc.noopt.expected @@ -1,3 +1,5 @@ +#define TYPE int + #include #include #include @@ -64,8 +66,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -#define TYPE int - TYPE foo() { if (!__dredd_enabled_mutation(24)) { return __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); } } diff --git a/test/single_file/enum.c.noopt.expected b/test/single_file/enum.c.noopt.expected index 1a0d6983..224d9cf2 100644 --- a/test/single_file/enum.c.noopt.expected +++ b/test/single_file/enum.c.noopt.expected @@ -1,3 +1,8 @@ +enum A { + X, + Y +}; + #include #include #include @@ -51,11 +56,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -enum A { - X, - Y -}; - void foo() { enum A myA = __dredd_replace_expr_int(X, 0); } diff --git a/test/single_file/expr_macro.c.expected b/test/single_file/expr_macro.c.expected index 5b9f9615..d9356d05 100644 --- a/test/single_file/expr_macro.c.expected +++ b/test/single_file/expr_macro.c.expected @@ -1,3 +1,7 @@ +#define E (1, 2, 3) + +void foo(int, int, int); + #include #include #include @@ -40,10 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); } -#define E (1, 2, 3) - -void foo(int, int, int); - int main() { if (!__dredd_enabled_mutation(0)) { foo E; } } diff --git a/test/single_file/expr_macro.c.noopt.expected b/test/single_file/expr_macro.c.noopt.expected index 5b9f9615..d9356d05 100644 --- a/test/single_file/expr_macro.c.noopt.expected +++ b/test/single_file/expr_macro.c.noopt.expected @@ -1,3 +1,7 @@ +#define E (1, 2, 3) + +void foo(int, int, int); + #include #include #include @@ -40,10 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); } -#define E (1, 2, 3) - -void foo(int, int, int); - int main() { if (!__dredd_enabled_mutation(0)) { foo E; } } diff --git a/test/single_file/expr_macro.cc.expected b/test/single_file/expr_macro.cc.expected index e7e0605e..4a8cd46f 100644 --- a/test/single_file/expr_macro.cc.expected +++ b/test/single_file/expr_macro.cc.expected @@ -1,3 +1,7 @@ +#define E (1, 2, 3) + +void foo(int, int, int); + #include #include #include @@ -42,10 +46,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#define E (1, 2, 3) - -void foo(int, int, int); - int main() { if (!__dredd_enabled_mutation(0)) { foo E; } } diff --git a/test/single_file/expr_macro.cc.noopt.expected b/test/single_file/expr_macro.cc.noopt.expected index e7e0605e..4a8cd46f 100644 --- a/test/single_file/expr_macro.cc.noopt.expected +++ b/test/single_file/expr_macro.cc.noopt.expected @@ -1,3 +1,7 @@ +#define E (1, 2, 3) + +void foo(int, int, int); + #include #include #include @@ -42,10 +46,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#define E (1, 2, 3) - -void foo(int, int, int); - int main() { if (!__dredd_enabled_mutation(0)) { foo E; } } diff --git a/test/single_file/initializer_list.cc.expected b/test/single_file/initializer_list.cc.expected index 4ac38bf1..7ac404e4 100644 --- a/test/single_file/initializer_list.cc.expected +++ b/test/single_file/initializer_list.cc.expected @@ -1,3 +1,12 @@ +#include + +struct A { + size_t x; + size_t y; +}; + +void foo(A arg); + #include #include #include @@ -49,15 +58,6 @@ static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { return arg; } -#include - -struct A { - size_t x; - size_t y; -}; - -void foo(A arg); - void bar() { if (!__dredd_enabled_mutation(4)) { foo({static_cast(__dredd_replace_expr_int_zero(0, 0)), static_cast(__dredd_replace_expr_int_zero(0, 2))}); } } diff --git a/test/single_file/initializer_list.cc.noopt.expected b/test/single_file/initializer_list.cc.noopt.expected index 9879e886..7227c4c1 100644 --- a/test/single_file/initializer_list.cc.noopt.expected +++ b/test/single_file/initializer_list.cc.noopt.expected @@ -1,3 +1,12 @@ +#include + +struct A { + size_t x; + size_t y; +}; + +void foo(A arg); + #include #include #include @@ -53,15 +62,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - -struct A { - size_t x; - size_t y; -}; - -void foo(A arg); - void bar() { if (!__dredd_enabled_mutation(12)) { foo({static_cast(__dredd_replace_expr_int(0, 0)), static_cast(__dredd_replace_expr_int(0, 6))}); } } diff --git a/test/single_file/initializer_list_long_to_short.cc.expected b/test/single_file/initializer_list_long_to_short.cc.expected index 6d947cb9..885e495f 100644 --- a/test/single_file/initializer_list_long_to_short.cc.expected +++ b/test/single_file/initializer_list_long_to_short.cc.expected @@ -1,3 +1,10 @@ +#include + +class foo { +public: + foo(std::initializer_list) {} +}; + #include #include #include @@ -52,13 +59,6 @@ static long __dredd_replace_expr_long_constant(long arg, int local_mutation_id) return arg; } -#include - -class foo { -public: - foo(std::initializer_list) {} -}; - int main() { if (!__dredd_enabled_mutation(5)) { foo{static_cast(__dredd_replace_expr_long_constant((long) 2, 0))}; } } diff --git a/test/single_file/initializer_list_long_to_short.cc.noopt.expected b/test/single_file/initializer_list_long_to_short.cc.noopt.expected index adad602d..98132b39 100644 --- a/test/single_file/initializer_list_long_to_short.cc.noopt.expected +++ b/test/single_file/initializer_list_long_to_short.cc.noopt.expected @@ -1,3 +1,10 @@ +#include + +class foo { +public: + foo(std::initializer_list) {} +}; + #include #include #include @@ -64,13 +71,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - -class foo { -public: - foo(std::initializer_list) {} -}; - int main() { if (!__dredd_enabled_mutation(18)) { foo{static_cast(__dredd_replace_expr_long((long) __dredd_replace_expr_long(__dredd_replace_expr_int(2, 0), 6), 12))}; } } diff --git a/test/single_file/initializer_list_narrower.cc.expected b/test/single_file/initializer_list_narrower.cc.expected index b889f5f0..8a3fd4f7 100644 --- a/test/single_file/initializer_list_narrower.cc.expected +++ b/test/single_file/initializer_list_narrower.cc.expected @@ -1,3 +1,10 @@ +#include + +class foo { +public: + foo(std::initializer_list) {} +}; + #include #include #include @@ -52,13 +59,6 @@ static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { return arg; } -#include - -class foo { -public: - foo(std::initializer_list) {} -}; - int main() { if (!__dredd_enabled_mutation(10)) { foo{static_cast(__dredd_replace_expr_int_constant(+__dredd_replace_expr_int_constant(2, 0), 5))}; } } diff --git a/test/single_file/initializer_list_narrower.cc.noopt.expected b/test/single_file/initializer_list_narrower.cc.noopt.expected index b6b41541..5287984a 100644 --- a/test/single_file/initializer_list_narrower.cc.noopt.expected +++ b/test/single_file/initializer_list_narrower.cc.noopt.expected @@ -1,3 +1,10 @@ +#include + +class foo { +public: + foo(std::initializer_list) {} +}; + #include #include #include @@ -53,13 +60,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - -class foo { -public: - foo(std::initializer_list) {} -}; - int main() { if (!__dredd_enabled_mutation(12)) { foo{static_cast(__dredd_replace_expr_int(+__dredd_replace_expr_int(2, 0), 6))}; } } diff --git a/test/single_file/misc004.cc b/test/single_file/misc004.cc new file mode 100644 index 00000000..ee3ad5ac --- /dev/null +++ b/test/single_file/misc004.cc @@ -0,0 +1,7 @@ +#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && defined(__CONFIG_H__) +# error test.h must be #included before system headers +#endif + +int main() { + int x = 1 + 2; +} diff --git a/test/single_file/misc004.cc.expected b/test/single_file/misc004.cc.expected new file mode 100644 index 00000000..55c380bd --- /dev/null +++ b/test/single_file/misc004.cc.expected @@ -0,0 +1,78 @@ +#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && defined(__CONFIG_H__) +# error test.h must be #included before system headers +#endif + +#include +#include +#include +#include + + +#ifdef _MSC_VER +#define thread_local __declspec(thread) +#elif __APPLE__ +#define thread_local __thread +#endif + +static thread_local bool __dredd_some_mutation_enabled = true; +static bool __dredd_enabled_mutation(int local_mutation_id) { + static thread_local bool initialized = false; + static thread_local uint64_t enabled_bitset[1]; + if (!initialized) { + bool some_mutation_enabled = false; + const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); + if (dredd_environment_variable != nullptr) { + std::string contents(dredd_environment_variable); + while (true) { + size_t pos = contents.find(","); + std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); + if (!token.empty()) { + int value = std::stoi(token); + int local_value = value - 0; + if (local_value >= 0 && local_value < 17) { + enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); + some_mutation_enabled = true; + } + } + if (pos == std::string::npos) { + break; + } + contents.erase(0, pos + 1); + } + } + initialized = true; + __dredd_some_mutation_enabled = some_mutation_enabled; + } + return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; +} + +static int __dredd_replace_expr_int_one(int arg, int local_mutation_id) { + if (!__dredd_some_mutation_enabled) return arg; + if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~(arg); + if (__dredd_enabled_mutation(local_mutation_id + 1)) return 0; + if (__dredd_enabled_mutation(local_mutation_id + 2)) return -1; + return arg; +} + +static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { + if (!__dredd_some_mutation_enabled) return arg; + if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~(arg); + if (__dredd_enabled_mutation(local_mutation_id + 1)) return -(arg); + if (__dredd_enabled_mutation(local_mutation_id + 2)) return 0; + if (__dredd_enabled_mutation(local_mutation_id + 3)) return 1; + if (__dredd_enabled_mutation(local_mutation_id + 4)) return -1; + return arg; +} + +static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(int arg1, int arg2, int local_mutation_id) { + if (!__dredd_some_mutation_enabled) return arg1 + arg2; + if (__dredd_enabled_mutation(local_mutation_id + 0)) return arg1 / arg2; + if (__dredd_enabled_mutation(local_mutation_id + 1)) return arg1 % arg2; + if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg1 - arg2; + if (__dredd_enabled_mutation(local_mutation_id + 3)) return arg2; + return arg1 + arg2; +} + +int main() { + int x = __dredd_replace_expr_int_constant(__dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_one(__dredd_replace_expr_int_one(1, 0) , __dredd_replace_expr_int_constant(2, 3), 8), 12); +} diff --git a/test/single_file/misc004.cc.noopt.expected b/test/single_file/misc004.cc.noopt.expected new file mode 100644 index 00000000..bc601fbd --- /dev/null +++ b/test/single_file/misc004.cc.noopt.expected @@ -0,0 +1,73 @@ +#if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && defined(__CONFIG_H__) +# error test.h must be #included before system headers +#endif + +#include +#include +#include +#include + + +#ifdef _MSC_VER +#define thread_local __declspec(thread) +#elif __APPLE__ +#define thread_local __thread +#endif + +static thread_local bool __dredd_some_mutation_enabled = true; +static bool __dredd_enabled_mutation(int local_mutation_id) { + static thread_local bool initialized = false; + static thread_local uint64_t enabled_bitset[1]; + if (!initialized) { + bool some_mutation_enabled = false; + const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); + if (dredd_environment_variable != nullptr) { + std::string contents(dredd_environment_variable); + while (true) { + size_t pos = contents.find(","); + std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); + if (!token.empty()) { + int value = std::stoi(token); + int local_value = value - 0; + if (local_value >= 0 && local_value < 24) { + enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); + some_mutation_enabled = true; + } + } + if (pos == std::string::npos) { + break; + } + contents.erase(0, pos + 1); + } + } + initialized = true; + __dredd_some_mutation_enabled = some_mutation_enabled; + } + return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; +} + +static int __dredd_replace_expr_int(int arg, int local_mutation_id) { + if (!__dredd_some_mutation_enabled) return arg; + if (__dredd_enabled_mutation(local_mutation_id + 0)) return !(arg); + if (__dredd_enabled_mutation(local_mutation_id + 1)) return ~(arg); + if (__dredd_enabled_mutation(local_mutation_id + 2)) return -(arg); + if (__dredd_enabled_mutation(local_mutation_id + 3)) return 0; + if (__dredd_enabled_mutation(local_mutation_id + 4)) return 1; + if (__dredd_enabled_mutation(local_mutation_id + 5)) return -1; + return arg; +} + +static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int arg2, int local_mutation_id) { + if (!__dredd_some_mutation_enabled) return arg1 + arg2; + if (__dredd_enabled_mutation(local_mutation_id + 0)) return arg1 / arg2; + if (__dredd_enabled_mutation(local_mutation_id + 1)) return arg1 * arg2; + if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg1 % arg2; + if (__dredd_enabled_mutation(local_mutation_id + 3)) return arg1 - arg2; + if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg1; + if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg2; + return arg1 + arg2; +} + +int main() { + int x = __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); +} diff --git a/test/single_file/new_expr_array_size.cc.expected b/test/single_file/new_expr_array_size.cc.expected index f3af4be2..cbd9e7af 100644 --- a/test/single_file/new_expr_array_size.cc.expected +++ b/test/single_file/new_expr_array_size.cc.expected @@ -1,3 +1,8 @@ +class foo { +public: + foo(int x) {} +}; + #include #include #include @@ -52,11 +57,6 @@ static int __dredd_replace_expr_int_constant(int arg, int local_mutation_id) { return arg; } -class foo { -public: - foo(int x) {} -}; - int main() { if (!__dredd_enabled_mutation(10)) { new foo[2]{__dredd_replace_expr_int_constant(4, 0), __dredd_replace_expr_int_constant(5, 5)}; } } diff --git a/test/single_file/new_expr_array_size.cc.noopt.expected b/test/single_file/new_expr_array_size.cc.noopt.expected index dbb038b1..f4ecebae 100644 --- a/test/single_file/new_expr_array_size.cc.noopt.expected +++ b/test/single_file/new_expr_array_size.cc.noopt.expected @@ -1,3 +1,8 @@ +class foo { +public: + foo(int x) {} +}; + #include #include #include @@ -53,11 +58,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -class foo { -public: - foo(int x) {} -}; - int main() { if (!__dredd_enabled_mutation(12)) { new foo[2]{__dredd_replace_expr_int(4, 0), __dredd_replace_expr_int(5, 6)}; } } diff --git a/test/single_file/printing.c.expected b/test/single_file/printing.c.expected index 2c7d4bd7..30620849 100644 --- a/test/single_file/printing.c.expected +++ b/test/single_file/printing.c.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -40,8 +42,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); } -#include - int main() { if (!__dredd_enabled_mutation(0)) { printf("%s\n", "A\n"); } if (!__dredd_enabled_mutation(1)) { printf("%s\n", "B\n"); } diff --git a/test/single_file/printing.c.noopt.expected b/test/single_file/printing.c.noopt.expected index bac6e784..d6028964 100644 --- a/test/single_file/printing.c.noopt.expected +++ b/test/single_file/printing.c.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -51,8 +53,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - int main() { if (!__dredd_enabled_mutation(6)) { __dredd_replace_expr_int(printf("%s\n", "A\n"), 0); } if (!__dredd_enabled_mutation(13)) { __dredd_replace_expr_int(printf("%s\n", "B\n"), 7); } diff --git a/test/single_file/printing.cc.expected b/test/single_file/printing.cc.expected index 92acec7c..a030f63d 100644 --- a/test/single_file/printing.cc.expected +++ b/test/single_file/printing.cc.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -42,8 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#include - int main() { if (!__dredd_enabled_mutation(0)) { std::cout << "A\n"; } if (!__dredd_enabled_mutation(1)) { std::cout << "B\n"; } diff --git a/test/single_file/printing.cc.noopt.expected b/test/single_file/printing.cc.noopt.expected index 92acec7c..a030f63d 100644 --- a/test/single_file/printing.cc.noopt.expected +++ b/test/single_file/printing.cc.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -42,8 +44,6 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; } -#include - int main() { if (!__dredd_enabled_mutation(0)) { std::cout << "A\n"; } if (!__dredd_enabled_mutation(1)) { std::cout << "B\n"; } diff --git a/test/single_file/sizeof_template2.cc.expected b/test/single_file/sizeof_template2.cc.expected index fa19d62e..3da4ae70 100644 --- a/test/single_file/sizeof_template2.cc.expected +++ b/test/single_file/sizeof_template2.cc.expected @@ -1,3 +1,5 @@ +bool f(int); + #include #include #include @@ -61,8 +63,6 @@ static bool __dredd_replace_expr_bool(std::function arg, int local_mutat return arg(); } -bool f(int); - template struct b { bool c() { if (!__dredd_enabled_mutation(9)) { return __dredd_replace_expr_bool([&]() -> bool { return static_cast(f(__dredd_replace_expr_int(sizeof(a), 0))); }, 6); } } }; diff --git a/test/single_file/sizeof_template2.cc.noopt.expected b/test/single_file/sizeof_template2.cc.noopt.expected index e194057e..8e99c8b6 100644 --- a/test/single_file/sizeof_template2.cc.noopt.expected +++ b/test/single_file/sizeof_template2.cc.noopt.expected @@ -1,3 +1,5 @@ +bool f(int); + #include #include #include @@ -70,8 +72,6 @@ static bool __dredd_replace_expr_bool(std::function arg, int local_mutat return arg(); } -bool f(int); - template struct b { bool c() { if (!__dredd_enabled_mutation(13)) { return __dredd_replace_expr_bool([&]() -> bool { return static_cast(f(__dredd_replace_expr_int(__dredd_replace_expr_unsigned_long(sizeof(a), 0), 4))); }, 10); } } }; diff --git a/test/single_file/space_needed_after_macro.c.expected b/test/single_file/space_needed_after_macro.c.expected index dcfc02eb..05c5072d 100644 --- a/test/single_file/space_needed_after_macro.c.expected +++ b/test/single_file/space_needed_after_macro.c.expected @@ -1,3 +1,5 @@ +#define BEGIN x = + #include #include #include @@ -51,8 +53,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#define BEGIN x = - int main() { int x, y; if (!__dredd_enabled_mutation(6)) { BEGIN __dredd_replace_expr_int((y), 0); } diff --git a/test/single_file/space_needed_after_macro.c.noopt.expected b/test/single_file/space_needed_after_macro.c.noopt.expected index c5117c01..80805613 100644 --- a/test/single_file/space_needed_after_macro.c.noopt.expected +++ b/test/single_file/space_needed_after_macro.c.noopt.expected @@ -1,3 +1,5 @@ +#define BEGIN x = + #include #include #include @@ -58,8 +60,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#define BEGIN x = - int main() { int x, y; if (!__dredd_enabled_mutation(14)) { __dredd_replace_expr_int(BEGIN __dredd_replace_expr_int( __dredd_replace_expr_int_lvalue(&((y)), 0), 2), 8); } diff --git a/test/single_file/space_needed_after_macro2.c.expected b/test/single_file/space_needed_after_macro2.c.expected index e5e30bf0..ad8d2ebc 100644 --- a/test/single_file/space_needed_after_macro2.c.expected +++ b/test/single_file/space_needed_after_macro2.c.expected @@ -1,3 +1,5 @@ +#define BEGIN_ x = + #include #include #include @@ -51,8 +53,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#define BEGIN_ x = - int main() { int x, y; if (!__dredd_enabled_mutation(6)) { BEGIN_ __dredd_replace_expr_int((y), 0); } diff --git a/test/single_file/space_needed_after_macro2.c.noopt.expected b/test/single_file/space_needed_after_macro2.c.noopt.expected index 74125f2a..5848bed4 100644 --- a/test/single_file/space_needed_after_macro2.c.noopt.expected +++ b/test/single_file/space_needed_after_macro2.c.noopt.expected @@ -1,3 +1,5 @@ +#define BEGIN_ x = + #include #include #include @@ -58,8 +60,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#define BEGIN_ x = - int main() { int x, y; if (!__dredd_enabled_mutation(14)) { __dredd_replace_expr_int(BEGIN_ __dredd_replace_expr_int( __dredd_replace_expr_int_lvalue(&((y)), 0), 2), 8); } diff --git a/test/single_file/switch_cases1.c.expected b/test/single_file/switch_cases1.c.expected index 8b648e16..055968e1 100644 --- a/test/single_file/switch_cases1.c.expected +++ b/test/single_file/switch_cases1.c.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -68,8 +70,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - int main() { int x = __dredd_replace_expr_int_constant(10, 0); if (!__dredd_enabled_mutation(16)) { switch (__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(&(x), 5), 7)) { diff --git a/test/single_file/switch_cases1.c.noopt.expected b/test/single_file/switch_cases1.c.noopt.expected index 2d2e302d..84e52c84 100644 --- a/test/single_file/switch_cases1.c.noopt.expected +++ b/test/single_file/switch_cases1.c.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -58,8 +60,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - int main() { int x = __dredd_replace_expr_int(10, 0); if (!__dredd_enabled_mutation(35)) { switch (__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(&(x), 6), 8)) { diff --git a/test/single_file/switch_cases2.c.expected b/test/single_file/switch_cases2.c.expected index 2af0ea6d..d5a08601 100644 --- a/test/single_file/switch_cases2.c.expected +++ b/test/single_file/switch_cases2.c.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -68,8 +70,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - int main() { int x = __dredd_replace_expr_int_constant(10, 0); if (!__dredd_enabled_mutation(16)) { switch (__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(&(x), 5), 7)) { diff --git a/test/single_file/switch_cases2.c.noopt.expected b/test/single_file/switch_cases2.c.noopt.expected index b461a13e..14f0be4c 100644 --- a/test/single_file/switch_cases2.c.noopt.expected +++ b/test/single_file/switch_cases2.c.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -58,8 +60,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - int main() { int x = __dredd_replace_expr_int(10, 0); if (!__dredd_enabled_mutation(35)) { switch (__dredd_replace_expr_int(__dredd_replace_expr_int_lvalue(&(x), 6), 8)) { diff --git a/test/single_file/typedef.c.noopt.expected b/test/single_file/typedef.c.noopt.expected index 92df5b23..1a054a9a 100644 --- a/test/single_file/typedef.c.noopt.expected +++ b/test/single_file/typedef.c.noopt.expected @@ -1,3 +1,7 @@ +typedef struct S { + int x; +} SomeS; + #include #include #include @@ -62,10 +66,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -typedef struct S { - int x; -} SomeS; - void foo() { if (!__dredd_enabled_mutation(24)) { __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); } } diff --git a/test/single_file/typedef.cc.noopt.expected b/test/single_file/typedef.cc.noopt.expected index 9b7ac517..6f5b2381 100644 --- a/test/single_file/typedef.cc.noopt.expected +++ b/test/single_file/typedef.cc.noopt.expected @@ -1,3 +1,7 @@ +typedef struct S { + int x; +} SomeS; + #include #include #include @@ -64,10 +68,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -typedef struct S { - int x; -} SomeS; - void foo() { if (!__dredd_enabled_mutation(24)) { __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); } } diff --git a/test/single_file/unary_logical_not.c.expected b/test/single_file/unary_logical_not.c.expected index 39208349..49e39509 100644 --- a/test/single_file/unary_logical_not.c.expected +++ b/test/single_file/unary_logical_not.c.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -72,8 +74,6 @@ static bool __dredd_replace_expr_bool(bool arg, int local_mutation_id) { return arg; } -#include - int main() { bool y = __dredd_replace_expr_bool_true(true, 0); if (!__dredd_enabled_mutation(12)) { return __dredd_replace_expr_int(__dredd_replace_unary_operator_LNot_bool(__dredd_replace_expr_bool(y, 1), 4), 6); } diff --git a/test/single_file/unary_logical_not.c.noopt.expected b/test/single_file/unary_logical_not.c.noopt.expected index 6c35a295..2e97e9a8 100644 --- a/test/single_file/unary_logical_not.c.noopt.expected +++ b/test/single_file/unary_logical_not.c.noopt.expected @@ -1,3 +1,5 @@ +#include + #include #include #include @@ -67,8 +69,6 @@ static bool __dredd_replace_expr_bool(bool arg, int local_mutation_id) { return arg; } -#include - int main() { bool y = __dredd_replace_expr_bool(__dredd_replace_expr_int(true, 0), 6); if (!__dredd_enabled_mutation(21)) { return __dredd_replace_expr_int(__dredd_replace_unary_operator_LNot_bool(__dredd_replace_expr_bool(y, 9), 12), 15); } diff --git a/test/single_file/user_defined_literals.cc.expected b/test/single_file/user_defined_literals.cc.expected index be6c6216..b45be2fe 100644 --- a/test/single_file/user_defined_literals.cc.expected +++ b/test/single_file/user_defined_literals.cc.expected @@ -1,3 +1,6 @@ +#include + +// Number wraps integer, enforcing explicit casting #include #include #include @@ -74,9 +77,6 @@ static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { return arg; } -#include - -// Number wraps integer, enforcing explicit casting struct Number { uint32_t value = {}; diff --git a/test/single_file/user_defined_literals.cc.noopt.expected b/test/single_file/user_defined_literals.cc.noopt.expected index 42755449..f6a9e269 100644 --- a/test/single_file/user_defined_literals.cc.noopt.expected +++ b/test/single_file/user_defined_literals.cc.noopt.expected @@ -1,3 +1,6 @@ +#include + +// Number wraps integer, enforcing explicit casting #include #include #include @@ -78,9 +81,6 @@ static int __dredd_replace_expr_int(int arg, int local_mutation_id) { return arg; } -#include - -// Number wraps integer, enforcing explicit casting struct Number { uint32_t value = {}; diff --git a/test/single_file/using.cc.noopt.expected b/test/single_file/using.cc.noopt.expected index 5eb65996..c46f76c7 100644 --- a/test/single_file/using.cc.noopt.expected +++ b/test/single_file/using.cc.noopt.expected @@ -1,3 +1,5 @@ +using blah = int; + #include #include #include @@ -64,8 +66,6 @@ static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(int arg1, int a return arg1 + arg2; } -using blah = int; - void foo() { if (!__dredd_enabled_mutation(24)) { __dredd_replace_expr_int(__dredd_replace_binary_operator_Add_arg1_int_arg2_int(__dredd_replace_expr_int(1, 0) , __dredd_replace_expr_int(2, 6), 12), 18); } }