diff --git a/src/libdredd/include/libdredd/mutation.h b/src/libdredd/include/libdredd/mutation.h index 56c93438..ac8fee9a 100644 --- a/src/libdredd/include/libdredd/mutation.h +++ b/src/libdredd/include/libdredd/mutation.h @@ -53,7 +53,8 @@ class Mutation { bool optimise_mutations, bool only_track_mutant_coverage, int first_mutation_id_in_file, int& mutation_id, clang::Rewriter& rewriter, - std::unordered_set& dredd_declarations) const = 0; + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const = 0; }; } // namespace dredd diff --git a/src/libdredd/include/libdredd/mutation_remove_stmt.h b/src/libdredd/include/libdredd/mutation_remove_stmt.h index b0f0f8ad..db915e14 100644 --- a/src/libdredd/include/libdredd/mutation_remove_stmt.h +++ b/src/libdredd/include/libdredd/mutation_remove_stmt.h @@ -40,7 +40,8 @@ class MutationRemoveStmt : public Mutation { bool optimise_mutations, bool only_track_mutant_coverage, int first_mutation_id_in_file, int& mutation_id, clang::Rewriter& rewriter, - std::unordered_set& dredd_declarations) const override; + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const override; private: // Helper method to determine whether the token immediately following the diff --git a/src/libdredd/include/libdredd/mutation_replace_binary_operator.h b/src/libdredd/include/libdredd/mutation_replace_binary_operator.h index e07b0734..c5f25c9a 100644 --- a/src/libdredd/include/libdredd/mutation_replace_binary_operator.h +++ b/src/libdredd/include/libdredd/mutation_replace_binary_operator.h @@ -42,14 +42,17 @@ class MutationReplaceBinaryOperator : public Mutation { bool optimise_mutations, bool only_track_mutant_coverage, int first_mutation_id_in_file, int& mutation_id, clang::Rewriter& rewriter, - std::unordered_set& dredd_declarations) const override; + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const override; private: std::string GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& lhs_type, - const std::string& rhs_type, bool optimise_mutations, - bool only_track_mutant_coverage, int& mutation_id, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& lhs_type, const std::string& rhs_type, + bool optimise_mutations, bool only_track_mutant_coverage, + int& mutation_id, protobufs::MutationReplaceBinaryOperator& protobuf_message) const; void ReplaceOperator(const std::string& lhs_type, const std::string& rhs_type, @@ -62,6 +65,12 @@ class MutationReplaceBinaryOperator : public Mutation { std::string GetFunctionName(bool optimise_mutations, clang::ASTContext& ast_context) const; + static std::string OpKindToString(clang::BinaryOperatorKind kind); + + [[nodiscard]] std::string GetBinaryMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const; + [[nodiscard]] bool IsRedundantReplacementOperator( clang::BinaryOperatorKind operator_kind, const clang::ASTContext& ast_context) const; @@ -79,7 +88,8 @@ class MutationReplaceBinaryOperator : public Mutation { // Replaces binary expressions with either the left or right operand. void GenerateArgumentReplacement( const std::string& arg1_evaluated, const std::string& arg2_evaluated, - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceBinaryOperator& protobuf_message) const; @@ -87,7 +97,8 @@ class MutationReplaceBinaryOperator : public Mutation { // Replaces binary operators with other valid binary operators. void GenerateBinaryOperatorReplacement( const std::string& arg1_evaluated, const std::string& arg2_evaluated, - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceBinaryOperator& protobuf_message) const; diff --git a/src/libdredd/include/libdredd/mutation_replace_expr.h b/src/libdredd/include/libdredd/mutation_replace_expr.h index fee39226..50d69d44 100644 --- a/src/libdredd/include/libdredd/mutation_replace_expr.h +++ b/src/libdredd/include/libdredd/mutation_replace_expr.h @@ -41,7 +41,12 @@ class MutationReplaceExpr : public Mutation { bool optimise_mutations, bool only_track_mutant_coverage, int first_mutation_id_in_file, int& mutation_id, clang::Rewriter& rewriter, - std::unordered_set& dredd_declarations) const override; + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const override; + + [[nodiscard]] std::string GetExprMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const; static void ApplyCppTypeModifiers(const clang::Expr& expr, std::string& type); @@ -94,25 +99,29 @@ class MutationReplaceExpr : public Mutation { // Replace expressions with constants. void GenerateConstantReplacement( - clang::ASTContext& ast_context, bool optimise_mutations, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; void GenerateBooleanConstantReplacement( - clang::ASTContext& ast_context, bool optimise_mutations, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; void GenerateIntegerConstantReplacement( - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; void GenerateFloatConstantReplacement( - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; @@ -120,29 +129,32 @@ class MutationReplaceExpr : public Mutation { // Insert valid unary operators such as !, ~, ++ and --. void GenerateUnaryOperatorInsertion( const std::string& arg_evaluated, clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; void GenerateUnaryOperatorInsertionBeforeNonLValue( const std::string& arg_evaluated, clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; void GenerateUnaryOperatorInsertionBeforeLValue( const std::string& arg_evaluated, clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const; std::string GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& input_type, - bool optimise_mutations, bool only_track_mutant_coverage, - int& mutation_id, protobufs::MutationReplaceExpr& protobuf_message) const; + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& input_type, bool optimise_mutations, + bool only_track_mutant_coverage, int& mutation_id, + protobufs::MutationReplaceExpr& protobuf_message) const; [[nodiscard]] std::string GetFunctionName( bool optimise_mutations, clang::ASTContext& ast_context) const; diff --git a/src/libdredd/include/libdredd/mutation_replace_unary_operator.h b/src/libdredd/include/libdredd/mutation_replace_unary_operator.h index 24c6f621..c2d11dbb 100644 --- a/src/libdredd/include/libdredd/mutation_replace_unary_operator.h +++ b/src/libdredd/include/libdredd/mutation_replace_unary_operator.h @@ -41,14 +41,16 @@ class MutationReplaceUnaryOperator : public Mutation { bool optimise_mutations, bool only_track_mutant_coverage, int first_mutation_id_in_file, int& mutation_id, clang::Rewriter& rewriter, - std::unordered_set& dredd_declarations) const override; + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const override; private: std::string GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& input_type, - bool optimise_mutations, bool only_track_mutant_coverage, - int& mutation_id, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& input_type, bool optimise_mutations, + bool only_track_mutant_coverage, int& mutation_id, protobufs::MutationReplaceUnaryOperator& protobuf_message) const; [[nodiscard]] static bool IsPrefix(clang::UnaryOperatorKind operator_kind); @@ -65,12 +67,18 @@ class MutationReplaceUnaryOperator : public Mutation { std::string GetFunctionName(bool optimise_mutations, clang::ASTContext& ast_context) const; + static std::string OpKindToString(clang::UnaryOperatorKind kind); + + [[nodiscard]] std::string GetUnaryMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const; + // Replaces unary operators with other valid unary operators. void GenerateUnaryOperatorReplacement( const std::string& arg_evaluated, const clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceUnaryOperator& protobuf_message) const; static void AddMutationInstance( diff --git a/src/libdredd/include/libdredd/util.h b/src/libdredd/include/libdredd/util.h index da47090a..965b3f55 100644 --- a/src/libdredd/include/libdredd/util.h +++ b/src/libdredd/include/libdredd/util.h @@ -128,6 +128,12 @@ bool EvaluateAsFloat(const clang::Expr& expr, bool IsCxx11ConstantExpr(const clang::Expr& expr, const clang::ASTContext& ast_context); +std::string GenerateMutationPrelude(); + +std::string GenerateMutationMacro(const std::string& name, + const std::string& args_evaluated); + +std::string GenerateMutationReturn(); } // namespace dredd #endif // LIBDREDD_UTIL_H diff --git a/src/libdredd/include_private/include/libdredd/mutate_ast_consumer.h b/src/libdredd/include_private/include/libdredd/mutate_ast_consumer.h index 6cefda09..ff0ee38c 100644 --- a/src/libdredd/include_private/include/libdredd/mutate_ast_consumer.h +++ b/src/libdredd/include_private/include/libdredd/mutate_ast_consumer.h @@ -66,7 +66,8 @@ class MutateAstConsumer : public clang::ASTConsumer { protobufs::MutationTreeNode ApplyMutations( const MutationTreeNode& mutation_tree_node, int initial_mutation_id, clang::ASTContext& context, - std::unordered_set& dredd_declarations); + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros); const clang::CompilerInstance* compiler_instance_; diff --git a/src/libdredd/src/mutate_ast_consumer.cc b/src/libdredd/src/mutate_ast_consumer.cc index 99b5dd85..147e025c 100644 --- a/src/libdredd/src/mutate_ast_consumer.cc +++ b/src/libdredd/src/mutate_ast_consumer.cc @@ -31,6 +31,7 @@ #include "clang/Frontend/CompilerInstance.h" #include "clang/Rewrite/Core/Rewriter.h" #include "libdredd/mutation.h" +#include "libdredd/util.h" #include "llvm/ADT/StringRef.h" #include "llvm/Support/raw_ostream.h" @@ -74,6 +75,7 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { // converted to an ordered set so that declarations can be added to the source // file in a deterministic order. std::unordered_set dredd_declarations; + std::unordered_set dredd_macros; protobufs::MutationInfoForFile mutation_info_for_file; mutation_info_for_file.set_filename( @@ -83,7 +85,7 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { .str()); *mutation_info_for_file.mutable_mutation_tree_root() = ApplyMutations(visitor_->GetMutations(), initial_mutation_id, ast_context, - dredd_declarations); + dredd_declarations, dredd_macros); if (initial_mutation_id == *mutation_id_) { // No possibilities for mutation were found; nothing else to do. @@ -111,6 +113,19 @@ void MutateAstConsumer::HandleTranslationUnit(clang::ASTContext& ast_context) { assert(!rewriter_result && "Rewrite failed.\n"); } + rewriter_.InsertTextBefore(start_of_source_file, GenerateMutationPrelude()); + + std::set sorted_dredd_macros; + sorted_dredd_macros.insert(dredd_macros.begin(), dredd_macros.end()); + for (const auto& macro : sorted_dredd_macros) { + const bool rewriter_result = + rewriter_.InsertTextBefore(start_of_source_file, macro); + (void)rewriter_result; // Keep release-mode compilers happy. + assert(!rewriter_result && "Rewrite failed.\n"); + } + + rewriter_.InsertTextBefore(start_of_source_file, GenerateMutationReturn()); + const std::string dredd_prelude = compiler_instance_->getLangOpts().CPlusPlus ? GetDreddPreludeCpp(initial_mutation_id) @@ -361,7 +376,8 @@ std::string MutateAstConsumer::GetDreddPreludeC(int initial_mutation_id) const { protobufs::MutationTreeNode MutateAstConsumer::ApplyMutations( const MutationTreeNode& mutation_tree_node, int initial_mutation_id, clang::ASTContext& context, - std::unordered_set& dredd_declarations) { + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) { assert(!(mutation_tree_node.IsEmpty() && mutation_tree_node.GetChildren().size() == 1) && "The mutation tree should already be compressed."); @@ -369,15 +385,15 @@ protobufs::MutationTreeNode MutateAstConsumer::ApplyMutations( for (const auto& child : mutation_tree_node.GetChildren()) { assert(!child->IsEmpty() && "The mutation tree should not have empty subtrees."); - *result.add_children() = ApplyMutations(*child, initial_mutation_id, - context, dredd_declarations); + *result.add_children() = ApplyMutations( + *child, initial_mutation_id, context, dredd_declarations, dredd_macros); } for (const auto& mutation : mutation_tree_node.GetMutations()) { const int mutation_id_old = *mutation_id_; const auto mutation_group = mutation->Apply( context, compiler_instance_->getPreprocessor(), optimise_mutations_, only_track_mutant_coverage_, initial_mutation_id, *mutation_id_, - rewriter_, dredd_declarations); + rewriter_, dredd_declarations, dredd_macros); if (*mutation_id_ > mutation_id_old) { // Only add the result of applying the mutation if it had an effect. *result.add_mutation_groups() = mutation_group; diff --git a/src/libdredd/src/mutation_remove_stmt.cc b/src/libdredd/src/mutation_remove_stmt.cc index 344f990b..d5bc0e47 100644 --- a/src/libdredd/src/mutation_remove_stmt.cc +++ b/src/libdredd/src/mutation_remove_stmt.cc @@ -42,8 +42,10 @@ protobufs::MutationGroup MutationRemoveStmt::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& dredd_declarations) const { + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const { (void)dredd_declarations; // Unused. + (void)dredd_macros; // Unused. (void)optimise_mutations; // Unused. // The protobuf object for the mutation, which will be wrapped in a diff --git a/src/libdredd/src/mutation_replace_binary_operator.cc b/src/libdredd/src/mutation_replace_binary_operator.cc index eac4bfac..20b687dd 100644 --- a/src/libdredd/src/mutation_replace_binary_operator.cc +++ b/src/libdredd/src/mutation_replace_binary_operator.cc @@ -84,104 +84,81 @@ bool MutationReplaceBinaryOperator::IsValidReplacementOperator( operator_kind == clang::BO_XorAssign)); } -std::string MutationReplaceBinaryOperator::GetFunctionName( - bool optimise_mutations, clang::ASTContext& ast_context) const { - std::string result = "__dredd_replace_binary_operator_"; - - // A string corresponding to the binary operator forms part of the name of the - // mutation function, to differentiate mutation functions for different - // operators - switch (binary_operator_->getOpcode()) { +std::string MutationReplaceBinaryOperator::OpKindToString( + clang::BinaryOperatorKind kind) { + switch (kind) { case clang::BinaryOperatorKind::BO_Add: - result += "Add"; - break; + return "Add"; case clang::BinaryOperatorKind::BO_Div: - result += "Div"; - break; + return "Div"; case clang::BinaryOperatorKind::BO_Mul: - result += "Mul"; - break; + return "Mul"; case clang::BinaryOperatorKind::BO_Rem: - result += "Rem"; - break; + return "Rem"; case clang::BinaryOperatorKind::BO_Sub: - result += "Sub"; - break; + return "Sub"; case clang::BinaryOperatorKind::BO_AddAssign: - result += "AddAssign"; - break; + return "AddAssign"; case clang::BinaryOperatorKind::BO_AndAssign: - result += "AndAssign"; - break; + return "AndAssign"; case clang::BinaryOperatorKind::BO_Assign: - result += "Assign"; - break; + return "Assign"; case clang::BinaryOperatorKind::BO_DivAssign: - result += "DivAssign"; - break; + return "DivAssign"; case clang::BinaryOperatorKind::BO_MulAssign: - result += "MulAssign"; - break; + return "MulAssign"; case clang::BinaryOperatorKind::BO_OrAssign: - result += "OrAssign"; - break; + return "OrAssign"; case clang::BinaryOperatorKind::BO_RemAssign: - result += "RemAssign"; - break; + return "RemAssign"; case clang::BinaryOperatorKind::BO_ShlAssign: - result += "ShlAssign"; - break; + return "ShlAssign"; case clang::BinaryOperatorKind::BO_ShrAssign: - result += "ShrAssign"; - break; + return "ShrAssign"; case clang::BinaryOperatorKind::BO_SubAssign: - result += "SubAssign"; - break; + return "SubAssign"; case clang::BinaryOperatorKind::BO_XorAssign: - result += "XorAssign"; - break; + return "XorAssign"; case clang::BinaryOperatorKind::BO_And: - result += "And"; - break; + return "And"; case clang::BinaryOperatorKind::BO_Or: - result += "Or"; - break; + return "Or"; case clang::BinaryOperatorKind::BO_Xor: - result += "Xor"; - break; + return "Xor"; case clang::BinaryOperatorKind::BO_LAnd: - result += "LAnd"; - break; + return "LAnd"; case clang::BinaryOperatorKind::BO_LOr: - result += "LOr"; - break; + return "LOr"; case clang::BinaryOperatorKind::BO_EQ: - result += "EQ"; - break; + return "EQ"; case clang::BinaryOperatorKind::BO_GE: - result += "GE"; - break; + return "GE"; case clang::BinaryOperatorKind::BO_GT: - result += "GT"; - break; + return "GT"; case clang::BinaryOperatorKind::BO_LE: - result += "LE"; - break; + return "LE"; case clang::BinaryOperatorKind::BO_LT: - result += "LT"; - break; + return "LT"; case clang::BinaryOperatorKind::BO_NE: - result += "NE"; - break; + return "NE"; case clang::BinaryOperatorKind::BO_Shl: - result += "Shl"; - break; + return "Shl"; case clang::BinaryOperatorKind::BO_Shr: - result += "Shr"; - break; + return "Shr"; default: assert(false && "Unsupported opcode"); + return ""; } +} + +std::string MutationReplaceBinaryOperator::GetFunctionName( + bool optimise_mutations, clang::ASTContext& ast_context) const { + std::string result = "__dredd_replace_binary_operator_"; + + // A string corresponding to the binary operator forms part of the name of the + // mutation function, to differentiate mutation functions for different + // operators + result += OpKindToString(binary_operator_->getOpcode()); std::string lhs_qualifier; @@ -254,9 +231,30 @@ std::string MutationReplaceBinaryOperator::GetFunctionName( return result; } +std::string MutationReplaceBinaryOperator::GetBinaryMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const { + std::string result = "REPLACE_BINARY_" + operator_name; + if (ast_context.getLangOpts().CPlusPlus && + binary_operator_->getLHS()->HasSideEffects(ast_context)) { + result += "_LHS_EVALUATED"; + } + if (ast_context.getLangOpts().CPlusPlus && + (binary_operator_->isLogicalOp() || + binary_operator_->getRHS()->HasSideEffects(ast_context))) { + result += "_RHS_EVALUATED"; + } + if (!ast_context.getLangOpts().CPlusPlus && + binary_operator_->isAssignmentOp()) { + result += "_LHS_POINTER"; + } + return result; +} + void MutationReplaceBinaryOperator::GenerateArgumentReplacement( const std::string& arg1_evaluated, const std::string& arg2_evaluated, - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceBinaryOperator& protobuf_message) const { @@ -302,9 +300,16 @@ void MutationReplaceBinaryOperator::GenerateArgumentReplacement( MutationReplaceExpr::ExprIsEquivalentToFloat( *binary_operator_->getLHS(), -1.0, ast_context))) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return " << arg1_evaluated - << ";\n"; + std::string macro_name = "REPLACE_BINARY_ARG1"; + if (ast_context.getLangOpts().CPlusPlus && + binary_operator_->getLHS()->HasSideEffects(ast_context)) { + macro_name += "_EVALUATED"; + } else if (!ast_context.getLangOpts().CPlusPlus && + binary_operator_->isAssignmentOp()) { + macro_name += "_POINTER"; + } + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, arg1_evaluated)); } AddMutationInstance( mutation_id_base, @@ -329,9 +334,14 @@ void MutationReplaceBinaryOperator::GenerateArgumentReplacement( MutationReplaceExpr::ExprIsEquivalentToFloat( *binary_operator_->getRHS(), -1.0, ast_context))) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return " << arg2_evaluated - << ";\n"; + std::string macro_name = "REPLACE_BINARY_ARG2"; + if (ast_context.getLangOpts().CPlusPlus && + (binary_operator_->isLogicalOp() || + binary_operator_->getRHS()->HasSideEffects(ast_context))) { + macro_name += "_EVALUATED"; + } + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, arg2_evaluated)); } AddMutationInstance( mutation_id_base, @@ -342,18 +352,22 @@ void MutationReplaceBinaryOperator::GenerateArgumentReplacement( void MutationReplaceBinaryOperator::GenerateBinaryOperatorReplacement( const std::string& arg1_evaluated, const std::string& arg2_evaluated, - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceBinaryOperator& protobuf_message) const { for (auto operator_kind : GetReplacementOperators(optimise_mutations, ast_context)) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return " << arg1_evaluated - << " " - << clang::BinaryOperator::getOpcodeStr(operator_kind).str() - << " " << arg2_evaluated << ";\n"; + const std::string macro_name = + GetBinaryMacroName(OpKindToString(operator_kind), ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert(GenerateMutationMacro( + macro_name, + arg1_evaluated + " " + + clang::BinaryOperator::getOpcodeStr(operator_kind).str() + " " + + arg2_evaluated)); } AddMutationInstance(mutation_id_base, OperatorKindToAction(operator_kind), mutation_id_offset, protobuf_message); @@ -435,10 +449,11 @@ MutationReplaceBinaryOperator::GetReplacementOperators( } std::string MutationReplaceBinaryOperator::GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& lhs_type, - const std::string& rhs_type, bool optimise_mutations, - bool only_track_mutant_coverage, int& mutation_id, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& lhs_type, const std::string& rhs_type, + bool optimise_mutations, bool only_track_mutant_coverage, int& mutation_id, protobufs::MutationReplaceBinaryOperator& protobuf_message) const { std::stringstream new_function; new_function << "static " << result_type << " " << function_name << "("; @@ -483,32 +498,32 @@ std::string MutationReplaceBinaryOperator::GenerateMutatorFunction( if (!only_track_mutant_coverage) { // Quickly apply the original operator if no mutant is enabled (which will // be the common case). - new_function << " if (!__dredd_some_mutation_enabled) return " - << arg1_evaluated << " " + new_function << " MUTATION_PRELUDE(" << arg1_evaluated << " " << clang::BinaryOperator::getOpcodeStr( binary_operator_->getOpcode()) .str() - << " " << arg2_evaluated << ";\n"; + << " " << arg2_evaluated << ");\n"; } GenerateBinaryOperatorReplacement( - arg1_evaluated, arg2_evaluated, ast_context, optimise_mutations, - only_track_mutant_coverage, mutation_id, new_function, mutation_id_offset, - protobuf_message); - GenerateArgumentReplacement(arg1_evaluated, arg2_evaluated, ast_context, - optimise_mutations, only_track_mutant_coverage, - mutation_id, new_function, mutation_id_offset, - protobuf_message); + arg1_evaluated, arg2_evaluated, ast_context, dredd_macros, + optimise_mutations, only_track_mutant_coverage, mutation_id, new_function, + mutation_id_offset, protobuf_message); + GenerateArgumentReplacement( + arg1_evaluated, arg2_evaluated, ast_context, dredd_macros, + optimise_mutations, only_track_mutant_coverage, mutation_id, new_function, + mutation_id_offset, protobuf_message); if (only_track_mutant_coverage) { new_function << " __dredd_record_covered_mutants(local_mutation_id, " + std::to_string(mutation_id_offset) + ");\n"; } - new_function << " return " << arg1_evaluated << " " + // TODO(JamesLee-Jones): Replace with return macro. + new_function << " return MUTATION_RETURN(" << arg1_evaluated << " " << clang::BinaryOperator::getOpcodeStr( binary_operator_->getOpcode()) .str() - << " " << arg2_evaluated << ";\n"; + << " " << arg2_evaluated << ");\n"; new_function << "}\n\n"; @@ -523,7 +538,8 @@ protobufs::MutationGroup MutationReplaceBinaryOperator::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& dredd_declarations) const { + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const { // The protobuf object for the mutation, which will be wrapped in a // MutationGroup. protobufs::MutationReplaceBinaryOperator inner_result; @@ -609,8 +625,8 @@ protobufs::MutationGroup MutationReplaceBinaryOperator::Apply( rewriter); const std::string new_function = GenerateMutatorFunction( - ast_context, new_function_name, result_type, lhs_type, rhs_type, - optimise_mutations, only_track_mutant_coverage, mutation_id, + ast_context, dredd_macros, new_function_name, result_type, lhs_type, + rhs_type, optimise_mutations, only_track_mutant_coverage, mutation_id, inner_result); assert(!new_function.empty() && "Unsupported opcode."); diff --git a/src/libdredd/src/mutation_replace_expr.cc b/src/libdredd/src/mutation_replace_expr.cc index 79f358e2..9f235241 100644 --- a/src/libdredd/src/mutation_replace_expr.cc +++ b/src/libdredd/src/mutation_replace_expr.cc @@ -41,7 +41,6 @@ dredd::MutationReplaceExpr::MutationReplaceExpr( : expr_(&expr), info_for_source_range_(GetSourceRangeInMainFile(preprocessor, expr), ast_context) {} - std::string MutationReplaceExpr::GetFunctionName( bool optimise_mutations, clang::ASTContext& ast_context) const { std::string result = "__dredd_replace_expr_"; @@ -116,6 +115,19 @@ void MutationReplaceExpr::AddOptimisationSpecifier( } } +std::string MutationReplaceExpr::GetExprMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const { + std::string result = "REPLACE_EXPR_" + operator_name; + if (ast_context.getLangOpts().CPlusPlus && + expr_->HasSideEffects(ast_context)) { + result += "_EVALUATED"; + } else if (!ast_context.getLangOpts().CPlusPlus && expr_->isLValue()) { + result += "_POINTER"; + } + return result; +} + bool MutationReplaceExpr::ExprIsEquivalentToInt( const clang::Expr& expr, int constant, const clang::ASTContext& ast_context) { @@ -179,6 +191,7 @@ bool MutationReplaceExpr::IsRedundantOperatorInsertion( void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeLValue( const std::string& arg_evaluated, clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { @@ -186,18 +199,20 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeLValue( return; } if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return ++(" << arg_evaluated - << ");\n"; + const std::string macro_name = GetExprMacroName("INC", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert( + GenerateMutationMacro(macro_name, "++(" + arg_evaluated + ")")); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::InsertPreInc, mutation_id_offset, protobuf_message); if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return --(" << arg_evaluated - << ");\n"; + const std::string macro_name = GetExprMacroName("DEC", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert( + GenerateMutationMacro(macro_name, "--(" + arg_evaluated + ")")); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::InsertPreDec, @@ -206,9 +221,9 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeLValue( void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeNonLValue( const std::string& arg_evaluated, clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { if (expr_->isLValue()) { return; @@ -220,9 +235,11 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeNonLValue( if (!optimise_mutations || !IsRedundantOperatorInsertion(ast_context, clang::UO_LNot)) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return !(" << arg_evaluated + const std::string macro_name = GetExprMacroName("LNOT", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert( + GenerateMutationMacro(macro_name, "!(" + arg_evaluated + ")")); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::InsertLNot, @@ -235,9 +252,11 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeNonLValue( if (!optimise_mutations || !IsRedundantOperatorInsertion(ast_context, clang::UO_Not)) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return ~(" << arg_evaluated + const std::string macro_name = GetExprMacroName("NOT", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert( + GenerateMutationMacro(macro_name, "~(" + arg_evaluated + ")")); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::InsertNot, @@ -250,9 +269,11 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeNonLValue( if (!optimise_mutations || !IsRedundantOperatorInsertion(ast_context, clang::UO_Minus)) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return -(" << arg_evaluated + const std::string macro_name = GetExprMacroName("MINUS", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert( + GenerateMutationMacro(macro_name, "-(" + arg_evaluated + ")")); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::InsertMinus, @@ -263,39 +284,44 @@ void MutationReplaceExpr::GenerateUnaryOperatorInsertionBeforeNonLValue( void MutationReplaceExpr::GenerateUnaryOperatorInsertion( const std::string& arg_evaluated, clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { GenerateUnaryOperatorInsertionBeforeLValue( - arg_evaluated, ast_context, only_track_mutant_coverage, mutation_id_base, - new_function, mutation_id_offset, protobuf_message); + arg_evaluated, ast_context, dredd_macros, only_track_mutant_coverage, + mutation_id_base, new_function, mutation_id_offset, protobuf_message); GenerateUnaryOperatorInsertionBeforeNonLValue( - arg_evaluated, ast_context, optimise_mutations, + arg_evaluated, ast_context, dredd_macros, optimise_mutations, only_track_mutant_coverage, mutation_id_base, new_function, mutation_id_offset, protobuf_message); } void MutationReplaceExpr::GenerateConstantReplacement( - clang::ASTContext& ast_context, bool optimise_mutations, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { if (!expr_->isLValue()) { GenerateBooleanConstantReplacement( - ast_context, optimise_mutations, only_track_mutant_coverage, - mutation_id_base, new_function, mutation_id_offset, protobuf_message); + ast_context, dredd_macros, optimise_mutations, + only_track_mutant_coverage, mutation_id_base, new_function, + mutation_id_offset, protobuf_message); GenerateIntegerConstantReplacement( - ast_context, optimise_mutations, only_track_mutant_coverage, - mutation_id_base, new_function, mutation_id_offset, protobuf_message); + ast_context, dredd_macros, optimise_mutations, + only_track_mutant_coverage, mutation_id_base, new_function, + mutation_id_offset, protobuf_message); GenerateFloatConstantReplacement( - ast_context, optimise_mutations, only_track_mutant_coverage, - mutation_id_base, new_function, mutation_id_offset, protobuf_message); + ast_context, dredd_macros, optimise_mutations, + only_track_mutant_coverage, mutation_id_base, new_function, + mutation_id_offset, protobuf_message); } } void MutationReplaceExpr::GenerateFloatConstantReplacement( - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { @@ -306,8 +332,10 @@ void MutationReplaceExpr::GenerateFloatConstantReplacement( !ExprIsEquivalentToFloat(*expr_, 0.0, ast_context)) { // Replace floating point expression with 0.0 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return 0.0;\n"; + const std::string macro_name = "REPLACE_EXPR_FLOAT_ZERO"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "0.0")); } AddMutationInstance( mutation_id_base, @@ -319,8 +347,10 @@ void MutationReplaceExpr::GenerateFloatConstantReplacement( !ExprIsEquivalentToFloat(*expr_, 1.0, ast_context)) { // Replace floating point expression with 1.0 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return 1.0;\n"; + const std::string macro_name = "REPLACE_EXPR_FLOAT_ONE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "1.0")); } AddMutationInstance( mutation_id_base, @@ -332,8 +362,10 @@ void MutationReplaceExpr::GenerateFloatConstantReplacement( !ExprIsEquivalentToFloat(*expr_, -1.0, ast_context)) { // Replace floating point expression with -1.0 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return -1.0;\n"; + const std::string macro_name = "REPLACE_EXPR_FLOAT_MINUS_ONE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "-1.0")); } AddMutationInstance( mutation_id_base, @@ -343,7 +375,8 @@ void MutationReplaceExpr::GenerateFloatConstantReplacement( } } void MutationReplaceExpr::GenerateIntegerConstantReplacement( - const clang::ASTContext& ast_context, bool optimise_mutations, + const clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { @@ -353,8 +386,10 @@ void MutationReplaceExpr::GenerateIntegerConstantReplacement( if (!optimise_mutations || !ExprIsEquivalentToInt(*expr_, 0, ast_context)) { // Replace expression with 0 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return 0;\n"; + const std::string macro_name = "REPLACE_EXPR_INT_ZERO"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "0")); } AddMutationInstance( mutation_id_base, @@ -365,8 +400,10 @@ void MutationReplaceExpr::GenerateIntegerConstantReplacement( if (!optimise_mutations || !ExprIsEquivalentToInt(*expr_, 1, ast_context)) { // Replace expression with 1 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return 1;\n"; + const std::string macro_name = "REPLACE_EXPR_INT_ONE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "1")); } AddMutationInstance( mutation_id_base, @@ -380,8 +417,10 @@ void MutationReplaceExpr::GenerateIntegerConstantReplacement( !ExprIsEquivalentToInt(*expr_, -1, ast_context)) { // Replace signed integer expression with -1 if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return -1;\n"; + const std::string macro_name = "REPLACE_EXPR_INT_MINUS_ONE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, "-1")); } AddMutationInstance( mutation_id_base, @@ -391,7 +430,8 @@ void MutationReplaceExpr::GenerateIntegerConstantReplacement( } } void MutationReplaceExpr::GenerateBooleanConstantReplacement( - clang::ASTContext& ast_context, bool optimise_mutations, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, bool optimise_mutations, bool only_track_mutant_coverage, int mutation_id_base, std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceExpr& protobuf_message) const { @@ -403,10 +443,11 @@ void MutationReplaceExpr::GenerateBooleanConstantReplacement( !IsBooleanReplacementRedundantForBinaryOperator(true, ast_context))) { // Replace expression with true if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return " - << (ast_context.getLangOpts().CPlusPlus ? "true" : "1") - << ";\n"; + const std::string macro_name = "REPLACE_EXPR_TRUE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro( + macro_name, (ast_context.getLangOpts().CPlusPlus ? "true" : "1"))); } AddMutationInstance(mutation_id_base, protobufs::MutationReplaceExprAction::ReplaceWithTrue, @@ -418,10 +459,11 @@ void MutationReplaceExpr::GenerateBooleanConstantReplacement( !IsBooleanReplacementRedundantForBinaryOperator(false, ast_context))) { // Replace expression with false if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return " - << (ast_context.getLangOpts().CPlusPlus ? "false" : "0") - << ";\n"; + const std::string macro_name = "REPLACE_EXPR_FALSE"; + new_function << " " << macro_name << "(" << mutation_id_offset + << ");\n"; + dredd_macros.insert(GenerateMutationMacro( + macro_name, (ast_context.getLangOpts().CPlusPlus ? "false" : "0"))); } AddMutationInstance( mutation_id_base, @@ -432,9 +474,11 @@ void MutationReplaceExpr::GenerateBooleanConstantReplacement( } std::string MutationReplaceExpr::GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& input_type, - bool optimise_mutations, bool only_track_mutant_coverage, int& mutation_id, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& input_type, bool optimise_mutations, + bool only_track_mutant_coverage, int& mutation_id, protobufs::MutationReplaceExpr& protobuf_message) const { std::stringstream new_function; new_function << "static " << result_type << " " << function_name << "("; @@ -459,26 +503,26 @@ std::string MutationReplaceExpr::GenerateMutatorFunction( if (!only_track_mutant_coverage) { // Quickly apply the original operator if no mutant is enabled (which will // be the common case). - new_function << " if (!__dredd_some_mutation_enabled) return " - << arg_evaluated << ";\n"; + new_function << " MUTATION_PRELUDE(" << arg_evaluated << ");\n"; } int mutation_id_offset = 0; - GenerateUnaryOperatorInsertion(arg_evaluated, ast_context, optimise_mutations, - only_track_mutant_coverage, mutation_id, - new_function, mutation_id_offset, + GenerateUnaryOperatorInsertion(arg_evaluated, ast_context, dredd_macros, + optimise_mutations, only_track_mutant_coverage, + mutation_id, new_function, mutation_id_offset, protobuf_message); GenerateConstantReplacement( - ast_context, optimise_mutations, only_track_mutant_coverage, mutation_id, - new_function, mutation_id_offset, protobuf_message); + ast_context, dredd_macros, optimise_mutations, only_track_mutant_coverage, + mutation_id, new_function, mutation_id_offset, protobuf_message); if (only_track_mutant_coverage) { new_function << " __dredd_record_covered_mutants(local_mutation_id, " + std::to_string(mutation_id_offset) + ");\n"; } - new_function << " return " << arg_evaluated << ";\n"; + // new_function << " return " << arg_evaluated << ";\n"; + new_function << " return MUTATION_RETURN(" << arg_evaluated << ");\n"; new_function << "}\n\n"; mutation_id += mutation_id_offset; @@ -596,7 +640,8 @@ protobufs::MutationGroup MutationReplaceExpr::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& dredd_declarations) const { + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const { // The protobuf object for the mutation, which will be wrapped in a // MutationGroup. protobufs::MutationReplaceExpr inner_result; @@ -634,7 +679,7 @@ protobufs::MutationGroup MutationReplaceExpr::Apply( ast_context, preprocessor, rewriter); const std::string new_function = GenerateMutatorFunction( - ast_context, new_function_name, result_type, input_type, + ast_context, dredd_macros, new_function_name, result_type, input_type, optimise_mutations, only_track_mutant_coverage, mutation_id, inner_result); assert(!new_function.empty() && "Unsupported expression."); diff --git a/src/libdredd/src/mutation_replace_unary_operator.cc b/src/libdredd/src/mutation_replace_unary_operator.cc index b9db1c3f..1be538d7 100644 --- a/src/libdredd/src/mutation_replace_unary_operator.cc +++ b/src/libdredd/src/mutation_replace_unary_operator.cc @@ -93,38 +93,37 @@ bool MutationReplaceUnaryOperator::IsValidReplacementOperator( return true; } -std::string MutationReplaceUnaryOperator::GetFunctionName( - bool optimise_mutations, clang::ASTContext& ast_context) const { - std::string result = "__dredd_replace_unary_operator_"; - - // A string corresponding to the unary operator forms part of the name of the - // mutation function, to differentiate mutation functions for different - // operators - switch (unary_operator_->getOpcode()) { +std::string MutationReplaceUnaryOperator::OpKindToString( + clang::UnaryOperatorKind kind) { + switch (kind) { case clang::UnaryOperatorKind::UO_Minus: - result += "Minus"; - break; + return "Minus"; case clang::UnaryOperatorKind::UO_Not: - result += "Not"; - break; + return "Not"; case clang::UnaryOperatorKind::UO_PreDec: - result += "PreDec"; - break; + return "PreDec"; case clang::UnaryOperatorKind::UO_PostDec: - result += "PostDec"; - break; + return "PostDec"; case clang::UnaryOperatorKind::UO_PreInc: - result += "PreInc"; - break; + return "PreInc"; case clang::UnaryOperatorKind::UO_PostInc: - result += "PostInc"; - break; + return "PostInc"; case clang::UnaryOperatorKind::UO_LNot: - result += "LNot"; - break; + return "LNot"; default: assert(false && "Unsupported opcode"); + return ""; } +} + +std::string MutationReplaceUnaryOperator::GetFunctionName( + bool optimise_mutations, clang::ASTContext& ast_context) const { + std::string result = "__dredd_replace_unary_operator_"; + + // A string corresponding to the unary operator forms part of the name of the + // mutation function, to differentiate mutation functions for different + // operators + result += OpKindToString(unary_operator_->getOpcode()); if (unary_operator_->getSubExpr()->isLValue()) { const clang::QualType qualified_type = @@ -179,9 +178,11 @@ std::string MutationReplaceUnaryOperator::GetFunctionName( } std::string MutationReplaceUnaryOperator::GenerateMutatorFunction( - clang::ASTContext& ast_context, const std::string& function_name, - const std::string& result_type, const std::string& input_type, - bool optimise_mutations, bool only_track_mutant_coverage, int& mutation_id, + clang::ASTContext& ast_context, + std::unordered_set& dredd_macros, + const std::string& function_name, const std::string& result_type, + const std::string& input_type, bool optimise_mutations, + bool only_track_mutant_coverage, int& mutation_id, protobufs::MutationReplaceUnaryOperator& protobuf_message) const { std::stringstream new_function; new_function << "static " << result_type << " " << function_name << "("; @@ -207,24 +208,24 @@ std::string MutationReplaceUnaryOperator::GenerateMutatorFunction( if (!only_track_mutant_coverage) { // Quickly apply the original operator if no mutant is enabled (which will // be the common case). - new_function << " if (!__dredd_some_mutation_enabled) return "; + new_function << " MUTATION_PRELUDE("; if (IsPrefix(unary_operator_->getOpcode())) { new_function << clang::UnaryOperator::getOpcodeStr( unary_operator_->getOpcode()) .str() - << arg_evaluated + ";\n"; + << arg_evaluated + ");\n"; } else { new_function << arg_evaluated << clang::UnaryOperator::getOpcodeStr( unary_operator_->getOpcode()) .str() - << ";\n"; + << ");\n"; } } int mutation_id_offset = 0; GenerateUnaryOperatorReplacement( - arg_evaluated, ast_context, optimise_mutations, + arg_evaluated, ast_context, dredd_macros, optimise_mutations, only_track_mutant_coverage, mutation_id, new_function, mutation_id_offset, protobuf_message); @@ -235,11 +236,11 @@ std::string MutationReplaceUnaryOperator::GenerateMutatorFunction( const std::string opcode_string = clang::UnaryOperator::getOpcodeStr(unary_operator_->getOpcode()).str(); - new_function << " return " + new_function << " return MUTATION_RETURN(" << (IsPrefix(unary_operator_->getOpcode()) ? opcode_string : "") << arg_evaluated << (IsPrefix(unary_operator_->getOpcode()) ? "" : opcode_string) - << ";\n"; + << ");\n"; new_function << "}\n\n"; @@ -281,11 +282,26 @@ bool MutationReplaceUnaryOperator::IsRedundantReplacementOperator( return false; } +std::string MutationReplaceUnaryOperator::GetUnaryMacroName( + const std::string& operator_name, + const clang::ASTContext& ast_context) const { + std::string result = "REPLACE_UNARY_" + operator_name; + if (ast_context.getLangOpts().CPlusPlus && + unary_operator_->HasSideEffects(ast_context)) { + result += "_EVALUATED"; + } + if (!ast_context.getLangOpts().CPlusPlus && + unary_operator_->isIncrementDecrementOp()) { + result += "_POINTER"; + } + return result; +} + void MutationReplaceUnaryOperator::GenerateUnaryOperatorReplacement( const std::string& arg_evaluated, const clang::ASTContext& ast_context, - bool optimise_mutations, bool only_track_mutant_coverage, - int mutation_id_base, std::stringstream& new_function, - int& mutation_id_offset, + std::unordered_set& dredd_macros, bool optimise_mutations, + bool only_track_mutant_coverage, int mutation_id_base, + std::stringstream& new_function, int& mutation_id_offset, protobufs::MutationReplaceUnaryOperator& protobuf_message) const { const std::vector candidate_replacement_operators = {clang::UnaryOperatorKind::UO_PreInc, @@ -304,15 +320,19 @@ void MutationReplaceUnaryOperator::GenerateUnaryOperatorReplacement( continue; } if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset << ")) return "; + const std::string macro_name = + GetUnaryMacroName(OpKindToString(operator_kind), ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; if (IsPrefix(operator_kind)) { - new_function << clang::UnaryOperator::getOpcodeStr(operator_kind).str() - << arg_evaluated + ";\n"; + dredd_macros.insert(GenerateMutationMacro( + macro_name, + clang::UnaryOperator::getOpcodeStr(operator_kind).str() + + arg_evaluated)); } else { - new_function << arg_evaluated - << clang::UnaryOperator::getOpcodeStr(operator_kind).str() - << ";\n"; + dredd_macros.insert(GenerateMutationMacro( + macro_name, + arg_evaluated + + clang::UnaryOperator::getOpcodeStr(operator_kind).str())); } } AddMutationInstance(mutation_id_base, OperatorKindToAction(operator_kind), @@ -324,9 +344,9 @@ void MutationReplaceUnaryOperator::GenerateUnaryOperatorReplacement( // another mutation. if (!optimise_mutations || !IsOperatorSelfInverse()) { if (!only_track_mutant_coverage) { - new_function << " if (__dredd_enabled_mutation(local_mutation_id + " - << mutation_id_offset - << ")) return " + arg_evaluated + ";\n"; + const std::string macro_name = GetUnaryMacroName("ARG", ast_context); + new_function << " " << macro_name << "(" << mutation_id_offset << ");\n"; + dredd_macros.insert(GenerateMutationMacro(macro_name, arg_evaluated)); } AddMutationInstance( mutation_id_base, @@ -339,7 +359,8 @@ protobufs::MutationGroup MutationReplaceUnaryOperator::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& dredd_declarations) const { + std::unordered_set& dredd_declarations, + std::unordered_set& dredd_macros) const { // The protobuf object for the mutation, which will be wrapped in a // MutationGroup. protobufs::MutationReplaceUnaryOperator inner_result; @@ -449,7 +470,7 @@ protobufs::MutationGroup MutationReplaceUnaryOperator::Apply( (void)rewriter_result; // Keep release-mode compilers happy. const std::string new_function = GenerateMutatorFunction( - ast_context, new_function_name, result_type, input_type, + ast_context, dredd_macros, new_function_name, result_type, input_type, optimise_mutations, only_track_mutant_coverage, mutation_id, inner_result); assert(!new_function.empty() && "Unsupported opcode."); diff --git a/src/libdredd/src/util.cc b/src/libdredd/src/util.cc index 53591ddc..dcf6546a 100644 --- a/src/libdredd/src/util.cc +++ b/src/libdredd/src/util.cc @@ -129,4 +129,21 @@ bool IsCxx11ConstantExpr(const clang::Expr& expr, return !expr.isValueDependent() && expr.isCXX11ConstantExpr(ast_context); } +std::string GenerateMutationPrelude() { + return "#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) " + "return arg\n"; +} + +std::string GenerateMutationMacro(const std::string& name, + const std::string& args_evaluated) { + return "#define " + name + + "(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id " + "+ mutation_id_offset)) return " + + args_evaluated + "\n"; +} + +std::string GenerateMutationReturn() { + return "#define MUTATION_RETURN(arg) arg\n"; +} + } // namespace dredd diff --git a/src/libdreddtest/src/mutation_remove_stmt_test.cc b/src/libdreddtest/src/mutation_remove_stmt_test.cc index 315d2c9b..5088a871 100644 --- a/src/libdreddtest/src/mutation_remove_stmt_test.cc +++ b/src/libdreddtest/src/mutation_remove_stmt_test.cc @@ -47,9 +47,10 @@ void TestRemoval(const std::string& original, const std::string& expected, ast_unit->getLangOpts()); int mutation_id = 0; std::unordered_set dredd_declarations; + std::unordered_set dredd_macros; mutation_supplier(ast_unit->getPreprocessor(), ast_unit->getASTContext()) .Apply(ast_unit->getASTContext(), ast_unit->getPreprocessor(), true, - false, 0, mutation_id, rewriter, dredd_declarations); + false, 0, mutation_id, rewriter, dredd_declarations, dredd_macros); ASSERT_EQ(1, mutation_id); ASSERT_EQ(0, dredd_declarations.size()); const clang::RewriteBuffer* rewrite_buffer = rewriter.getRewriteBufferFor( diff --git a/src/libdreddtest/src/mutation_replace_binary_operator_test.cc b/src/libdreddtest/src/mutation_replace_binary_operator_test.cc index 2a5bef1c..45621c19 100644 --- a/src/libdreddtest/src/mutation_replace_binary_operator_test.cc +++ b/src/libdreddtest/src/mutation_replace_binary_operator_test.cc @@ -57,9 +57,10 @@ void TestReplacement(const std::string& original, const std::string& expected, ast_unit->getLangOpts()); int mutation_id = 0; std::unordered_set dredd_declarations; + std::unordered_set dredd_macros; mutation.Apply(ast_unit->getASTContext(), ast_unit->getPreprocessor(), optimise_mutations, false, 0, mutation_id, rewriter, - dredd_declarations); + dredd_declarations, dredd_macros); ASSERT_EQ(num_replacements, mutation_id); ASSERT_EQ(1, dredd_declarations.size()); ASSERT_EQ(expected_dredd_declaration, *dredd_declarations.begin()); @@ -80,12 +81,12 @@ TEST(MutationReplaceBinaryOperatorTest, MutateAdd) { "}"; const std::string expected_dredd_declaration_opt = R"(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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG2(3); + return MUTATION_RETURN(arg1 + arg2); } )"; @@ -100,14 +101,14 @@ TEST(MutationReplaceBinaryOperatorTest, MutateAdd) { "}"; const std::string expected_dredd_declaration_no_opt = R"(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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } )"; @@ -129,11 +130,11 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAnd) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_EQ_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 && arg2()); } )"; @@ -149,13 +150,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAnd) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_LOr_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 && arg2()); } )"; @@ -177,11 +178,11 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLOr) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LOr_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 || arg2(); + MUTATION_PRELUDE(arg1 || arg2()); + REPLACE_BINARY_NE_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 || arg2()); } )"; @@ -197,13 +198,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLOr) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LOr_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 || arg2(); + MUTATION_PRELUDE(arg1 || arg2()); + REPLACE_BINARY_LAnd_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 || arg2()); } )"; @@ -225,10 +226,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateGT) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_GT_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; - return arg1 > arg2; + MUTATION_PRELUDE(arg1 > arg2); + REPLACE_BINARY_NE(0); + REPLACE_BINARY_GE(1); + return MUTATION_RETURN(arg1 > arg2); } )"; @@ -244,15 +245,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateGT) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_GT_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 > arg2; + MUTATION_PRELUDE(arg1 > arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_NE(1); + REPLACE_BINARY_GE(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 > arg2); } )"; @@ -274,10 +275,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLT) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LT_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; - return arg1 < arg2; + MUTATION_PRELUDE(arg1 < arg2); + REPLACE_BINARY_NE(0); + REPLACE_BINARY_LE(1); + return MUTATION_RETURN(arg1 < arg2); } )"; @@ -293,15 +294,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLT) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LT_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 <= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 < arg2; + MUTATION_PRELUDE(arg1 < arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_NE(1); + REPLACE_BINARY_GE(2); + REPLACE_BINARY_GT(3); + REPLACE_BINARY_LE(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 < arg2); } )"; @@ -323,10 +324,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateEQ) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_EQ_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; - return arg1 == arg2; + MUTATION_PRELUDE(arg1 == arg2); + REPLACE_BINARY_GE(0); + REPLACE_BINARY_LE(1); + return MUTATION_RETURN(arg1 == arg2); } )"; @@ -342,15 +343,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateEQ) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_EQ_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 == arg2; + MUTATION_PRELUDE(arg1 == arg2); + REPLACE_BINARY_NE(0); + REPLACE_BINARY_GE(1); + REPLACE_BINARY_GT(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 == arg2); } )"; @@ -372,10 +373,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateGE) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_GE_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; - return arg1 >= arg2; + MUTATION_PRELUDE(arg1 >= arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_GT(1); + return MUTATION_RETURN(arg1 >= arg2); } )"; @@ -391,15 +392,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateGE) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_GE_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 >= arg2; + MUTATION_PRELUDE(arg1 >= arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_NE(1); + REPLACE_BINARY_GT(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 >= arg2); } )"; @@ -421,10 +422,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLE) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LE_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; - return arg1 <= arg2; + MUTATION_PRELUDE(arg1 <= arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_LT(1); + return MUTATION_RETURN(arg1 <= arg2); } )"; @@ -440,15 +441,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLE) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LE_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 <= arg2; + MUTATION_PRELUDE(arg1 <= arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_NE(1); + REPLACE_BINARY_GE(2); + REPLACE_BINARY_GT(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 <= arg2); } )"; @@ -470,10 +471,10 @@ TEST(MutationReplaceBinaryOperatorTest, MutateNE) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_NE_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; - return arg1 != arg2; + MUTATION_PRELUDE(arg1 != arg2); + REPLACE_BINARY_GT(0); + REPLACE_BINARY_LT(1); + return MUTATION_RETURN(arg1 != arg2); } )"; @@ -489,15 +490,15 @@ TEST(MutationReplaceBinaryOperatorTest, MutateNE) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_NE_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 != arg2; + MUTATION_PRELUDE(arg1 != arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_GE(1); + REPLACE_BINARY_GT(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 != arg2); } )"; @@ -521,18 +522,18 @@ TEST(MutationReplaceBinaryOperatorTest, MutateAssign) { )"; const std::string expected_dredd_declaration_opt = R"(static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } )"; @@ -549,18 +550,18 @@ TEST(MutationReplaceBinaryOperatorTest, MutateAssign) { )"; const std::string expected_dredd_declaration_no_opt = R"(static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } )"; @@ -588,18 +589,18 @@ void foo() { )"; const std::string expected_dredd_declaration_opt = R"(static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } )"; @@ -618,18 +619,18 @@ void foo() { )"; const std::string expected_dredd_declaration_no_opt = R"(static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } )"; @@ -655,13 +656,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateFloatDiv) { )"; const std::string expected_dredd_declaration_opt = R"(static float __dredd_replace_binary_operator_Div_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 / arg2; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 / arg2); } )"; @@ -679,13 +680,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateFloatDiv) { )"; const std::string expected_dredd_declaration_no_opt = R"(static float __dredd_replace_binary_operator_Div_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 / arg2; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 / arg2); } )"; @@ -711,12 +712,12 @@ TEST(MutationReplaceBinaryOperatorTest, MutateFloatSubAssign) { )"; const std::string expected_dredd_declaration_opt = R"(static double& __dredd_replace_binary_operator_SubAssign_arg1_double_arg2_double(double& arg1, double 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; - return arg1 -= arg2; + MUTATION_PRELUDE(arg1 -= arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + return MUTATION_RETURN(arg1 -= arg2); } )"; @@ -734,12 +735,12 @@ TEST(MutationReplaceBinaryOperatorTest, MutateFloatSubAssign) { )"; const std::string expected_dredd_declaration_no_opt = R"(static double& __dredd_replace_binary_operator_SubAssign_arg1_double_arg2_double(double& arg1, double 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; - return arg1 -= arg2; + MUTATION_PRELUDE(arg1 -= arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + return MUTATION_RETURN(arg1 -= arg2); } )"; @@ -761,11 +762,11 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithLhsSideEffect) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(std::function arg1, std::function 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(); - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1() && arg2(); + MUTATION_PRELUDE(arg1() && arg2()); + REPLACE_BINARY_EQ_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1_EVALUATED(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1() && arg2()); } )"; @@ -781,13 +782,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithLhsSideEffect) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(std::function arg1, std::function 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(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1() && arg2(); + MUTATION_PRELUDE(arg1() && arg2()); + REPLACE_BINARY_LOr_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_LHS_EVALUATED_RHS_EVALUATED(1); + REPLACE_BINARY_NE_LHS_EVALUATED_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1_EVALUATED(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1() && arg2()); } )"; @@ -809,11 +810,11 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithRhsSideEffect) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_EQ_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 && arg2()); } )"; @@ -829,13 +830,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithRhsSideEffect) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_LOr_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 && arg2()); } )"; @@ -857,11 +858,11 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithLhsRhsSideEffect) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(std::function arg1, std::function 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(); - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1() && arg2(); + MUTATION_PRELUDE(arg1() && arg2()); + REPLACE_BINARY_EQ_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1_EVALUATED(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1() && arg2()); } )"; @@ -877,13 +878,13 @@ TEST(MutationReplaceBinaryOperatorTest, MutateLAndWithLhsRhsSideEffect) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(std::function arg1, std::function 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(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1() && arg2(); + MUTATION_PRELUDE(arg1() && arg2()); + REPLACE_BINARY_LOr_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_LHS_EVALUATED_RHS_EVALUATED(1); + REPLACE_BINARY_NE_LHS_EVALUATED_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1_EVALUATED(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1() && arg2()); } )"; diff --git a/src/libdreddtest/src/mutation_replace_expr_test.cc b/src/libdreddtest/src/mutation_replace_expr_test.cc index d416e996..5d6905e4 100644 --- a/src/libdreddtest/src/mutation_replace_expr_test.cc +++ b/src/libdreddtest/src/mutation_replace_expr_test.cc @@ -60,8 +60,10 @@ void TestReplacement(const std::string& original, const std::string& expected, ast_unit->getLangOpts()); int mutation_id = 0; std::unordered_set dredd_declarations; + std::unordered_set dredd_macros; mutation.Apply(ast_unit->getASTContext(), ast_unit->getPreprocessor(), true, - false, 0, mutation_id, rewriter, dredd_declarations); + false, 0, mutation_id, rewriter, dredd_declarations, + dredd_macros); ASSERT_EQ(num_replacements, mutation_id); ASSERT_EQ(1, dredd_declarations.size()); ASSERT_EQ(expected_dredd_declaration, *dredd_declarations.begin()); @@ -79,13 +81,13 @@ TEST(MutationReplaceExprTest, MutateSignedConstants) { "void foo() { __dredd_replace_expr_int_constant(2, 0); }"; const std::string expected_dredd_declaration = R"(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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } )"; @@ -101,11 +103,11 @@ TEST(MutationReplaceExprTest, MutateUnsignedConstants) { "__dredd_replace_expr_unsigned_int_constant(2, 0); }"; const std::string expected_dredd_declaration = R"(static unsigned int __dredd_replace_expr_unsigned_int_constant(unsigned 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_ONE(2); + return MUTATION_RETURN(arg); } )"; @@ -120,12 +122,12 @@ TEST(MutationReplaceExprTest, MutateFloatConstants) { "void foo() { __dredd_replace_expr_double(2.523, 0); }"; const std::string expected_dredd_declaration = R"(static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } )"; @@ -149,10 +151,10 @@ TEST(MutationReplaceExprTest, MutateLValues) { )"; const std::string expected_dredd_declaration = R"(static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } )"; @@ -190,14 +192,14 @@ int neg(int x) { )"; const std::string expected_dredd_declaration = R"(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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } )"; @@ -221,9 +223,9 @@ bool foo(bool a, bool b) { )"; const std::string expected_dredd_declaration = R"(static bool __dredd_replace_expr_bool_omit_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } )"; @@ -247,9 +249,9 @@ bool foo(bool a, bool b) { )"; const std::string expected_dredd_declaration = R"(static bool __dredd_replace_expr_bool_omit_false(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + return MUTATION_RETURN(arg); } )"; diff --git a/src/libdreddtest/src/mutation_replace_unary_operator_test.cc b/src/libdreddtest/src/mutation_replace_unary_operator_test.cc index c31780bc..138cb7d3 100644 --- a/src/libdreddtest/src/mutation_replace_unary_operator_test.cc +++ b/src/libdreddtest/src/mutation_replace_unary_operator_test.cc @@ -57,9 +57,10 @@ void TestReplacement(const std::string& original, const std::string& expected, ast_unit->getLangOpts()); int mutation_id = 0; std::unordered_set dredd_declarations; + std::unordered_set dredd_macros; mutation.Apply(ast_unit->getASTContext(), ast_unit->getPreprocessor(), optimise_mutations, false, 0, mutation_id, rewriter, - dredd_declarations); + dredd_declarations, dredd_macros); ASSERT_EQ(num_replacements, mutation_id); ASSERT_EQ(1, dredd_declarations.size()); ASSERT_EQ(expected_dredd_declaration, *dredd_declarations.begin()); @@ -77,10 +78,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateMinus) { "void foo() { __dredd_replace_unary_operator_Minus_int(2, 0); }"; const std::string expected_dredd_declaration_opt = R"(static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(-arg); } )"; @@ -94,11 +95,11 @@ TEST(MutationReplaceUnaryOperatorTest, MutateMinus) { "void foo() { __dredd_replace_unary_operator_Minus_int(2, 0); }"; const std::string expected_dredd_declaration_no_opt = R"(static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } )"; @@ -123,10 +124,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateNot) { )"; const std::string expected_dredd_declaration_opt = R"(static bool __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + return MUTATION_RETURN(!arg); } )"; @@ -144,11 +145,11 @@ TEST(MutationReplaceUnaryOperatorTest, MutateNot) { )"; const std::string expected_dredd_declaration_no_opt = R"(static bool __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(!arg); } )"; @@ -173,10 +174,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateIncrement) { )"; const std::string expected_dredd_declaration_opt = R"(static double& __dredd_replace_unary_operator_PreInc_double(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } )"; @@ -194,10 +195,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateIncrement) { )"; const std::string expected_dredd_declaration_noopt = R"(static double& __dredd_replace_unary_operator_PreInc_double(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } )"; @@ -222,13 +223,13 @@ TEST(MutationReplaceUnaryOperatorTest, MutateDecrement) { )"; const std::string expected_dredd_declaration_opt = R"(static int __dredd_replace_unary_operator_PostDec_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()--); } )"; @@ -246,13 +247,13 @@ TEST(MutationReplaceUnaryOperatorTest, MutateDecrement) { )"; const std::string expected_dredd_declaration_no_opt = R"(static int __dredd_replace_unary_operator_PostDec_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()--); } )"; @@ -277,10 +278,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateDecrementAssign) { )"; const std::string expected_dredd_declaration_opt = R"(static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } )"; @@ -298,10 +299,10 @@ TEST(MutationReplaceUnaryOperatorTest, MutateDecrementAssign) { )"; const std::string expected_dredd_declaration_no_opt = R"(static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } )"; diff --git a/test/single_file/add.c.expected b/test/single_file/add.c.expected index a5a6b094..da3b9fee 100644 --- a/test/single_file/add.c.expected +++ b/test/single_file/add.c.expected @@ -40,51 +40,67 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add.c.noopt.expected b/test/single_file/add.c.noopt.expected index 60632ba4..f9bc3b4a 100644 --- a/test/single_file/add.c.noopt.expected +++ b/test/single_file/add.c.noopt.expected @@ -40,33 +40,49 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add.cc.expected b/test/single_file/add.cc.expected index b4286cba..507f78a5 100644 --- a/test/single_file/add.cc.expected +++ b/test/single_file/add.cc.expected @@ -42,51 +42,67 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add.cc.noopt.expected b/test/single_file/add.cc.noopt.expected index d80b67a4..87cca3bf 100644 --- a/test/single_file/add.cc.noopt.expected +++ b/test/single_file/add.cc.noopt.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_float.c.expected b/test/single_file/add_float.c.expected index dc5a9f3c..d88bf3c9 100644 --- a/test/single_file/add_float.c.expected +++ b/test/single_file/add_float.c.expected @@ -40,46 +40,65 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float_lvalue(float* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_Assign_arg1_float_arg2_float(float* arg1, float 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; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_DivAssign_LHS_POINTER(1); + REPLACE_BINARY_MulAssign_LHS_POINTER(2); + REPLACE_BINARY_SubAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) = arg2); } static float __dredd_replace_binary_operator_Add_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_float.c.noopt.expected b/test/single_file/add_float.c.noopt.expected index cbc735e5..e53a80f5 100644 --- a/test/single_file/add_float.c.noopt.expected +++ b/test/single_file/add_float.c.noopt.expected @@ -40,59 +40,81 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float_lvalue(float* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_Assign_arg1_float_arg2_float(float* arg1, float 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; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_DivAssign_LHS_POINTER(1); + REPLACE_BINARY_MulAssign_LHS_POINTER(2); + REPLACE_BINARY_SubAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) = arg2); } static float __dredd_replace_binary_operator_Add_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/add_float.cc.expected b/test/single_file/add_float.cc.expected index bd19dacf..3d531023 100644 --- a/test/single_file/add_float.cc.expected +++ b/test/single_file/add_float.cc.expected @@ -42,46 +42,65 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static float& __dredd_replace_binary_operator_Assign_arg1_float_arg2_float(float& arg1, float 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; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_DivAssign(1); + REPLACE_BINARY_MulAssign(2); + REPLACE_BINARY_SubAssign(3); + return MUTATION_RETURN(arg1 = arg2); } static float __dredd_replace_expr_float_lvalue(float& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_Add_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_float.cc.noopt.expected b/test/single_file/add_float.cc.noopt.expected index 64c3ffc2..df946bbe 100644 --- a/test/single_file/add_float.cc.noopt.expected +++ b/test/single_file/add_float.cc.noopt.expected @@ -42,59 +42,81 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float& __dredd_replace_binary_operator_Assign_arg1_float_arg2_float(float& arg1, float 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; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_DivAssign(1); + REPLACE_BINARY_MulAssign(2); + REPLACE_BINARY_SubAssign(3); + return MUTATION_RETURN(arg1 = arg2); } static float __dredd_replace_expr_float_lvalue(float& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_Add_arg1_float_arg2_float(float arg1, float 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/add_mul.c.expected b/test/single_file/add_mul.c.expected index 8fee7775..725f65e7 100644 --- a/test/single_file/add_mul.c.expected +++ b/test/single_file/add_mul.c.expected @@ -40,62 +40,79 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Mul_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; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 * arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_mul.c.noopt.expected b/test/single_file/add_mul.c.noopt.expected index 688b1c5b..e5ef73a0 100644 --- a/test/single_file/add_mul.c.noopt.expected +++ b/test/single_file/add_mul.c.noopt.expected @@ -40,44 +40,61 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Mul_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; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 * arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_mul.cc.expected b/test/single_file/add_mul.cc.expected index 3e37d850..41efcd13 100644 --- a/test/single_file/add_mul.cc.expected +++ b/test/single_file/add_mul.cc.expected @@ -42,62 +42,79 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Mul_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; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 * arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_mul.cc.noopt.expected b/test/single_file/add_mul.cc.noopt.expected index 5089250e..38f052f0 100644 --- a/test/single_file/add_mul.cc.noopt.expected +++ b/test/single_file/add_mul.cc.noopt.expected @@ -42,44 +42,61 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Mul_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; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 * arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/add_type_aliases.c.noopt.expected b/test/single_file/add_type_aliases.c.noopt.expected index 00424d5f..93ba3176 100644 --- a/test/single_file/add_type_aliases.c.noopt.expected +++ b/test/single_file/add_type_aliases.c.noopt.expected @@ -40,116 +40,132 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned long __dredd_replace_expr_unsigned_long_lvalue(unsigned long* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static unsigned long __dredd_replace_expr_unsigned_long(unsigned long 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned long __dredd_replace_binary_operator_Add_arg1_unsigned_long_arg2_unsigned_long(unsigned long arg1, unsigned long 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Add_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static long __dredd_replace_expr_long_lvalue(long* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static long __dredd_replace_expr_long(long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static long __dredd_replace_binary_operator_Add_arg1_long_arg2_long(long arg1, long 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } #include diff --git a/test/single_file/add_type_aliases.cc.noopt.expected b/test/single_file/add_type_aliases.cc.noopt.expected index 087aed5a..72ca90e4 100644 --- a/test/single_file/add_type_aliases.cc.noopt.expected +++ b/test/single_file/add_type_aliases.cc.noopt.expected @@ -42,116 +42,132 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned long __dredd_replace_expr_unsigned_long_lvalue(unsigned long& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static unsigned long __dredd_replace_expr_unsigned_long(unsigned long 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned long __dredd_replace_binary_operator_Add_arg1_unsigned_long_arg2_unsigned_long(unsigned long arg1, unsigned long 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Add_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static long __dredd_replace_expr_long_lvalue(long& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static long __dredd_replace_expr_long(long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static long __dredd_replace_binary_operator_Add_arg1_long_arg2_long(long arg1, long 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } #include diff --git a/test/single_file/assign.c.expected b/test/single_file/assign.c.expected index c94e399a..89b84ed2 100644 --- a/test/single_file/assign.c.expected +++ b/test/single_file/assign.c.expected @@ -40,44 +40,61 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(volatile 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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/assign.c.noopt.expected b/test/single_file/assign.c.noopt.expected index 882db8bf..34d76156 100644 --- a/test/single_file/assign.c.noopt.expected +++ b/test/single_file/assign.c.noopt.expected @@ -40,45 +40,63 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(volatile 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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/assign.cc.expected b/test/single_file/assign.cc.expected index 1d358437..b348490d 100644 --- a/test/single_file/assign.cc.expected +++ b/test/single_file/assign.cc.expected @@ -42,44 +42,61 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(volatile 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/assign.cc.noopt.expected b/test/single_file/assign.cc.noopt.expected index 385d29f1..bc4a7c32 100644 --- a/test/single_file/assign.cc.noopt.expected +++ b/test/single_file/assign.cc.noopt.expected @@ -42,45 +42,63 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(volatile 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/auto.cc.expected b/test/single_file/auto.cc.expected index 317b0f50..010a2e3a 100644 --- a/test/single_file/auto.cc.expected +++ b/test/single_file/auto.cc.expected @@ -42,32 +42,42 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int foo(int x) { diff --git a/test/single_file/auto.cc.noopt.expected b/test/single_file/auto.cc.noopt.expected index a039fbbf..71d6aa3c 100644 --- a/test/single_file/auto.cc.noopt.expected +++ b/test/single_file/auto.cc.noopt.expected @@ -42,22 +42,32 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int foo(int x) { diff --git a/test/single_file/basic.c.expected b/test/single_file/basic.c.expected index e36beb46..79933fbc 100644 --- a/test/single_file/basic.c.expected +++ b/test/single_file/basic.c.expected @@ -40,11 +40,15 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/basic.c.noopt.expected b/test/single_file/basic.c.noopt.expected index f9efca8c..a899b69e 100644 --- a/test/single_file/basic.c.noopt.expected +++ b/test/single_file/basic.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/basic.cc.expected b/test/single_file/basic.cc.expected index db57b374..2b5b82a7 100644 --- a/test/single_file/basic.cc.expected +++ b/test/single_file/basic.cc.expected @@ -42,11 +42,15 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/basic.cc.noopt.expected b/test/single_file/basic.cc.noopt.expected index f3a7eee8..49832e03 100644 --- a/test/single_file/basic.cc.noopt.expected +++ b/test/single_file/basic.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/binary_lhs_zero.cc.expected b/test/single_file/binary_lhs_zero.cc.expected index 12a7aad8..8414d49a 100644 --- a/test/single_file/binary_lhs_zero.cc.expected +++ b/test/single_file/binary_lhs_zero.cc.expected @@ -42,46 +42,58 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_zero(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 arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + REPLACE_BINARY_ARG2(1); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_lhs_zero.cc.noopt.expected b/test/single_file/binary_lhs_zero.cc.noopt.expected index eb2343a1..8e72326f 100644 --- a/test/single_file/binary_lhs_zero.cc.noopt.expected +++ b/test/single_file/binary_lhs_zero.cc.noopt.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_long_long_and_long_name_clash.c.noopt.expected b/test/single_file/binary_long_long_and_long_name_clash.c.noopt.expected index a92421c5..f9627b16 100644 --- a/test/single_file/binary_long_long_and_long_name_clash.c.noopt.expected +++ b/test/single_file/binary_long_long_and_long_name_clash.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static long long __dredd_replace_expr_long_long(long long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static long long __dredd_replace_binary_operator_LAnd_arg1_long_long_arg2_long_lhs(long long arg, int local_mutation_id) { @@ -64,14 +72,14 @@ static long long __dredd_replace_binary_operator_LAnd_arg1_long_arg2_long_long_r return arg; } static long __dredd_replace_expr_long(long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static long __dredd_replace_binary_operator_LAnd_arg1_long_long_arg2_long_rhs(long arg, int local_mutation_id) { @@ -87,14 +95,14 @@ static long __dredd_replace_binary_operator_LAnd_arg1_long_arg2_long_long_lhs(lo return arg; } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LAnd_arg1_long_long_arg2_long_outer(int arg, int local_mutation_id) { diff --git a/test/single_file/binary_no_arg_replacement.cc.expected b/test/single_file/binary_no_arg_replacement.cc.expected index 88fadba9..546201af 100644 --- a/test/single_file/binary_no_arg_replacement.cc.expected +++ b/test/single_file/binary_no_arg_replacement.cc.expected @@ -42,61 +42,74 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ZERO(0); + REPLACE_EXPR_INT_ONE(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Sub_arg1_int_arg2_int_lhs_zero(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 arg2; - return arg1 - arg2; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_ARG2(0); + return MUTATION_RETURN(arg1 - arg2); } static int __dredd_replace_binary_operator_Mul_arg1_int_arg2_int_lhs_minus_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 arg1 - arg2; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 * arg2; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 * arg2); } static int __dredd_replace_binary_operator_Div_arg1_int_arg2_int_rhs_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 arg1; - return arg1 / arg2; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + return MUTATION_RETURN(arg1 / arg2); } int main() { diff --git a/test/single_file/binary_no_arg_replacement.cc.noopt.expected b/test/single_file/binary_no_arg_replacement.cc.noopt.expected index 954edb87..4e96c2d4 100644 --- a/test/single_file/binary_no_arg_replacement.cc.noopt.expected +++ b/test/single_file/binary_no_arg_replacement.cc.noopt.expected @@ -42,56 +42,74 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Sub_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; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Mul(2); + REPLACE_BINARY_Rem(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 - arg2); } static int __dredd_replace_binary_operator_Mul_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; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 * arg2); } static int __dredd_replace_binary_operator_Div_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; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 / arg2); } int main() { diff --git a/test/single_file/binary_operands_both_zero.c.expected b/test/single_file/binary_operands_both_zero.c.expected index 77c6b73a..27b9869b 100644 --- a/test/single_file/binary_operands_both_zero.c.expected +++ b/test/single_file/binary_operands_both_zero.c.expected @@ -40,80 +40,99 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ZERO(0); + REPLACE_EXPR_INT_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_lhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_lhs_minus_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_one_lhs_minus_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Rem(0); + REPLACE_BINARY_Sub(1); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_minus_one_lhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_minus_one_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_operands_both_zero.c.noopt.expected b/test/single_file/binary_operands_both_zero.c.noopt.expected index 4431ace9..04c2d874 100644 --- a/test/single_file/binary_operands_both_zero.c.noopt.expected +++ b/test/single_file/binary_operands_both_zero.c.noopt.expected @@ -40,49 +40,76 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_operands_both_zero.cc.expected b/test/single_file/binary_operands_both_zero.cc.expected index d6c3d2a6..52abc986 100644 --- a/test/single_file/binary_operands_both_zero.cc.expected +++ b/test/single_file/binary_operands_both_zero.cc.expected @@ -42,80 +42,99 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ZERO(0); + REPLACE_EXPR_INT_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_lhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero_lhs_minus_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_one_lhs_minus_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Rem(0); + REPLACE_BINARY_Sub(1); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_minus_one_lhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_minus_one_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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_operands_both_zero.cc.noopt.expected b/test/single_file/binary_operands_both_zero.cc.noopt.expected index 5971e60c..80892a85 100644 --- a/test/single_file/binary_operands_both_zero.cc.noopt.expected +++ b/test/single_file/binary_operands_both_zero.cc.noopt.expected @@ -42,49 +42,76 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_redundant_name_clash.cc.expected b/test/single_file/binary_redundant_name_clash.cc.expected index d37cd99e..e1fd10e8 100644 --- a/test/single_file/binary_redundant_name_clash.cc.expected +++ b/test/single_file/binary_redundant_name_clash.cc.expected @@ -42,35 +42,46 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_ARG1(1); + return MUTATION_RETURN(arg1 + arg2); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_lhs_zero(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 arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + REPLACE_BINARY_ARG2(1); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_redundant_name_clash.cc.noopt.expected b/test/single_file/binary_redundant_name_clash.cc.noopt.expected index 5112204c..8d03c552 100644 --- a/test/single_file/binary_redundant_name_clash.cc.noopt.expected +++ b/test/single_file/binary_redundant_name_clash.cc.noopt.expected @@ -42,26 +42,40 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_rhs_zero.cc.expected b/test/single_file/binary_rhs_zero.cc.expected index dfdc5bd0..297b2187 100644 --- a/test/single_file/binary_rhs_zero.cc.expected +++ b/test/single_file/binary_rhs_zero.cc.expected @@ -42,46 +42,58 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int_rhs_zero(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; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_ARG1(1); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/binary_rhs_zero.cc.noopt.expected b/test/single_file/binary_rhs_zero.cc.noopt.expected index 1dd5fcc3..28708c9f 100644 --- a/test/single_file/binary_rhs_zero.cc.noopt.expected +++ b/test/single_file/binary_rhs_zero.cc.noopt.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/bitfield.c.expected b/test/single_file/bitfield.c.expected index dff8db80..edf7a3c6 100644 --- a/test/single_file/bitfield.c.expected +++ b/test/single_file/bitfield.c.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } struct S { diff --git a/test/single_file/bitfield.c.noopt.expected b/test/single_file/bitfield.c.noopt.expected index 0a0d422e..78eedf4f 100644 --- a/test/single_file/bitfield.c.noopt.expected +++ b/test/single_file/bitfield.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } struct S { diff --git a/test/single_file/bitfield.cc.expected b/test/single_file/bitfield.cc.expected index d1b84430..a381bafa 100644 --- a/test/single_file/bitfield.cc.expected +++ b/test/single_file/bitfield.cc.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } struct S { diff --git a/test/single_file/bitfield.cc.noopt.expected b/test/single_file/bitfield.cc.noopt.expected index 8e478536..5ebc2938 100644 --- a/test/single_file/bitfield.cc.noopt.expected +++ b/test/single_file/bitfield.cc.noopt.expected @@ -42,26 +42,37 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } struct S { diff --git a/test/single_file/bool_assignment.cc.expected b/test/single_file/bool_assignment.cc.expected index c65e6601..57883838 100644 --- a/test/single_file/bool_assignment.cc.expected +++ b/test/single_file/bool_assignment.cc.expected @@ -42,16 +42,20 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_false(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/bool_assignment.cc.noopt.expected b/test/single_file/bool_assignment.cc.noopt.expected index 763360fc..90f5fab2 100644 --- a/test/single_file/bool_assignment.cc.noopt.expected +++ b/test/single_file/bool_assignment.cc.noopt.expected @@ -42,12 +42,17 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/boolean_not_insertion_optimisation.c.expected b/test/single_file/boolean_not_insertion_optimisation.c.expected index 69dc6968..c7966b0c 100644 --- a/test/single_file/boolean_not_insertion_optimisation.c.expected +++ b/test/single_file/boolean_not_insertion_optimisation.c.expected @@ -40,19 +40,25 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs_zero_lhs_one_rhs(int arg, int local_mutation_id) { 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 a5e6a206..365a26a1 100644 --- a/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected +++ b/test/single_file/boolean_not_insertion_optimisation.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs(int arg, int local_mutation_id) { diff --git a/test/single_file/boolean_not_insertion_optimisation.cc.expected b/test/single_file/boolean_not_insertion_optimisation.cc.expected index ac0fa3ab..0b8b3ef9 100644 --- a/test/single_file/boolean_not_insertion_optimisation.cc.expected +++ b/test/single_file/boolean_not_insertion_optimisation.cc.expected @@ -42,31 +42,45 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool& __dredd_replace_binary_operator_Assign_arg1_bool_arg2_bool(bool& arg1, bool 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_false(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/boolean_not_insertion_optimisation.cc.noopt.expected b/test/single_file/boolean_not_insertion_optimisation.cc.noopt.expected index be92bb0c..b6aca6df 100644 --- a/test/single_file/boolean_not_insertion_optimisation.cc.noopt.expected +++ b/test/single_file/boolean_not_insertion_optimisation.cc.noopt.expected @@ -42,27 +42,42 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool& __dredd_replace_binary_operator_Assign_arg1_bool_arg2_bool(bool& arg1, bool 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/comma.c.expected b/test/single_file/comma.c.expected index aacbccab..c51ce785 100644 --- a/test/single_file/comma.c.expected +++ b/test/single_file/comma.c.expected @@ -40,40 +40,50 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/comma.c.noopt.expected b/test/single_file/comma.c.noopt.expected index b00aa6db..bef58434 100644 --- a/test/single_file/comma.c.noopt.expected +++ b/test/single_file/comma.c.noopt.expected @@ -40,22 +40,32 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/comment.cc.expected b/test/single_file/comment.cc.expected index 5644bba2..2e7abd78 100644 --- a/test/single_file/comment.cc.expected +++ b/test/single_file/comment.cc.expected @@ -42,10 +42,13 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } void g(); diff --git a/test/single_file/comment.cc.noopt.expected b/test/single_file/comment.cc.noopt.expected index 9ede8102..57a1e584 100644 --- a/test/single_file/comment.cc.noopt.expected +++ b/test/single_file/comment.cc.noopt.expected @@ -42,12 +42,17 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } void g(); 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 119a05d0..096f2d7a 100644 --- a/test/single_file/comment_at_start_of_file.cc.expected +++ b/test/single_file/comment_at_start_of_file.cc.expected @@ -42,14 +42,21 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } // Hello 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 055ec6ff..f650d53d 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 @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } // Hello diff --git a/test/single_file/const_expr.cc.expected b/test/single_file/const_expr.cc.expected index 88367221..368e2f1d 100644 --- a/test/single_file/const_expr.cc.expected +++ b/test/single_file/const_expr.cc.expected @@ -42,13 +42,19 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } double foo(const double &x) { diff --git a/test/single_file/const_expr.cc.noopt.expected b/test/single_file/const_expr.cc.noopt.expected index 88367221..368e2f1d 100644 --- a/test/single_file/const_expr.cc.noopt.expected +++ b/test/single_file/const_expr.cc.noopt.expected @@ -42,13 +42,19 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } double foo(const double &x) { diff --git a/test/single_file/const_sized_array_int.c.expected b/test/single_file/const_sized_array_int.c.expected index dd93f512..42e522f6 100644 --- a/test/single_file/const_sized_array_int.c.expected +++ b/test/single_file/const_sized_array_int.c.expected @@ -40,11 +40,15 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/const_sized_array_int.c.noopt.expected b/test/single_file/const_sized_array_int.c.noopt.expected index cd8aae0b..2ade58b7 100644 --- a/test/single_file/const_sized_array_int.c.noopt.expected +++ b/test/single_file/const_sized_array_int.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/const_sized_array_int.cc.expected b/test/single_file/const_sized_array_int.cc.expected index 24965833..f79eaab9 100644 --- a/test/single_file/const_sized_array_int.cc.expected +++ b/test/single_file/const_sized_array_int.cc.expected @@ -42,11 +42,15 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/const_sized_array_int.cc.noopt.expected b/test/single_file/const_sized_array_int.cc.noopt.expected index 32c47e62..e9dce351 100644 --- a/test/single_file/const_sized_array_int.cc.noopt.expected +++ b/test/single_file/const_sized_array_int.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() { 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 ccd687c2..c4a7cc3d 100644 --- a/test/single_file/define_at_start_of_file.c.expected +++ b/test/single_file/define_at_start_of_file.c.expected @@ -40,12 +40,17 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } #define API 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 3fd27dba..9fc0c405 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 @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } #define API diff --git a/test/single_file/define_in_first_decl.c.expected b/test/single_file/define_in_first_decl.c.expected index 8757e783..7e6349e7 100644 --- a/test/single_file/define_in_first_decl.c.expected +++ b/test/single_file/define_in_first_decl.c.expected @@ -40,31 +40,42 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG2(3); + return MUTATION_RETURN(arg1 + arg2); } #define TYPE int 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 9907f2b6..5ea2b826 100644 --- a/test/single_file/define_in_first_decl.c.noopt.expected +++ b/test/single_file/define_in_first_decl.c.noopt.expected @@ -40,26 +40,40 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } #define TYPE int diff --git a/test/single_file/define_in_first_decl.cc.expected b/test/single_file/define_in_first_decl.cc.expected index 43d7a6eb..ab6dd5ae 100644 --- a/test/single_file/define_in_first_decl.cc.expected +++ b/test/single_file/define_in_first_decl.cc.expected @@ -42,31 +42,42 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Rem(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG2(3); + return MUTATION_RETURN(arg1 + arg2); } #define TYPE int 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 35c42a24..8bb37ed4 100644 --- a/test/single_file/define_in_first_decl.cc.noopt.expected +++ b/test/single_file/define_in_first_decl.cc.noopt.expected @@ -42,26 +42,40 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } #define TYPE int diff --git a/test/single_file/enum.c.noopt.expected b/test/single_file/enum.c.noopt.expected index b620bec1..41382fe8 100644 --- a/test/single_file/enum.c.noopt.expected +++ b/test/single_file/enum.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } enum A { diff --git a/test/single_file/expr_lvalue.c.expected b/test/single_file/expr_lvalue.c.expected index 33557f17..e78be5d0 100644 --- a/test/single_file/expr_lvalue.c.expected +++ b/test/single_file/expr_lvalue.c.expected @@ -40,47 +40,67 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/expr_lvalue.c.noopt.expected b/test/single_file/expr_lvalue.c.noopt.expected index 37f9faf5..ff42401f 100644 --- a/test/single_file/expr_lvalue.c.noopt.expected +++ b/test/single_file/expr_lvalue.c.noopt.expected @@ -40,37 +40,57 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/expr_lvalue.cc.expected b/test/single_file/expr_lvalue.cc.expected index 508141c4..e516a8f4 100644 --- a/test/single_file/expr_lvalue.cc.expected +++ b/test/single_file/expr_lvalue.cc.expected @@ -42,47 +42,67 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/expr_lvalue.cc.noopt.expected b/test/single_file/expr_lvalue.cc.noopt.expected index 1031ae7f..518e7591 100644 --- a/test/single_file/expr_lvalue.cc.noopt.expected +++ b/test/single_file/expr_lvalue.cc.noopt.expected @@ -42,37 +42,57 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 = arg2; + MUTATION_PRELUDE(arg1 = arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_AndAssign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 = arg2); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/expr_macro.c.expected b/test/single_file/expr_macro.c.expected index 73200131..db616c30 100644 --- a/test/single_file/expr_macro.c.expected +++ b/test/single_file/expr_macro.c.expected @@ -40,6 +40,8 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #define E (1, 2, 3) void foo(int, int, int); diff --git a/test/single_file/expr_macro.c.noopt.expected b/test/single_file/expr_macro.c.noopt.expected index 73200131..db616c30 100644 --- a/test/single_file/expr_macro.c.noopt.expected +++ b/test/single_file/expr_macro.c.noopt.expected @@ -40,6 +40,8 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #define E (1, 2, 3) void foo(int, int, int); diff --git a/test/single_file/expr_macro.cc.expected b/test/single_file/expr_macro.cc.expected index aa120ead..7fd8b13c 100644 --- a/test/single_file/expr_macro.cc.expected +++ b/test/single_file/expr_macro.cc.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #define E (1, 2, 3) void foo(int, int, int); diff --git a/test/single_file/expr_macro.cc.noopt.expected b/test/single_file/expr_macro.cc.noopt.expected index aa120ead..7fd8b13c 100644 --- a/test/single_file/expr_macro.cc.noopt.expected +++ b/test/single_file/expr_macro.cc.noopt.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #define E (1, 2, 3) void foo(int, int, int); diff --git a/test/single_file/float_binary_opts.c.expected b/test/single_file/float_binary_opts.c.expected index 1922cb7a..999ff5c8 100644 --- a/test/single_file/float_binary_opts.c.expected +++ b/test/single_file/float_binary_opts.c.expected @@ -40,37 +40,48 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double_zero(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ONE(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double_lhs_zero(double arg1, double 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 arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + REPLACE_BINARY_ARG2(1); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/float_binary_opts.c.noopt.expected b/test/single_file/float_binary_opts.c.noopt.expected index 0e238cdc..9842fd78 100644 --- a/test/single_file/float_binary_opts.c.noopt.expected +++ b/test/single_file/float_binary_opts.c.noopt.expected @@ -40,23 +40,34 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/float_binary_opts.cc.expected b/test/single_file/float_binary_opts.cc.expected index 42f247ee..817ce9a4 100644 --- a/test/single_file/float_binary_opts.cc.expected +++ b/test/single_file/float_binary_opts.cc.expected @@ -42,37 +42,48 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double_zero(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ONE(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double_lhs_zero(double arg1, double 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 arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Sub(0); + REPLACE_BINARY_ARG2(1); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/float_binary_opts.cc.noopt.expected b/test/single_file/float_binary_opts.cc.noopt.expected index bf50951b..8672bcaf 100644 --- a/test/single_file/float_binary_opts.cc.noopt.expected +++ b/test/single_file/float_binary_opts.cc.noopt.expected @@ -42,23 +42,34 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/float_unary_opt.c.expected b/test/single_file/float_unary_opt.c.expected index feded92d..3b986a31 100644 --- a/test/single_file/float_unary_opt.c.expected +++ b/test/single_file/float_unary_opt.c.expected @@ -40,18 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double_minus_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/float_unary_opt.c.noopt.expected b/test/single_file/float_unary_opt.c.noopt.expected index b93bb429..e8721914 100644 --- a/test/single_file/float_unary_opt.c.noopt.expected +++ b/test/single_file/float_unary_opt.c.noopt.expected @@ -40,20 +40,28 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_unary_operator_Minus_double(double 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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_LNot(0); + REPLACE_UNARY_ARG(1); + return MUTATION_RETURN(-arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/float_unary_opt.cc.expected b/test/single_file/float_unary_opt.cc.expected index 5b202832..8e082a8c 100644 --- a/test/single_file/float_unary_opt.cc.expected +++ b/test/single_file/float_unary_opt.cc.expected @@ -42,18 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_expr_double_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double_minus_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/float_unary_opt.cc.noopt.expected b/test/single_file/float_unary_opt.cc.noopt.expected index b397aef5..9275f30c 100644 --- a/test/single_file/float_unary_opt.cc.noopt.expected +++ b/test/single_file/float_unary_opt.cc.noopt.expected @@ -42,20 +42,28 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static double __dredd_replace_unary_operator_Minus_double(double 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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_LNot(0); + REPLACE_UNARY_ARG(1); + return MUTATION_RETURN(-arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/floats.c.expected b/test/single_file/floats.c.expected index d00939b0..11025508 100644 --- a/test/single_file/floats.c.expected +++ b/test/single_file/floats.c.expected @@ -40,85 +40,109 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Assign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) = arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_SubAssign_arg1_float_arg2_double(float* arg1, double 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; - return (*arg1) -= arg2; + MUTATION_PRELUDE((*arg1) -= arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_Assign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) -= arg2); } static double __dredd_replace_expr_double_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double_lvalue(double* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Mul_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 * arg2; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 * arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_binary_operator_AddAssign_arg1_double_arg2_double(double* arg1, double 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; - return (*arg1) += arg2; + MUTATION_PRELUDE((*arg1) += arg2); + REPLACE_BINARY_Assign_LHS_POINTER(0); + REPLACE_BINARY_DivAssign_LHS_POINTER(1); + REPLACE_BINARY_MulAssign_LHS_POINTER(2); + REPLACE_BINARY_SubAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) += arg2); } int main() { diff --git a/test/single_file/floats.c.noopt.expected b/test/single_file/floats.c.noopt.expected index a59d9f2c..7b054d37 100644 --- a/test/single_file/floats.c.noopt.expected +++ b/test/single_file/floats.c.noopt.expected @@ -40,78 +40,102 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Assign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) = arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static float __dredd_replace_binary_operator_SubAssign_arg1_float_arg2_double(float* arg1, double 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; - return (*arg1) -= arg2; + MUTATION_PRELUDE((*arg1) -= arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_Assign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) -= arg2); } static double __dredd_replace_expr_double_lvalue(double* 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Mul_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 * arg2; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 * arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } static double __dredd_replace_binary_operator_AddAssign_arg1_double_arg2_double(double* arg1, double 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; - return (*arg1) += arg2; + MUTATION_PRELUDE((*arg1) += arg2); + REPLACE_BINARY_Assign_LHS_POINTER(0); + REPLACE_BINARY_DivAssign_LHS_POINTER(1); + REPLACE_BINARY_MulAssign_LHS_POINTER(2); + REPLACE_BINARY_SubAssign_LHS_POINTER(3); + return MUTATION_RETURN((*arg1) += arg2); } int main() { diff --git a/test/single_file/floats.cc.expected b/test/single_file/floats.cc.expected index 2c819fad..23fbada4 100644 --- a/test/single_file/floats.cc.expected +++ b/test/single_file/floats.cc.expected @@ -42,85 +42,109 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Assign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 = arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float& __dredd_replace_binary_operator_SubAssign_arg1_float_arg2_double(float& arg1, double 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; - return arg1 -= arg2; + MUTATION_PRELUDE(arg1 -= arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + return MUTATION_RETURN(arg1 -= arg2); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double& __dredd_replace_binary_operator_AddAssign_arg1_double_arg2_double(double& arg1, double 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; - return arg1 += arg2; + MUTATION_PRELUDE(arg1 += arg2); + REPLACE_BINARY_Assign(0); + REPLACE_BINARY_DivAssign(1); + REPLACE_BINARY_MulAssign(2); + REPLACE_BINARY_SubAssign(3); + return MUTATION_RETURN(arg1 += arg2); } static double __dredd_replace_expr_double_one(double arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0.0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FLOAT_ZERO(0); + REPLACE_EXPR_FLOAT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double_lvalue(double& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Mul_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 * arg2; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 * arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/floats.cc.noopt.expected b/test/single_file/floats.cc.noopt.expected index 45dd2aca..bdbd8ffb 100644 --- a/test/single_file/floats.cc.noopt.expected +++ b/test/single_file/floats.cc.noopt.expected @@ -42,78 +42,102 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Assign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 = arg2 +#define REPLACE_BINARY_AddAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float& __dredd_replace_binary_operator_SubAssign_arg1_float_arg2_double(float& arg1, double 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; - return arg1 -= arg2; + MUTATION_PRELUDE(arg1 -= arg2); + REPLACE_BINARY_AddAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + return MUTATION_RETURN(arg1 -= arg2); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double& __dredd_replace_binary_operator_AddAssign_arg1_double_arg2_double(double& arg1, double 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; - return arg1 += arg2; + MUTATION_PRELUDE(arg1 += arg2); + REPLACE_BINARY_Assign(0); + REPLACE_BINARY_DivAssign(1); + REPLACE_BINARY_MulAssign(2); + REPLACE_BINARY_SubAssign(3); + return MUTATION_RETURN(arg1 += arg2); } static double __dredd_replace_expr_double_lvalue(double& 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_binary_operator_Mul_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 * arg2; + MUTATION_PRELUDE(arg1 * arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 * arg2); } static double __dredd_replace_binary_operator_Add_arg1_double_arg2_double(double arg1, double 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2; - return arg1 + arg2; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Sub(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2(4); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/initializer.c.expected b/test/single_file/initializer.c.expected index a853cdb3..340993aa 100644 --- a/test/single_file/initializer.c.expected +++ b/test/single_file/initializer.c.expected @@ -40,33 +40,49 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo(int a, int b) { diff --git a/test/single_file/initializer.c.noopt.expected b/test/single_file/initializer.c.noopt.expected index a853cdb3..340993aa 100644 --- a/test/single_file/initializer.c.noopt.expected +++ b/test/single_file/initializer.c.noopt.expected @@ -40,33 +40,49 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo(int a, int b) { diff --git a/test/single_file/initializer.cc.expected b/test/single_file/initializer.cc.expected index 15a47d8c..6b47adb1 100644 --- a/test/single_file/initializer.cc.expected +++ b/test/single_file/initializer.cc.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo(int a, int b) { diff --git a/test/single_file/initializer.cc.noopt.expected b/test/single_file/initializer.cc.noopt.expected index 15a47d8c..6b47adb1 100644 --- a/test/single_file/initializer.cc.noopt.expected +++ b/test/single_file/initializer.cc.noopt.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo(int a, int b) { diff --git a/test/single_file/initializer_list.cc.expected b/test/single_file/initializer_list.cc.expected index 8332313d..8adc3c46 100644 --- a/test/single_file/initializer_list.cc.expected +++ b/test/single_file/initializer_list.cc.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #include struct A { diff --git a/test/single_file/initializer_list.cc.noopt.expected b/test/single_file/initializer_list.cc.noopt.expected index 347e9339..ee68897b 100644 --- a/test/single_file/initializer_list.cc.noopt.expected +++ b/test/single_file/initializer_list.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } #include diff --git a/test/single_file/lambda_capture.cc.expected b/test/single_file/lambda_capture.cc.expected index ccddbdc6..c531a98e 100644 --- a/test/single_file/lambda_capture.cc.expected +++ b/test/single_file/lambda_capture.cc.expected @@ -42,25 +42,33 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/lambda_capture.cc.noopt.expected b/test/single_file/lambda_capture.cc.noopt.expected index c0ccda83..005fafc2 100644 --- a/test/single_file/lambda_capture.cc.noopt.expected +++ b/test/single_file/lambda_capture.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/left_shift_opt.c.expected b/test/single_file/left_shift_opt.c.expected index 5dadb221..dd8fa6a0 100644 --- a/test/single_file/left_shift_opt.c.expected +++ b/test/single_file/left_shift_opt.c.expected @@ -40,19 +40,25 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/left_shift_opt.c.noopt.expected b/test/single_file/left_shift_opt.c.noopt.expected index 492ddacd..3bcf0b8d 100644 --- a/test/single_file/left_shift_opt.c.noopt.expected +++ b/test/single_file/left_shift_opt.c.noopt.expected @@ -40,23 +40,34 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Shr(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >> arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Shl_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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2; - return arg1 << arg2; + MUTATION_PRELUDE(arg1 << arg2); + REPLACE_BINARY_Shr(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2(2); + return MUTATION_RETURN(arg1 << arg2); } int main() { diff --git a/test/single_file/left_shift_opt.cc.expected b/test/single_file/left_shift_opt.cc.expected index ecc79d9d..f37d7130 100644 --- a/test/single_file/left_shift_opt.cc.expected +++ b/test/single_file/left_shift_opt.cc.expected @@ -42,19 +42,25 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/left_shift_opt.cc.noopt.expected b/test/single_file/left_shift_opt.cc.noopt.expected index 029d9587..993b3913 100644 --- a/test/single_file/left_shift_opt.cc.noopt.expected +++ b/test/single_file/left_shift_opt.cc.noopt.expected @@ -42,23 +42,34 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Shr(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >> arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Shl_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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2; - return arg1 << arg2; + MUTATION_PRELUDE(arg1 << arg2); + REPLACE_BINARY_Shr(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2(2); + return MUTATION_RETURN(arg1 << arg2); } int main() { diff --git a/test/single_file/logical_and.c.expected b/test/single_file/logical_and.c.expected index 9836be0e..4a01108a 100644 --- a/test/single_file/logical_and.c.expected +++ b/test/single_file/logical_and.c.expected @@ -40,22 +40,32 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs(int arg, int local_mutation_id) { diff --git a/test/single_file/logical_and.c.noopt.expected b/test/single_file/logical_and.c.noopt.expected index 9836be0e..4a01108a 100644 --- a/test/single_file/logical_and.c.noopt.expected +++ b/test/single_file/logical_and.c.noopt.expected @@ -40,22 +40,32 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LAnd_arg1_int_arg2_int_rhs(int arg, int local_mutation_id) { diff --git a/test/single_file/logical_and.cc.expected b/test/single_file/logical_and.cc.expected index 1e8e0933..ee820ea3 100644 --- a/test/single_file/logical_and.cc.expected +++ b/test/single_file/logical_and.cc.expected @@ -42,45 +42,60 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_EQ_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_before_logical_operator_argument(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + REPLACE_EXPR_FALSE(1); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_EQ_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 && arg2()); } int foo(int a, int b) { diff --git a/test/single_file/logical_and.cc.noopt.expected b/test/single_file/logical_and.cc.noopt.expected index cdcd4fca..0b8cd2ad 100644 --- a/test/single_file/logical_and.cc.noopt.expected +++ b/test/single_file/logical_and.cc.noopt.expected @@ -42,40 +42,57 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_NE_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 != arg2() +#define REPLACE_BINARY_LOr_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 || arg2() +#define REPLACE_BINARY_EQ_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_LOr_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 && arg2()); } int foo(int a, int b) { diff --git a/test/single_file/logical_and_div.cc.expected b/test/single_file/logical_and_div.cc.expected index 6056bdff..037f3526 100644 --- a/test/single_file/logical_and_div.cc.expected +++ b/test/single_file/logical_and_div.cc.expected @@ -42,68 +42,90 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_LT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 < arg2 +#define REPLACE_BINARY_GT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 > arg2 +#define REPLACE_BINARY_EQ_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2() +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Div_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; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 / arg2); } static bool __dredd_replace_expr_bool_omit_false(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_before_logical_operator_argument(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + REPLACE_EXPR_FALSE(1); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_NE_arg1_int_arg2_int_rhs_zero(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; - return arg1 != arg2; + MUTATION_PRELUDE(arg1 != arg2); + REPLACE_BINARY_GT(0); + REPLACE_BINARY_LT(1); + return MUTATION_RETURN(arg1 != arg2); } static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_EQ_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 && arg2()); } int foo(int a, int b) { diff --git a/test/single_file/logical_and_div.cc.noopt.expected b/test/single_file/logical_and_div.cc.noopt.expected index ddfb4201..a515d7e1 100644 --- a/test/single_file/logical_and_div.cc.noopt.expected +++ b/test/single_file/logical_and_div.cc.noopt.expected @@ -42,63 +42,90 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_NE_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 != arg2() +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_LT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 < arg2 +#define REPLACE_BINARY_LOr_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 || arg2() +#define REPLACE_BINARY_LE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <= arg2 +#define REPLACE_BINARY_GT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 > arg2 +#define REPLACE_BINARY_GE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >= arg2 +#define REPLACE_BINARY_EQ_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2() +#define REPLACE_BINARY_EQ(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Div_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; + MUTATION_PRELUDE(arg1 / arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 / arg2); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_NE_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 != arg2; + MUTATION_PRELUDE(arg1 != arg2); + REPLACE_BINARY_EQ(0); + REPLACE_BINARY_GE(1); + REPLACE_BINARY_GT(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 != arg2); } static bool __dredd_replace_binary_operator_LAnd_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 && arg2(); + MUTATION_PRELUDE(arg1 && arg2()); + REPLACE_BINARY_LOr_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 && arg2()); } int foo(int a, int b) { diff --git a/test/single_file/logical_or.c.expected b/test/single_file/logical_or.c.expected index bb39398f..86c30a8d 100644 --- a/test/single_file/logical_or.c.expected +++ b/test/single_file/logical_or.c.expected @@ -40,22 +40,32 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LOr_arg1_int_arg2_int_rhs(int arg, int local_mutation_id) { diff --git a/test/single_file/logical_or.c.noopt.expected b/test/single_file/logical_or.c.noopt.expected index bb39398f..86c30a8d 100644 --- a/test/single_file/logical_or.c.noopt.expected +++ b/test/single_file/logical_or.c.noopt.expected @@ -40,22 +40,32 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_LOr_arg1_int_arg2_int_rhs(int arg, int local_mutation_id) { diff --git a/test/single_file/logical_or.cc.expected b/test/single_file/logical_or.cc.expected index 32ad83f1..2790f5b2 100644 --- a/test/single_file/logical_or.cc.expected +++ b/test/single_file/logical_or.cc.expected @@ -42,45 +42,60 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_NE_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 != arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_before_logical_operator_argument(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + REPLACE_EXPR_FALSE(1); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_LOr_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return arg2(); - return arg1 || arg2(); + MUTATION_PRELUDE(arg1 || arg2()); + REPLACE_BINARY_NE_RHS_EVALUATED(0); + REPLACE_BINARY_ARG1(1); + REPLACE_BINARY_ARG2_EVALUATED(2); + return MUTATION_RETURN(arg1 || arg2()); } int foo(int a, int b) { diff --git a/test/single_file/logical_or.cc.noopt.expected b/test/single_file/logical_or.cc.noopt.expected index a7bf76df..12211e58 100644 --- a/test/single_file/logical_or.cc.noopt.expected +++ b/test/single_file/logical_or.cc.noopt.expected @@ -42,40 +42,57 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_NE_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 != arg2() +#define REPLACE_BINARY_LAnd_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 && arg2() +#define REPLACE_BINARY_EQ_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 == arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_LOr_arg1_bool_arg2_bool(bool arg1, std::function 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; - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg2(); - return arg1 || arg2(); + MUTATION_PRELUDE(arg1 || arg2()); + REPLACE_BINARY_LAnd_RHS_EVALUATED(0); + REPLACE_BINARY_EQ_RHS_EVALUATED(1); + REPLACE_BINARY_NE_RHS_EVALUATED(2); + REPLACE_BINARY_ARG1(3); + REPLACE_BINARY_ARG2_EVALUATED(4); + return MUTATION_RETURN(arg1 || arg2()); } int foo(int a, int b) { diff --git a/test/single_file/misc002.cc.expected b/test/single_file/misc002.cc.expected index dbe249be..f6909095 100644 --- a/test/single_file/misc002.cc.expected +++ b/test/single_file/misc002.cc.expected @@ -42,26 +42,35 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_LE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <= arg2 +#define REPLACE_BINARY_GE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >= arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_false_omit_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - return arg; + MUTATION_PRELUDE(arg); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_EQ_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; - return arg1 == arg2; + MUTATION_PRELUDE(arg1 == arg2); + REPLACE_BINARY_GE(0); + REPLACE_BINARY_LE(1); + return MUTATION_RETURN(arg1 == arg2); } void f() { diff --git a/test/single_file/misc002.cc.noopt.expected b/test/single_file/misc002.cc.noopt.expected index dd337caa..fa486984 100644 --- a/test/single_file/misc002.cc.noopt.expected +++ b/test/single_file/misc002.cc.noopt.expected @@ -42,35 +42,52 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_BINARY_NE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 != arg2 +#define REPLACE_BINARY_LT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 < arg2 +#define REPLACE_BINARY_LE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <= arg2 +#define REPLACE_BINARY_GT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 > arg2 +#define REPLACE_BINARY_GE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >= arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } static bool __dredd_replace_binary_operator_EQ_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 < arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg2; - return arg1 == arg2; + MUTATION_PRELUDE(arg1 == arg2); + REPLACE_BINARY_NE(0); + REPLACE_BINARY_GE(1); + REPLACE_BINARY_GT(2); + REPLACE_BINARY_LE(3); + REPLACE_BINARY_LT(4); + REPLACE_BINARY_ARG1(5); + REPLACE_BINARY_ARG2(6); + return MUTATION_RETURN(arg1 == arg2); } void f() { diff --git a/test/single_file/misc003.cc.expected b/test/single_file/misc003.cc.expected index 0ab51208..d59b1ed5 100644 --- a/test/single_file/misc003.cc.expected +++ b/test/single_file/misc003.cc.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg void f(){ if (!__dredd_enabled_mutation(0)) { try { } catch (...) { diff --git a/test/single_file/misc003.cc.noopt.expected b/test/single_file/misc003.cc.noopt.expected index 0ab51208..d59b1ed5 100644 --- a/test/single_file/misc003.cc.noopt.expected +++ b/test/single_file/misc003.cc.noopt.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg void f(){ if (!__dredd_enabled_mutation(0)) { try { } catch (...) { diff --git a/test/single_file/negative_switch_case.c.expected b/test/single_file/negative_switch_case.c.expected index 2dbed313..6a83923c 100644 --- a/test/single_file/negative_switch_case.c.expected +++ b/test/single_file/negative_switch_case.c.expected @@ -40,11 +40,15 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/negative_switch_case.c.noopt.expected b/test/single_file/negative_switch_case.c.noopt.expected index 6497468f..1169e40b 100644 --- a/test/single_file/negative_switch_case.c.noopt.expected +++ b/test/single_file/negative_switch_case.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/negative_switch_case.cc.expected b/test/single_file/negative_switch_case.cc.expected index 8437eaf0..79d9c72c 100644 --- a/test/single_file/negative_switch_case.cc.expected +++ b/test/single_file/negative_switch_case.cc.expected @@ -42,11 +42,15 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/negative_switch_case.cc.noopt.expected b/test/single_file/negative_switch_case.cc.noopt.expected index 020bc5b2..9065505e 100644 --- a/test/single_file/negative_switch_case.cc.noopt.expected +++ b/test/single_file/negative_switch_case.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/non_const_sized_array.c.expected b/test/single_file/non_const_sized_array.c.expected index 747447ad..645affce 100644 --- a/test/single_file/non_const_sized_array.c.expected +++ b/test/single_file/non_const_sized_array.c.expected @@ -40,43 +40,59 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_volatile_int_lvalue(volatile 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo() { diff --git a/test/single_file/non_const_sized_array.c.noopt.expected b/test/single_file/non_const_sized_array.c.noopt.expected index baf9468d..81ca97ca 100644 --- a/test/single_file/non_const_sized_array.c.noopt.expected +++ b/test/single_file/non_const_sized_array.c.noopt.expected @@ -40,33 +40,49 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_volatile_int_lvalue(volatile 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo() { diff --git a/test/single_file/non_const_sized_array.cc.expected b/test/single_file/non_const_sized_array.cc.expected index 37ea65b9..3cf08ea6 100644 --- a/test/single_file/non_const_sized_array.cc.expected +++ b/test/single_file/non_const_sized_array.cc.expected @@ -42,14 +42,21 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/non_const_sized_array.cc.noopt.expected b/test/single_file/non_const_sized_array.cc.noopt.expected index 1b533828..4113cb11 100644 --- a/test/single_file/non_const_sized_array.cc.noopt.expected +++ b/test/single_file/non_const_sized_array.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/parens.cc.expected b/test/single_file/parens.cc.expected index bea763fc..6d06839c 100644 --- a/test/single_file/parens.cc.expected +++ b/test/single_file/parens.cc.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int foo(int x) { diff --git a/test/single_file/parens.cc.noopt.expected b/test/single_file/parens.cc.noopt.expected index 9c631225..95ae9712 100644 --- a/test/single_file/parens.cc.noopt.expected +++ b/test/single_file/parens.cc.noopt.expected @@ -42,22 +42,32 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int foo(int x) { diff --git a/test/single_file/positive_int_as_minus_one.c.expected b/test/single_file/positive_int_as_minus_one.c.expected index 998c80b6..b4c56999 100644 --- a/test/single_file/positive_int_as_minus_one.c.expected +++ b/test/single_file/positive_int_as_minus_one.c.expected @@ -40,50 +40,66 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static unsigned int __dredd_replace_expr_unsigned_int_constant(unsigned 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_ONE(2); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Sub_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Mul(2); + REPLACE_BINARY_Rem(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 - arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/positive_int_as_minus_one.c.noopt.expected b/test/single_file/positive_int_as_minus_one.c.noopt.expected index 5592c185..522c60f4 100644 --- a/test/single_file/positive_int_as_minus_one.c.noopt.expected +++ b/test/single_file/positive_int_as_minus_one.c.noopt.expected @@ -40,53 +40,69 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Sub_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Mul(2); + REPLACE_BINARY_Rem(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 - arg2); } static long __dredd_replace_expr_long(long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/positive_int_as_minus_one.cc.expected b/test/single_file/positive_int_as_minus_one.cc.expected index 87f82209..a1eb3038 100644 --- a/test/single_file/positive_int_as_minus_one.cc.expected +++ b/test/single_file/positive_int_as_minus_one.cc.expected @@ -42,50 +42,66 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int_constant(unsigned 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_ONE(2); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Sub_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Mul(2); + REPLACE_BINARY_Rem(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 - arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/positive_int_as_minus_one.cc.noopt.expected b/test/single_file/positive_int_as_minus_one.cc.noopt.expected index 2f317c00..9aefee6c 100644 --- a/test/single_file/positive_int_as_minus_one.cc.noopt.expected +++ b/test/single_file/positive_int_as_minus_one.cc.noopt.expected @@ -42,53 +42,69 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_Add(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 + arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_lvalue(unsigned 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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_binary_operator_Sub_arg1_unsigned_int_arg2_unsigned_int(unsigned int arg1, unsigned 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; + MUTATION_PRELUDE(arg1 - arg2); + REPLACE_BINARY_Add(0); + REPLACE_BINARY_Div(1); + REPLACE_BINARY_Mul(2); + REPLACE_BINARY_Rem(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 - arg2); } static long __dredd_replace_expr_long(long 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/post_inc_volatile.c.expected b/test/single_file/post_inc_volatile.c.expected index 81ceb330..d0947af0 100644 --- a/test/single_file/post_inc_volatile.c.expected +++ b/test/single_file/post_inc_volatile.c.expected @@ -40,68 +40,99 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)-- +#define REPLACE_UNARY_Not_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(*arg) +#define REPLACE_UNARY_Minus_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(*arg) +#define REPLACE_UNARY_LNot_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(*arg) +#define REPLACE_UNARY_ARG_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_PostInc_volatile_int(volatile 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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)++); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/post_inc_volatile.c.noopt.expected b/test/single_file/post_inc_volatile.c.noopt.expected index 7c5aa4ec..885af8a7 100644 --- a/test/single_file/post_inc_volatile.c.noopt.expected +++ b/test/single_file/post_inc_volatile.c.noopt.expected @@ -40,58 +40,89 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)-- +#define REPLACE_UNARY_Not_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(*arg) +#define REPLACE_UNARY_Minus_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(*arg) +#define REPLACE_UNARY_LNot_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(*arg) +#define REPLACE_UNARY_ARG_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_PostInc_volatile_int(volatile 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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)++); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } 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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } int main() { diff --git a/test/single_file/post_inc_volatile.cc.expected b/test/single_file/post_inc_volatile.cc.expected index cb3ea5cb..f5549faf 100644 --- a/test/single_file/post_inc_volatile.cc.expected +++ b/test/single_file/post_inc_volatile.cc.expected @@ -42,79 +42,113 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_Sub_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() - arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_Rem_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() % arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_Mul_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() * arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_Div_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() / arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } static int __dredd_replace_unary_operator_PostInc_volatile_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(std::function arg1, std::function 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(); + MUTATION_PRELUDE(arg1() + arg2()); + REPLACE_BINARY_Div_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_Mul_LHS_EVALUATED_RHS_EVALUATED(1); + REPLACE_BINARY_Rem_LHS_EVALUATED_RHS_EVALUATED(2); + REPLACE_BINARY_Sub_LHS_EVALUATED_RHS_EVALUATED(3); + REPLACE_BINARY_ARG1_EVALUATED(4); + REPLACE_BINARY_ARG2_EVALUATED(5); + return MUTATION_RETURN(arg1() + arg2()); } int main() { diff --git a/test/single_file/post_inc_volatile.cc.noopt.expected b/test/single_file/post_inc_volatile.cc.noopt.expected index 78befc8d..9eefa26f 100644 --- a/test/single_file/post_inc_volatile.cc.noopt.expected +++ b/test/single_file/post_inc_volatile.cc.noopt.expected @@ -42,69 +42,103 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_Sub_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() - arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_Rem_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() % arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_Mul_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() * arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_Div_LHS_EVALUATED_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() / arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define REPLACE_BINARY_ARG2_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2() +#define REPLACE_BINARY_ARG1_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } static int __dredd_replace_unary_operator_PostInc_volatile_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Add_arg1_int_arg2_int(std::function arg1, std::function 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(); + MUTATION_PRELUDE(arg1() + arg2()); + REPLACE_BINARY_Div_LHS_EVALUATED_RHS_EVALUATED(0); + REPLACE_BINARY_Mul_LHS_EVALUATED_RHS_EVALUATED(1); + REPLACE_BINARY_Rem_LHS_EVALUATED_RHS_EVALUATED(2); + REPLACE_BINARY_Sub_LHS_EVALUATED_RHS_EVALUATED(3); + REPLACE_BINARY_ARG1_EVALUATED(4); + REPLACE_BINARY_ARG2_EVALUATED(5); + return MUTATION_RETURN(arg1() + arg2()); } int main() { diff --git a/test/single_file/pre_dec_assign.cc.expected b/test/single_file/pre_dec_assign.cc.expected index 39a11fef..dc972ba2 100644 --- a/test/single_file/pre_dec_assign.cc.expected +++ b/test/single_file/pre_dec_assign.cc.expected @@ -42,76 +42,98 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_unary_operator_PreDec_volatile_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static volatile int& __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(std::function 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() |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1() %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1() <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1() >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1() -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1() ^= arg2; - return arg1() = arg2; + MUTATION_PRELUDE(arg1() = arg2); + REPLACE_BINARY_AddAssign_LHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_LHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_LHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_LHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_LHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_LHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_LHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_LHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_LHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_LHS_EVALUATED(9); + return MUTATION_RETURN(arg1() = arg2); } static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(std::function 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() |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1() %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1() <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1() >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1() -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1() ^= arg2; - return arg1() = arg2; + MUTATION_PRELUDE(arg1() = arg2); + REPLACE_BINARY_AddAssign_LHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_LHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_LHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_LHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_LHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_LHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_LHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_LHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_LHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_LHS_EVALUATED(9); + return MUTATION_RETURN(arg1() = arg2); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/pre_dec_assign.cc.noopt.expected b/test/single_file/pre_dec_assign.cc.noopt.expected index 07d7dc60..9739d9cc 100644 --- a/test/single_file/pre_dec_assign.cc.noopt.expected +++ b/test/single_file/pre_dec_assign.cc.noopt.expected @@ -42,66 +42,88 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_XorAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() &= arg2 +#define REPLACE_BINARY_AddAssign_LHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1() += arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_unary_operator_PreDec_volatile_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static volatile int& __dredd_replace_binary_operator_Assign_arg1_volatile_int_arg2_int(std::function 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() |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1() %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1() <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1() >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1() -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1() ^= arg2; - return arg1() = arg2; + MUTATION_PRELUDE(arg1() = arg2); + REPLACE_BINARY_AddAssign_LHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_LHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_LHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_LHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_LHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_LHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_LHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_LHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_LHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_LHS_EVALUATED(9); + return MUTATION_RETURN(arg1() = arg2); } static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(std::function 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() |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1() %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1() <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1() >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1() -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1() ^= arg2; - return arg1() = arg2; + MUTATION_PRELUDE(arg1() = arg2); + REPLACE_BINARY_AddAssign_LHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_LHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_LHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_LHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_LHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_LHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_LHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_LHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_LHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_LHS_EVALUATED(9); + return MUTATION_RETURN(arg1() = arg2); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/preprocessor_if.c.expected b/test/single_file/preprocessor_if.c.expected index 0a8dd9e1..074eac30 100644 --- a/test/single_file/preprocessor_if.c.expected +++ b/test/single_file/preprocessor_if.c.expected @@ -40,38 +40,59 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_Xor(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^ arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_And(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 & arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Or_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; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return arg2; - return arg1 | arg2; + MUTATION_PRELUDE(arg1 | arg2); + REPLACE_BINARY_And(0); + REPLACE_BINARY_Xor(1); + REPLACE_BINARY_ARG1(2); + REPLACE_BINARY_ARG2(3); + return MUTATION_RETURN(arg1 | arg2); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/preprocessor_if.c.noopt.expected b/test/single_file/preprocessor_if.c.noopt.expected index 4528ef9d..30d98c1e 100644 --- a/test/single_file/preprocessor_if.c.noopt.expected +++ b/test/single_file/preprocessor_if.c.noopt.expected @@ -40,39 +40,61 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_Xor(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^ arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define REPLACE_BINARY_And(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 & arg2 +#define REPLACE_BINARY_AddAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) += arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_Or_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; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return arg2; - return arg1 | arg2; + MUTATION_PRELUDE(arg1 | arg2); + REPLACE_BINARY_And(0); + REPLACE_BINARY_Xor(1); + REPLACE_BINARY_ARG1(2); + REPLACE_BINARY_ARG2(3); + return MUTATION_RETURN(arg1 | arg2); } static int __dredd_replace_binary_operator_Assign_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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) = arg2; + MUTATION_PRELUDE((*arg1) = arg2); + REPLACE_BINARY_AddAssign_LHS_POINTER(0); + REPLACE_BINARY_AndAssign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) = arg2); } int main() { diff --git a/test/single_file/printing.c.expected b/test/single_file/printing.c.expected index 554ba5c4..680ebc01 100644 --- a/test/single_file/printing.c.expected +++ b/test/single_file/printing.c.expected @@ -40,6 +40,8 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #include int main() { diff --git a/test/single_file/printing.c.noopt.expected b/test/single_file/printing.c.noopt.expected index 67c226ba..9af0434a 100644 --- a/test/single_file/printing.c.noopt.expected +++ b/test/single_file/printing.c.noopt.expected @@ -40,15 +40,23 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } #include diff --git a/test/single_file/printing.cc.expected b/test/single_file/printing.cc.expected index 55dd46db..cc6be45f 100644 --- a/test/single_file/printing.cc.expected +++ b/test/single_file/printing.cc.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #include int main() { diff --git a/test/single_file/printing.cc.noopt.expected b/test/single_file/printing.cc.noopt.expected index 55dd46db..cc6be45f 100644 --- a/test/single_file/printing.cc.noopt.expected +++ b/test/single_file/printing.cc.noopt.expected @@ -42,6 +42,8 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg #include int main() { diff --git a/test/single_file/signed_int_constants.cc.expected b/test/single_file/signed_int_constants.cc.expected index 55833874..88d7f0ff 100644 --- a/test/single_file/signed_int_constants.cc.expected +++ b/test/single_file/signed_int_constants.cc.expected @@ -42,54 +42,64 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ZERO(0); + REPLACE_EXPR_INT_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo(int a) { diff --git a/test/single_file/signed_int_constants.cc.noopt.expected b/test/single_file/signed_int_constants.cc.noopt.expected index 7fea59d0..490ecd87 100644 --- a/test/single_file/signed_int_constants.cc.noopt.expected +++ b/test/single_file/signed_int_constants.cc.noopt.expected @@ -42,30 +42,43 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo(int a) { diff --git a/test/single_file/sizeof_template.cc.expected b/test/single_file/sizeof_template.cc.expected index 8bfcde8a..277624f0 100644 --- a/test/single_file/sizeof_template.cc.expected +++ b/test/single_file/sizeof_template.cc.expected @@ -42,13 +42,19 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned long __dredd_replace_expr_unsigned_long(unsigned long 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } template void b() { if (!__dredd_enabled_mutation(4)) { a(__dredd_replace_expr_unsigned_long(sizeof(a), 0)); } } diff --git a/test/single_file/sizeof_template.cc.noopt.expected b/test/single_file/sizeof_template.cc.noopt.expected index 8bfcde8a..277624f0 100644 --- a/test/single_file/sizeof_template.cc.noopt.expected +++ b/test/single_file/sizeof_template.cc.noopt.expected @@ -42,13 +42,19 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned long __dredd_replace_expr_unsigned_long(unsigned long 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } template void b() { if (!__dredd_enabled_mutation(4)) { a(__dredd_replace_expr_unsigned_long(sizeof(a), 0)); } } diff --git a/test/single_file/sizeof_template2.cc.expected b/test/single_file/sizeof_template2.cc.expected index 55472d28..5bd61e22 100644 --- a/test/single_file/sizeof_template2.cc.expected +++ b/test/single_file/sizeof_template2.cc.expected @@ -42,23 +42,34 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(std::function 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg()); } bool f(int); diff --git a/test/single_file/sizeof_template2.cc.noopt.expected b/test/single_file/sizeof_template2.cc.noopt.expected index ca636194..89022bfb 100644 --- a/test/single_file/sizeof_template2.cc.noopt.expected +++ b/test/single_file/sizeof_template2.cc.noopt.expected @@ -42,32 +42,43 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned long __dredd_replace_expr_unsigned_long(unsigned long 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(std::function 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg()); } bool f(int); diff --git a/test/single_file/static_initializer.cc.expected b/test/single_file/static_initializer.cc.expected index 3c75e155..a7d4e823 100644 --- a/test/single_file/static_initializer.cc.expected +++ b/test/single_file/static_initializer.cc.expected @@ -42,40 +42,56 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo() { diff --git a/test/single_file/static_initializer.cc.noopt.expected b/test/single_file/static_initializer.cc.noopt.expected index 1c16556c..40b17f80 100644 --- a/test/single_file/static_initializer.cc.noopt.expected +++ b/test/single_file/static_initializer.cc.noopt.expected @@ -42,33 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } void foo() { diff --git a/test/single_file/structured_binding.cc.expected b/test/single_file/structured_binding.cc.expected index 8e6b5975..40c032ae 100644 --- a/test/single_file/structured_binding.cc.expected +++ b/test/single_file/structured_binding.cc.expected @@ -42,64 +42,90 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } static int __dredd_replace_unary_operator_PostInc_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/structured_binding.cc.noopt.expected b/test/single_file/structured_binding.cc.noopt.expected index 03b0b83e..405cceb0 100644 --- a/test/single_file/structured_binding.cc.noopt.expected +++ b/test/single_file/structured_binding.cc.noopt.expected @@ -42,59 +42,87 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } static int __dredd_replace_unary_operator_PostInc_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/template.cc.expected b/test/single_file/template.cc.expected index 409a9120..b0f258cf 100644 --- a/test/single_file/template.cc.expected +++ b/test/single_file/template.cc.expected @@ -42,40 +42,60 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } template diff --git a/test/single_file/template.cc.noopt.expected b/test/single_file/template.cc.noopt.expected index 49f4dcbe..19561ac9 100644 --- a/test/single_file/template.cc.noopt.expected +++ b/test/single_file/template.cc.noopt.expected @@ -42,41 +42,62 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2() +#define REPLACE_BINARY_SubAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2() +#define REPLACE_BINARY_ShrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2() +#define REPLACE_BINARY_ShlAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2() +#define REPLACE_BINARY_RemAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2() +#define REPLACE_BINARY_OrAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2() +#define REPLACE_BINARY_MulAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2() +#define REPLACE_BINARY_DivAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2() +#define REPLACE_BINARY_AndAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2() +#define REPLACE_BINARY_AddAssign_RHS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 += arg2() +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_binary_operator_Assign_arg1_int_arg2_int(int& arg1, std::function 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 |= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2(); - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2(); - return arg1 = arg2(); + MUTATION_PRELUDE(arg1 = arg2()); + REPLACE_BINARY_AddAssign_RHS_EVALUATED(0); + REPLACE_BINARY_AndAssign_RHS_EVALUATED(1); + REPLACE_BINARY_DivAssign_RHS_EVALUATED(2); + REPLACE_BINARY_MulAssign_RHS_EVALUATED(3); + REPLACE_BINARY_OrAssign_RHS_EVALUATED(4); + REPLACE_BINARY_RemAssign_RHS_EVALUATED(5); + REPLACE_BINARY_ShlAssign_RHS_EVALUATED(6); + REPLACE_BINARY_ShrAssign_RHS_EVALUATED(7); + REPLACE_BINARY_SubAssign_RHS_EVALUATED(8); + REPLACE_BINARY_XorAssign_RHS_EVALUATED(9); + return MUTATION_RETURN(arg1 = arg2()); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } template diff --git a/test/single_file/template_instantiation.cc.expected b/test/single_file/template_instantiation.cc.expected index 66f803a4..218bc0b1 100644 --- a/test/single_file/template_instantiation.cc.expected +++ b/test/single_file/template_instantiation.cc.expected @@ -42,11 +42,15 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } template void foo() { diff --git a/test/single_file/template_instantiation.cc.noopt.expected b/test/single_file/template_instantiation.cc.noopt.expected index 4793c80c..4a19d9d8 100644 --- a/test/single_file/template_instantiation.cc.noopt.expected +++ b/test/single_file/template_instantiation.cc.noopt.expected @@ -42,15 +42,23 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } template void foo() { diff --git a/test/single_file/typedef.c.noopt.expected b/test/single_file/typedef.c.noopt.expected index 3d2c2b52..7b266716 100644 --- a/test/single_file/typedef.c.noopt.expected +++ b/test/single_file/typedef.c.noopt.expected @@ -40,26 +40,40 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } typedef struct S { diff --git a/test/single_file/typedef.cc.noopt.expected b/test/single_file/typedef.cc.noopt.expected index a573ef77..f9346f8b 100644 --- a/test/single_file/typedef.cc.noopt.expected +++ b/test/single_file/typedef.cc.noopt.expected @@ -42,26 +42,40 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } typedef struct S { diff --git a/test/single_file/unary.c.expected b/test/single_file/unary.c.expected index 487ef4d9..0bb82724 100644 --- a/test/single_file/unary.c.expected +++ b/test/single_file/unary.c.expected @@ -40,124 +40,147 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(*arg) +#define REPLACE_UNARY_PreDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(*arg) +#define REPLACE_UNARY_PostInc_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)++ +#define REPLACE_UNARY_PostDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)-- +#define REPLACE_UNARY_Not_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(*arg) +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(*arg) +#define REPLACE_UNARY_LNot_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(*arg) +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_PreInc_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return ++(*arg); + MUTATION_PRELUDE(++(*arg)); + REPLACE_UNARY_PreDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN(++(*arg)); } static int __dredd_replace_unary_operator_PreDec_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return --(*arg); + MUTATION_PRELUDE(--(*arg)); + REPLACE_UNARY_PreInc_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN(--(*arg)); } static int __dredd_replace_unary_operator_PostInc_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)++); } static int __dredd_replace_unary_operator_PostDec_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)--; + MUTATION_PRELUDE((*arg)--); + REPLACE_UNARY_PostInc_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)--); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float __dredd_replace_unary_operator_PreInc_float(float* 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 (*arg); - return ++(*arg); + MUTATION_PRELUDE(++(*arg)); + REPLACE_UNARY_PreDec_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN(++(*arg)); } static float __dredd_replace_unary_operator_PreDec_float(float* 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 (*arg); - return --(*arg); + MUTATION_PRELUDE(--(*arg)); + REPLACE_UNARY_PreInc_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN(--(*arg)); } static float __dredd_replace_unary_operator_PostInc_float(float* 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 (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN((*arg)++); } static float __dredd_replace_unary_operator_PostDec_float(float* 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 (*arg); - return (*arg)--; + MUTATION_PRELUDE((*arg)--); + REPLACE_UNARY_PostInc_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN((*arg)--); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary.c.noopt.expected b/test/single_file/unary.c.noopt.expected index b9ba2785..5a0d30fe 100644 --- a/test/single_file/unary.c.noopt.expected +++ b/test/single_file/unary.c.noopt.expected @@ -40,124 +40,148 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(*arg) +#define REPLACE_UNARY_PreDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(*arg) +#define REPLACE_UNARY_PostInc_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)++ +#define REPLACE_UNARY_PostDec_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg)-- +#define REPLACE_UNARY_Not_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(*arg) +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(*arg) +#define REPLACE_UNARY_LNot_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(*arg) +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg) +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_PreInc_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return ++(*arg); + MUTATION_PRELUDE(++(*arg)); + REPLACE_UNARY_PreDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN(++(*arg)); } static int __dredd_replace_unary_operator_PreDec_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return --(*arg); + MUTATION_PRELUDE(--(*arg)); + REPLACE_UNARY_PreInc_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN(--(*arg)); } static int __dredd_replace_unary_operator_PostInc_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)++); } static int __dredd_replace_unary_operator_PostDec_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 !(*arg); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return (*arg); - return (*arg)--; + MUTATION_PRELUDE((*arg)--); + REPLACE_UNARY_PostInc_POINTER(0); + REPLACE_UNARY_Not_POINTER(1); + REPLACE_UNARY_Minus_POINTER(2); + REPLACE_UNARY_LNot_POINTER(3); + REPLACE_UNARY_ARG_POINTER(4); + return MUTATION_RETURN((*arg)--); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float __dredd_replace_unary_operator_PreInc_float(float* 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 (*arg); - return ++(*arg); + MUTATION_PRELUDE(++(*arg)); + REPLACE_UNARY_PreDec_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN(++(*arg)); } static float __dredd_replace_unary_operator_PreDec_float(float* 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 (*arg); - return --(*arg); + MUTATION_PRELUDE(--(*arg)); + REPLACE_UNARY_PreInc_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN(--(*arg)); } static float __dredd_replace_unary_operator_PostInc_float(float* 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 (*arg); - return (*arg)++; + MUTATION_PRELUDE((*arg)++); + REPLACE_UNARY_PostDec_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN((*arg)++); } static float __dredd_replace_unary_operator_PostDec_float(float* 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 (*arg); - return (*arg)--; + MUTATION_PRELUDE((*arg)--); + REPLACE_UNARY_PostInc_POINTER(0); + REPLACE_UNARY_Minus_POINTER(1); + REPLACE_UNARY_LNot_POINTER(2); + REPLACE_UNARY_ARG_POINTER(3); + return MUTATION_RETURN((*arg)--); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary.cc.expected b/test/single_file/unary.cc.expected index 37ab5ce2..4a3f91b8 100644 --- a/test/single_file/unary.cc.expected +++ b/test/single_file/unary.cc.expected @@ -42,114 +42,137 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++arg() +#define REPLACE_UNARY_PreDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --arg() +#define REPLACE_UNARY_PostInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()++ +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_unary_operator_PreInc_int(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static int __dredd_replace_unary_operator_PostInc_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } static int __dredd_replace_unary_operator_PostDec_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()--); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float& __dredd_replace_unary_operator_PreInc_float(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } static float& __dredd_replace_unary_operator_PreDec_float(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static float __dredd_replace_unary_operator_PostInc_float(std::function 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 arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Minus_EVALUATED(1); + REPLACE_UNARY_LNot_EVALUATED(2); + REPLACE_UNARY_ARG_EVALUATED(3); + return MUTATION_RETURN(arg()++); } static float __dredd_replace_unary_operator_PostDec_float(std::function 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 arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Minus_EVALUATED(1); + REPLACE_UNARY_LNot_EVALUATED(2); + REPLACE_UNARY_ARG_EVALUATED(3); + return MUTATION_RETURN(arg()--); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary.cc.noopt.expected b/test/single_file/unary.cc.noopt.expected index 0b25de35..2e1f7e3d 100644 --- a/test/single_file/unary.cc.noopt.expected +++ b/test/single_file/unary.cc.noopt.expected @@ -42,134 +42,161 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_PreInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++arg() +#define REPLACE_UNARY_PreDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --arg() +#define REPLACE_UNARY_PostInc_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()++ +#define REPLACE_UNARY_PostDec_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg()-- +#define REPLACE_UNARY_Not_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg() +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg() +#define REPLACE_UNARY_LNot_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg() +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg() +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg()) +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg()) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT_EVALUATED(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg()) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_FLOAT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0.0 +#define REPLACE_EXPR_FLOAT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1.0 +#define REPLACE_EXPR_FLOAT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1.0 +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int& __dredd_replace_unary_operator_PreInc_int(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } static int& __dredd_replace_unary_operator_PreDec_int(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static int __dredd_replace_unary_operator_PostInc_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()++); } static int __dredd_replace_unary_operator_PostDec_int(std::function 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 !arg(); - if (__dredd_enabled_mutation(local_mutation_id + 4)) return arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Not_EVALUATED(1); + REPLACE_UNARY_Minus_EVALUATED(2); + REPLACE_UNARY_LNot_EVALUATED(3); + REPLACE_UNARY_ARG_EVALUATED(4); + return MUTATION_RETURN(arg()--); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int(std::function 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(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_LNOT_EVALUATED(0); + REPLACE_EXPR_NOT_EVALUATED(1); + REPLACE_EXPR_MINUS_EVALUATED(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg()); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static float& __dredd_replace_unary_operator_PreInc_float(std::function 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(); - return ++arg(); + MUTATION_PRELUDE(++arg()); + REPLACE_UNARY_PreDec_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(++arg()); } static float& __dredd_replace_unary_operator_PreDec_float(std::function 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(); - return --arg(); + MUTATION_PRELUDE(--arg()); + REPLACE_UNARY_PreInc_EVALUATED(0); + REPLACE_UNARY_ARG_EVALUATED(1); + return MUTATION_RETURN(--arg()); } static float __dredd_replace_unary_operator_PostInc_float(std::function 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 arg(); - return arg()++; + MUTATION_PRELUDE(arg()++); + REPLACE_UNARY_PostDec_EVALUATED(0); + REPLACE_UNARY_Minus_EVALUATED(1); + REPLACE_UNARY_LNot_EVALUATED(2); + REPLACE_UNARY_ARG_EVALUATED(3); + return MUTATION_RETURN(arg()++); } static float __dredd_replace_unary_operator_PostDec_float(std::function 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 arg(); - return arg()--; + MUTATION_PRELUDE(arg()--); + REPLACE_UNARY_PostInc_EVALUATED(0); + REPLACE_UNARY_Minus_EVALUATED(1); + REPLACE_UNARY_LNot_EVALUATED(2); + REPLACE_UNARY_ARG_EVALUATED(3); + return MUTATION_RETURN(arg()--); } static float __dredd_replace_expr_float(std::function 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg(); + MUTATION_PRELUDE(arg()); + REPLACE_EXPR_MINUS_EVALUATED(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg()); } static float __dredd_replace_expr_float(float 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } static double __dredd_replace_expr_double(double 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.0; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 1.0; - if (__dredd_enabled_mutation(local_mutation_id + 3)) return -1.0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_MINUS(0); + REPLACE_EXPR_FLOAT_ZERO(1); + REPLACE_EXPR_FLOAT_ONE(2); + REPLACE_EXPR_FLOAT_MINUS_ONE(3); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_logical_not.c.expected b/test/single_file/unary_logical_not.c.expected index 973de270..2971ab82 100644 --- a/test/single_file/unary_logical_not.c.expected +++ b/test/single_file/unary_logical_not.c.expected @@ -40,36 +40,48 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + return MUTATION_RETURN(!arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 1; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } #include diff --git a/test/single_file/unary_logical_not.c.noopt.expected b/test/single_file/unary_logical_not.c.noopt.expected index 712dbcaf..9e5e4cc1 100644 --- a/test/single_file/unary_logical_not.c.noopt.expected +++ b/test/single_file/unary_logical_not.c.noopt.expected @@ -40,31 +40,44 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(!arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 1; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return 0; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } #include diff --git a/test/single_file/unary_logical_not.cc.expected b/test/single_file/unary_logical_not.cc.expected index 7e67219c..f8d2be1c 100644 --- a/test/single_file/unary_logical_not.cc.expected +++ b/test/single_file/unary_logical_not.cc.expected @@ -42,36 +42,48 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + return MUTATION_RETURN(!arg); } static bool __dredd_replace_expr_bool_true(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_FALSE(0); + return MUTATION_RETURN(arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_logical_not.cc.noopt.expected b/test/single_file/unary_logical_not.cc.noopt.expected index c8517d12..62d826ca 100644 --- a/test/single_file/unary_logical_not.cc.noopt.expected +++ b/test/single_file/unary_logical_not.cc.noopt.expected @@ -42,31 +42,44 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(!arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_minus.c.expected b/test/single_file/unary_minus.c.expected index cc8b7709..96931b1c 100644 --- a/test/single_file/unary_minus.c.expected +++ b/test/single_file/unary_minus.c.expected @@ -40,37 +40,49 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_minus.c.noopt.expected b/test/single_file/unary_minus.c.noopt.expected index 27b9e5d5..f2259afd 100644 --- a/test/single_file/unary_minus.c.noopt.expected +++ b/test/single_file/unary_minus.c.noopt.expected @@ -40,30 +40,43 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++((*arg)) +#define REPLACE_EXPR_DEC_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --((*arg)) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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)); - return (*arg); + MUTATION_PRELUDE((*arg)); + REPLACE_EXPR_INC_POINTER(0); + REPLACE_EXPR_DEC_POINTER(1); + return MUTATION_RETURN((*arg)); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_minus.cc.expected b/test/single_file/unary_minus.cc.expected index 9938245f..a7470fb9 100644 --- a/test/single_file/unary_minus.cc.expected +++ b/test/single_file/unary_minus.cc.expected @@ -42,37 +42,49 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_minus.cc.noopt.expected b/test/single_file/unary_minus.cc.noopt.expected index ef9569ce..b89541e4 100644 --- a/test/single_file/unary_minus.cc.noopt.expected +++ b/test/single_file/unary_minus.cc.noopt.expected @@ -42,30 +42,43 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_INC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ++(arg) +#define REPLACE_EXPR_DEC(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return --(arg) +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } static int __dredd_replace_expr_int_lvalue(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); - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INC(0); + REPLACE_EXPR_DEC(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_operator_opt.c.expected b/test/single_file/unary_operator_opt.c.expected index eab9557e..e919ecf2 100644 --- a/test/single_file/unary_operator_opt.c.expected +++ b/test/single_file/unary_operator_opt.c.expected @@ -40,42 +40,50 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Not_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return ~arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return !arg; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_LNot(0); + return MUTATION_RETURN(~arg); } static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_RETURN(arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_MINUS_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_expr_int_minus_one(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 0; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return 1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ZERO(0); + REPLACE_EXPR_INT_ONE(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unary_operator_opt.c.noopt.expected b/test/single_file/unary_operator_opt.c.noopt.expected index 18696ab5..0e98d461 100644 --- a/test/single_file/unary_operator_opt.c.noopt.expected +++ b/test/single_file/unary_operator_opt.c.noopt.expected @@ -40,31 +40,43 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static int __dredd_replace_unary_operator_Not_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; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_Minus(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(~arg); } static int __dredd_replace_unary_operator_Minus_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; - return -arg; + MUTATION_PRELUDE(-arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(-arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unsigned_int.c.expected b/test/single_file/unsigned_int.c.expected index 617ffc63..316e40a5 100644 --- a/test/single_file/unsigned_int.c.expected +++ b/test/single_file/unsigned_int.c.expected @@ -40,49 +40,59 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_one(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int_constant(unsigned 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_unary_operator_Not_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; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_Minus(0); + REPLACE_UNARY_LNot(1); + return MUTATION_RETURN(~arg); } static int __dredd_replace_unary_operator_LNot_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return !arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~arg; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + return MUTATION_RETURN(!arg); } static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; - if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_INT_ONE(0); + REPLACE_EXPR_INT_MINUS_ONE(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unsigned_int.c.noopt.expected b/test/single_file/unsigned_int.c.noopt.expected index 9c9f3e65..c19b4d3c 100644 --- a/test/single_file/unsigned_int.c.noopt.expected +++ b/test/single_file/unsigned_int.c.noopt.expected @@ -40,40 +40,52 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static int __dredd_replace_unary_operator_Not_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; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_Minus(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(~arg); } static int __dredd_replace_unary_operator_LNot_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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(!arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unsigned_int.cc.expected b/test/single_file/unsigned_int.cc.expected index c3f6bd45..455d95f3 100644 --- a/test/single_file/unsigned_int.cc.expected +++ b/test/single_file/unsigned_int.cc.expected @@ -42,48 +42,59 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int_one(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + return MUTATION_RETURN(arg); } static unsigned int __dredd_replace_expr_unsigned_int_constant(unsigned 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_INT_ZERO(1); + REPLACE_EXPR_INT_ONE(2); + return MUTATION_RETURN(arg); } static int __dredd_replace_unary_operator_Not_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; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_Minus(0); + REPLACE_UNARY_LNot(1); + return MUTATION_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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static bool __dredd_replace_unary_operator_LNot_bool_zero(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return !arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~arg; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + return MUTATION_RETURN(!arg); } static bool __dredd_replace_expr_bool_false(bool arg, int local_mutation_id) { - if (!__dredd_some_mutation_enabled) return arg; - if (__dredd_enabled_mutation(local_mutation_id + 0)) return true; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_TRUE(0); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/unsigned_int.cc.noopt.expected b/test/single_file/unsigned_int.cc.noopt.expected index ccb8608f..b8b305f2 100644 --- a/test/single_file/unsigned_int.cc.noopt.expected +++ b/test/single_file/unsigned_int.cc.noopt.expected @@ -42,48 +42,62 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_UNARY_Not(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~arg +#define REPLACE_UNARY_Minus(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -arg +#define REPLACE_UNARY_LNot(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !arg +#define REPLACE_UNARY_ARG(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg +#define REPLACE_EXPR_TRUE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return true +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_EXPR_FALSE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return false +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static unsigned int __dredd_replace_expr_unsigned_int(unsigned 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; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + return MUTATION_RETURN(arg); } static int __dredd_replace_unary_operator_Not_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; - return ~arg; + MUTATION_PRELUDE(~arg); + REPLACE_UNARY_Minus(0); + REPLACE_UNARY_LNot(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(~arg); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static bool __dredd_replace_unary_operator_LNot_bool(bool 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; - return !arg; + MUTATION_PRELUDE(!arg); + REPLACE_UNARY_Not(0); + REPLACE_UNARY_Minus(1); + REPLACE_UNARY_ARG(2); + return MUTATION_RETURN(!arg); } static bool __dredd_replace_expr_bool(bool 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 true; - if (__dredd_enabled_mutation(local_mutation_id + 2)) return false; - return arg; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_TRUE(1); + REPLACE_EXPR_FALSE(2); + return MUTATION_RETURN(arg); } int main() { diff --git a/test/single_file/using.cc.noopt.expected b/test/single_file/using.cc.noopt.expected index 9de76a94..db222738 100644 --- a/test/single_file/using.cc.noopt.expected +++ b/test/single_file/using.cc.noopt.expected @@ -42,26 +42,40 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_Sub(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 - arg2 +#define REPLACE_BINARY_Rem(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 % arg2 +#define REPLACE_BINARY_Mul(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 * arg2 +#define REPLACE_BINARY_Div(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 / arg2 +#define REPLACE_BINARY_ARG2(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg2 +#define REPLACE_BINARY_ARG1(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_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; + MUTATION_PRELUDE(arg1 + arg2); + REPLACE_BINARY_Div(0); + REPLACE_BINARY_Mul(1); + REPLACE_BINARY_Rem(2); + REPLACE_BINARY_Sub(3); + REPLACE_BINARY_ARG1(4); + REPLACE_BINARY_ARG2(5); + return MUTATION_RETURN(arg1 + arg2); } using blah = int; diff --git a/test/single_file/volatile.c.expected b/test/single_file/volatile.c.expected index ba6f689f..a6c0f9e5 100644 --- a/test/single_file/volatile.c.expected +++ b/test/single_file/volatile.c.expected @@ -40,29 +40,46 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Assign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) = arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_AddAssign_arg1_volatile_int_arg2_int(volatile 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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) += arg2; + MUTATION_PRELUDE((*arg1) += arg2); + REPLACE_BINARY_AndAssign_LHS_POINTER(0); + REPLACE_BINARY_Assign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) += arg2); } void foo() { diff --git a/test/single_file/volatile.c.noopt.expected b/test/single_file/volatile.c.noopt.expected index 9ea19efe..55f2ce63 100644 --- a/test/single_file/volatile.c.noopt.expected +++ b/test/single_file/volatile.c.noopt.expected @@ -40,30 +40,48 @@ static int __dredd_enabled_mutation(int local_mutation_id) { return enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64)); } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) ^= arg2 +#define REPLACE_BINARY_SubAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) -= arg2 +#define REPLACE_BINARY_ShrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) >>= arg2 +#define REPLACE_BINARY_ShlAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) <<= arg2 +#define REPLACE_BINARY_RemAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) %= arg2 +#define REPLACE_BINARY_OrAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) |= arg2 +#define REPLACE_BINARY_MulAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) *= arg2 +#define REPLACE_BINARY_DivAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) /= arg2 +#define REPLACE_BINARY_Assign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) = arg2 +#define REPLACE_BINARY_AndAssign_LHS_POINTER(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return (*arg1) &= arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } static int __dredd_replace_binary_operator_AddAssign_arg1_volatile_int_arg2_int(volatile 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) |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return (*arg1) %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return (*arg1) <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return (*arg1) >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return (*arg1) -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return (*arg1) ^= arg2; - return (*arg1) += arg2; + MUTATION_PRELUDE((*arg1) += arg2); + REPLACE_BINARY_AndAssign_LHS_POINTER(0); + REPLACE_BINARY_Assign_LHS_POINTER(1); + REPLACE_BINARY_DivAssign_LHS_POINTER(2); + REPLACE_BINARY_MulAssign_LHS_POINTER(3); + REPLACE_BINARY_OrAssign_LHS_POINTER(4); + REPLACE_BINARY_RemAssign_LHS_POINTER(5); + REPLACE_BINARY_ShlAssign_LHS_POINTER(6); + REPLACE_BINARY_ShrAssign_LHS_POINTER(7); + REPLACE_BINARY_SubAssign_LHS_POINTER(8); + REPLACE_BINARY_XorAssign_LHS_POINTER(9); + return MUTATION_RETURN((*arg1) += arg2); } void foo() { diff --git a/test/single_file/volatile.cc.expected b/test/single_file/volatile.cc.expected index 4ab4918b..25c6cffb 100644 --- a/test/single_file/volatile.cc.expected +++ b/test/single_file/volatile.cc.expected @@ -42,29 +42,46 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Assign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 = arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_binary_operator_AddAssign_arg1_volatile_int_arg2_int(volatile 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 += arg2; + MUTATION_PRELUDE(arg1 += arg2); + REPLACE_BINARY_AndAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 += arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_NOT(0); + REPLACE_EXPR_MINUS(1); + REPLACE_EXPR_INT_ZERO(2); + REPLACE_EXPR_INT_ONE(3); + REPLACE_EXPR_INT_MINUS_ONE(4); + return MUTATION_RETURN(arg); } void foo() { diff --git a/test/single_file/volatile.cc.noopt.expected b/test/single_file/volatile.cc.noopt.expected index 0ccd0ab1..7672da7d 100644 --- a/test/single_file/volatile.cc.noopt.expected +++ b/test/single_file/volatile.cc.noopt.expected @@ -42,30 +42,48 @@ static bool __dredd_enabled_mutation(int local_mutation_id) { return (enabled_bitset[local_mutation_id / 64] & (1 << (local_mutation_id % 64))) != 0; } +#define MUTATION_RETURN(arg) arg +#define REPLACE_EXPR_NOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return ~(arg) +#define REPLACE_EXPR_MINUS(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -(arg) +#define REPLACE_EXPR_LNOT(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return !(arg) +#define REPLACE_EXPR_INT_ZERO(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 0 +#define REPLACE_EXPR_INT_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return 1 +#define REPLACE_EXPR_INT_MINUS_ONE(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return -1 +#define REPLACE_BINARY_XorAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 ^= arg2 +#define REPLACE_BINARY_SubAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 -= arg2 +#define REPLACE_BINARY_ShrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 >>= arg2 +#define REPLACE_BINARY_ShlAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 <<= arg2 +#define REPLACE_BINARY_RemAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 %= arg2 +#define REPLACE_BINARY_OrAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 |= arg2 +#define REPLACE_BINARY_MulAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 *= arg2 +#define REPLACE_BINARY_DivAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 /= arg2 +#define REPLACE_BINARY_Assign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 = arg2 +#define REPLACE_BINARY_AndAssign(mutation_id_offset) if (__dredd_enabled_mutation(local_mutation_id + mutation_id_offset)) return arg1 &= arg2 +#define MUTATION_PRELUDE(arg) if (!__dredd_some_mutation_enabled) return arg static volatile int& __dredd_replace_binary_operator_AddAssign_arg1_volatile_int_arg2_int(volatile 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 |= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 5)) return arg1 %= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 6)) return arg1 <<= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 7)) return arg1 >>= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 8)) return arg1 -= arg2; - if (__dredd_enabled_mutation(local_mutation_id + 9)) return arg1 ^= arg2; - return arg1 += arg2; + MUTATION_PRELUDE(arg1 += arg2); + REPLACE_BINARY_AndAssign(0); + REPLACE_BINARY_Assign(1); + REPLACE_BINARY_DivAssign(2); + REPLACE_BINARY_MulAssign(3); + REPLACE_BINARY_OrAssign(4); + REPLACE_BINARY_RemAssign(5); + REPLACE_BINARY_ShlAssign(6); + REPLACE_BINARY_ShrAssign(7); + REPLACE_BINARY_SubAssign(8); + REPLACE_BINARY_XorAssign(9); + return MUTATION_RETURN(arg1 += arg2); } 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; + MUTATION_PRELUDE(arg); + REPLACE_EXPR_LNOT(0); + REPLACE_EXPR_NOT(1); + REPLACE_EXPR_MINUS(2); + REPLACE_EXPR_INT_ZERO(3); + REPLACE_EXPR_INT_ONE(4); + REPLACE_EXPR_INT_MINUS_ONE(5); + return MUTATION_RETURN(arg); } void foo() {