├── .github └── workflows │ ├── build.sh │ ├── build.yml │ ├── c_apps.sh │ ├── c_apps.yml │ ├── cxx_apps.sh │ ├── cxx_apps.yml │ ├── dev_build.sh │ ├── dev_build.yml │ ├── release.sh │ └── release.yml ├── .gitignore ├── .gitmodules ├── AUTHORS ├── CMakeLists.txt ├── CONTRIBUTORS ├── LICENSE ├── README.md ├── dev_shell.sh.template ├── examples ├── math │ ├── CMakeLists.txt │ ├── math │ │ ├── CMakeLists.txt │ │ ├── include │ │ │ └── math │ │ │ │ ├── exp.h │ │ │ │ ├── number_theoretic.h │ │ │ │ └── trig.h │ │ └── src │ │ │ ├── exp.cc │ │ │ ├── number_theoretic.cc │ │ │ └── trig.cc │ └── mathtest │ │ ├── CMakeLists.txt │ │ ├── include_private │ │ └── include │ │ │ └── mathtest │ │ │ └── test_funcs.h │ │ └── src │ │ ├── exp_test.cc │ │ ├── number_theoretic_test.cc │ │ ├── test_funcs.cc │ │ └── trig_test.cc ├── simple │ └── pi.cc └── threaded │ ├── CMakeLists.txt │ ├── include │ ├── consumer.h │ ├── locked_queue.h │ └── producer.h │ └── src │ ├── consumer.cc │ ├── locked_queue.cc │ ├── main.cc │ └── producer.cc ├── scripts ├── check_all.sh ├── check_bespoke_tests.sh ├── check_build.sh ├── check_clang_tidy.sh ├── check_clean_build.sh ├── check_cmakelint.sh ├── check_compile_commands.sh ├── check_cppcheck.sh ├── check_cpplint.sh ├── check_execute_tests.sh ├── check_format.sh ├── check_headers.py ├── check_iwyu.sh ├── check_json.py ├── check_one_bespoke_test.py ├── check_one_execute_test.py ├── check_one_single_file_test.sh ├── check_single_file_tests.sh ├── dredd_cc_files.sh ├── dredd_cmake_files.sh ├── dredd_source_files.sh ├── examples_cmake_files.sh ├── examples_source_files.sh ├── fix_format.sh ├── interesting.py.template ├── llvm_tag.sh ├── query_mutant_info.py ├── regenerate_one_single_file_expectation.sh └── regenerate_single_file_expectations.sh ├── src ├── .clang-format ├── .clang-tidy ├── CPPLINT.cfg ├── dredd │ ├── CMakeLists.txt │ ├── include_private │ │ └── include │ │ │ └── dredd │ │ │ ├── log_failed_files_diagnostic_consumer.h │ │ │ └── protobufs │ │ │ └── protobuf_serialization.h │ └── src │ │ ├── log_failed_files_diagnostic_consumer.cc │ │ └── main.cc ├── iwyu.imp ├── libdredd │ ├── CMakeLists.txt │ ├── include │ │ └── libdredd │ │ │ ├── mutation.h │ │ │ ├── mutation_remove_stmt.h │ │ │ ├── mutation_replace_binary_operator.h │ │ │ ├── mutation_replace_expr.h │ │ │ ├── mutation_replace_unary_operator.h │ │ │ ├── new_mutate_frontend_action_factory.h │ │ │ ├── options.h │ │ │ ├── protobufs │ │ │ ├── dredd.proto │ │ │ └── dredd_protobufs.h │ │ │ └── util.h │ ├── include_private │ │ └── include │ │ │ └── libdredd │ │ │ ├── mutate_ast_consumer.h │ │ │ ├── mutate_visitor.h │ │ │ └── mutation_tree_node.h │ └── src │ │ ├── mutate_ast_consumer.cc │ │ ├── mutate_visitor.cc │ │ ├── mutation.cc │ │ ├── mutation_remove_stmt.cc │ │ ├── mutation_replace_binary_operator.cc │ │ ├── mutation_replace_expr.cc │ │ ├── mutation_replace_unary_operator.cc │ │ ├── mutation_tree_node.cc │ │ ├── new_mutate_frontend_action_factory.cc │ │ └── util.cc └── libdreddtest │ ├── .clang-tidy │ ├── CMakeLists.txt │ ├── include_private │ └── include │ │ └── libdreddtest │ │ └── gtest.h │ └── src │ ├── mutation_remove_stmt_test.cc │ ├── mutation_replace_binary_operator_test.cc │ ├── mutation_replace_expr_test.cc │ └── mutation_replace_unary_operator_test.cc ├── temp └── .gitignore ├── test ├── README.md ├── bespoke │ ├── README.md │ ├── mutant_tracking │ │ ├── example.c │ │ └── test.py │ ├── nonexistent-file │ │ └── test.py │ ├── query_mutant_info │ │ └── test.py │ └── skip_bad_files │ │ ├── bad1.c │ │ ├── bad2.c │ │ ├── good1.c │ │ ├── good2.c │ │ └── test.py ├── execute │ ├── README.md │ ├── add │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── bit_overflow_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── bit_overflow_cc │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── constant_function_argument │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── constant_sized_array │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── materialized_temporary_1 │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── materialized_temporary_2 │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── nomutants │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── static_assert_rewrite │ │ ├── harness.cc │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.cc │ ├── switch_cases │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_eq_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_eq_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_ge_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_ge_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_gt_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_gt_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_le_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_le_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_lt_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_lt_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ ├── unsigned_comparison_ne_0_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c │ └── unsigned_comparison_ne_c │ │ ├── harness.c │ │ ├── mutants.txt │ │ ├── original.txt │ │ └── tomutate.c └── single_file │ ├── README.md │ ├── add.c │ ├── add.c.expected │ ├── add.c.noopt.expected │ ├── add.cc │ ├── add.cc.expected │ ├── add.cc.noopt.expected │ ├── add_float.c │ ├── add_float.c.expected │ ├── add_float.c.noopt.expected │ ├── add_float.cc │ ├── add_float.cc.expected │ ├── add_float.cc.noopt.expected │ ├── add_mul.c │ ├── add_mul.c.expected │ ├── add_mul.c.noopt.expected │ ├── add_mul.cc │ ├── add_mul.cc.expected │ ├── add_mul.cc.noopt.expected │ ├── add_type_aliases.c │ ├── add_type_aliases.c.expected │ ├── add_type_aliases.c.noopt.expected │ ├── add_type_aliases.cc │ ├── add_type_aliases.cc.expected │ ├── add_type_aliases.cc.noopt.expected │ ├── adl.cc │ ├── adl.cc.expected │ ├── adl.cc.noopt.expected │ ├── array_with_named_constant_size_rewrite.cc │ ├── array_with_named_constant_size_rewrite.cc.expected │ ├── array_with_named_constant_size_rewrite.cc.noopt.expected │ ├── array_with_named_constant_size_rewrite2.cc │ ├── array_with_named_constant_size_rewrite2.cc.expected │ ├── array_with_named_constant_size_rewrite2.cc.noopt.expected │ ├── assign.c │ ├── assign.c.expected │ ├── assign.c.noopt.expected │ ├── assign.cc │ ├── assign.cc.expected │ ├── assign.cc.noopt.expected │ ├── assign_null.c │ ├── assign_null.c.expected │ ├── assign_null.c.noopt.expected │ ├── assign_null.cc │ ├── assign_null.cc.expected │ ├── assign_null.cc.noopt.expected │ ├── auto.cc │ ├── auto.cc.expected │ ├── auto.cc.noopt.expected │ ├── basic.c │ ├── basic.c.expected │ ├── basic.c.noopt.expected │ ├── basic.cc │ ├── basic.cc.expected │ ├── basic.cc.noopt.expected │ ├── binary_both_zero.cc │ ├── binary_both_zero.cc.expected │ ├── binary_both_zero.cc.noopt.expected │ ├── binary_lhs_zero.cc │ ├── binary_lhs_zero.cc.expected │ ├── binary_lhs_zero.cc.noopt.expected │ ├── binary_long_long_and_long_name_clash.c │ ├── binary_long_long_and_long_name_clash.c.expected │ ├── binary_long_long_and_long_name_clash.c.noopt.expected │ ├── binary_no_arg_replacement.cc │ ├── binary_no_arg_replacement.cc.expected │ ├── binary_no_arg_replacement.cc.noopt.expected │ ├── binary_operands_both_zero.c │ ├── binary_operands_both_zero.c.expected │ ├── binary_operands_both_zero.c.noopt.expected │ ├── binary_operands_both_zero.cc │ ├── binary_operands_both_zero.cc.expected │ ├── binary_operands_both_zero.cc.noopt.expected │ ├── binary_redundant_name_clash.cc │ ├── binary_redundant_name_clash.cc.expected │ ├── binary_redundant_name_clash.cc.noopt.expected │ ├── binary_rhs_zero.cc │ ├── binary_rhs_zero.cc.expected │ ├── binary_rhs_zero.cc.noopt.expected │ ├── bitfield.c │ ├── bitfield.c.expected │ ├── bitfield.c.noopt.expected │ ├── bitfield.cc │ ├── bitfield.cc.expected │ ├── bitfield.cc.noopt.expected │ ├── bitfield_reference_passing.cc │ ├── bitfield_reference_passing.cc.expected │ ├── bitfield_reference_passing.cc.noopt.expected │ ├── bool_assignment.cc │ ├── bool_assignment.cc.expected │ ├── bool_assignment.cc.noopt.expected │ ├── boolean_not_insertion_optimisation.c │ ├── boolean_not_insertion_optimisation.c.expected │ ├── boolean_not_insertion_optimisation.c.noopt.expected │ ├── boolean_not_insertion_optimisation.cc │ ├── boolean_not_insertion_optimisation.cc.expected │ ├── boolean_not_insertion_optimisation.cc.noopt.expected │ ├── braced_initialization.cc │ ├── braced_initialization.cc.expected │ ├── braced_initialization.cc.noopt.expected │ ├── builtin_frame_address.cc │ ├── builtin_frame_address.cc.expected │ ├── builtin_frame_address.cc.noopt.expected │ ├── builtin_frame_address_with_argument_rewrite.cc │ ├── builtin_frame_address_with_argument_rewrite.cc.expected │ ├── builtin_frame_address_with_argument_rewrite.cc.noopt.expected │ ├── comma.c │ ├── comma.c.expected │ ├── comma.c.noopt.expected │ ├── comma_initialization.c │ ├── comma_initialization.c.expected │ ├── comma_initialization.c.noopt.expected │ ├── comma_initialization.cc │ ├── comma_initialization.cc.expected │ ├── comma_initialization.cc.noopt.expected │ ├── comma_side_effects.c │ ├── comma_side_effects.c.expected │ ├── comma_side_effects.c.noopt.expected │ ├── comma_side_effects.cc │ ├── comma_side_effects.cc.expected │ ├── comma_side_effects.cc.noopt.expected │ ├── comment.cc │ ├── comment.cc.expected │ ├── comment.cc.noopt.expected │ ├── comment_at_start_of_file.cc │ ├── comment_at_start_of_file.cc.expected │ ├── comment_at_start_of_file.cc.noopt.expected │ ├── const_expr.cc │ ├── const_expr.cc.expected │ ├── const_expr.cc.noopt.expected │ ├── const_expr_function.cc │ ├── const_expr_function.cc.expected │ ├── const_expr_function.cc.noopt.expected │ ├── const_expr_function_call.cc │ ├── const_expr_function_call.cc.expected │ ├── const_expr_function_call.cc.noopt.expected │ ├── const_init.cc │ ├── const_init.cc.expected │ ├── const_init.cc.noopt.expected │ ├── const_sized_array_int.c │ ├── const_sized_array_int.c.expected │ ├── const_sized_array_int.c.noopt.expected │ ├── const_sized_array_int.cc │ ├── const_sized_array_int.cc.expected │ ├── const_sized_array_int.cc.noopt.expected │ ├── constexpr.cc │ ├── constexpr.cc.expected │ ├── constexpr.cc.noopt.expected │ ├── constexpr_array.cc │ ├── constexpr_array.cc.expected │ ├── constexpr_array.cc.noopt.expected │ ├── constexpr_if1.cc │ ├── constexpr_if1.cc.expected │ ├── constexpr_if1.cc.noopt.expected │ ├── constexpr_if2.cc │ ├── constexpr_if2.cc.expected │ ├── constexpr_if2.cc.noopt.expected │ ├── constexpr_initializer.cc │ ├── constexpr_initializer.cc.expected │ ├── constexpr_initializer.cc.noopt.expected │ ├── construct_struct_from_enum_constant.cc │ ├── construct_struct_from_enum_constant.cc.expected │ ├── construct_struct_from_enum_constant.cc.noopt.expected │ ├── decltype_cast.cc │ ├── decltype_cast.cc.expected │ ├── decltype_cast.cc.noopt.expected │ ├── decltype_cast_function_call.cc │ ├── decltype_cast_function_call.cc.expected │ ├── decltype_cast_function_call.cc.noopt.expected │ ├── default_param.cc │ ├── default_param.cc.expected │ ├── default_param.cc.noopt.expected │ ├── define_at_start_of_file.c │ ├── define_at_start_of_file.c.expected │ ├── define_at_start_of_file.c.noopt.expected │ ├── define_in_first_decl.c │ ├── define_in_first_decl.c.expected │ ├── define_in_first_decl.c.noopt.expected │ ├── define_in_first_decl.cc │ ├── define_in_first_decl.cc.expected │ ├── define_in_first_decl.cc.noopt.expected │ ├── do_not_mutate_under_alignof.cc │ ├── do_not_mutate_under_alignof.cc.expected │ ├── do_not_mutate_under_alignof.cc.noopt.expected │ ├── do_not_mutate_under_sizeof.c │ ├── do_not_mutate_under_sizeof.c.expected │ ├── do_not_mutate_under_sizeof.c.noopt.expected │ ├── dredd_prelude_start.cc │ ├── dredd_prelude_start.cc.expected │ ├── dredd_prelude_start.cc.noopt.expected │ ├── enum.c │ ├── enum.c.expected │ ├── enum.c.noopt.expected │ ├── expr_lvalue.c │ ├── expr_lvalue.c.expected │ ├── expr_lvalue.c.noopt.expected │ ├── expr_lvalue.cc │ ├── expr_lvalue.cc.expected │ ├── expr_lvalue.cc.noopt.expected │ ├── expr_macro.c │ ├── expr_macro.c.expected │ ├── expr_macro.c.noopt.expected │ ├── expr_macro.cc │ ├── expr_macro.cc.expected │ ├── expr_macro.cc.noopt.expected │ ├── float_binary_opts.c │ ├── float_binary_opts.c.expected │ ├── float_binary_opts.c.noopt.expected │ ├── float_binary_opts.cc │ ├── float_binary_opts.cc.expected │ ├── float_binary_opts.cc.noopt.expected │ ├── float_unary_opt.c │ ├── float_unary_opt.c.expected │ ├── float_unary_opt.c.noopt.expected │ ├── float_unary_opt.cc │ ├── float_unary_opt.cc.expected │ ├── float_unary_opt.cc.noopt.expected │ ├── floats.c │ ├── floats.c.expected │ ├── floats.c.noopt.expected │ ├── floats.cc │ ├── floats.cc.expected │ ├── floats.cc.noopt.expected │ ├── initializer.c │ ├── initializer.c.expected │ ├── initializer.c.noopt.expected │ ├── initializer.cc │ ├── initializer.cc.expected │ ├── initializer.cc.noopt.expected │ ├── initializer_list.cc │ ├── initializer_list.cc.expected │ ├── initializer_list.cc.noopt.expected │ ├── initializer_list_long_to_short.cc │ ├── initializer_list_long_to_short.cc.expected │ ├── initializer_list_long_to_short.cc.noopt.expected │ ├── initializer_list_narrower.cc │ ├── initializer_list_narrower.cc.expected │ ├── initializer_list_narrower.cc.noopt.expected │ ├── initializer_list_narrower_nested.cc │ ├── initializer_list_narrower_nested.cc.expected │ ├── initializer_list_narrower_nested.cc.noopt.expected │ ├── initializer_list_parenthesis.cc │ ├── initializer_list_parenthesis.cc.expected │ ├── initializer_list_parenthesis.cc.noopt.expected │ ├── initializer_list_with_templates.cc │ ├── initializer_list_with_templates.cc.expected │ ├── initializer_list_with_templates.cc.noopt.expected │ ├── initializers_outside_functions.cc │ ├── initializers_outside_functions.cc.expected │ ├── initializers_outside_functions.cc.noopt.expected │ ├── lambda_capture.cc │ ├── lambda_capture.cc.expected │ ├── lambda_capture.cc.noopt.expected │ ├── large_summation.c │ ├── large_summation.c.expected │ ├── large_summation.c.noopt.expected │ ├── large_summation.cc │ ├── large_summation.cc.expected │ ├── large_summation.cc.noopt.expected │ ├── left_shift_opt.c │ ├── left_shift_opt.c.expected │ ├── left_shift_opt.c.noopt.expected │ ├── left_shift_opt.cc │ ├── left_shift_opt.cc.expected │ ├── left_shift_opt.cc.noopt.expected │ ├── logical_and.c │ ├── logical_and.c.expected │ ├── logical_and.c.noopt.expected │ ├── logical_and.cc │ ├── logical_and.cc.expected │ ├── logical_and.cc.noopt.expected │ ├── logical_and_div.cc │ ├── logical_and_div.cc.expected │ ├── logical_and_div.cc.noopt.expected │ ├── logical_or.c │ ├── logical_or.c.expected │ ├── logical_or.c.noopt.expected │ ├── logical_or.cc │ ├── logical_or.cc.expected │ ├── logical_or.cc.noopt.expected │ ├── macro_pasting.c │ ├── macro_pasting.c.expected │ ├── macro_pasting.c.noopt.expected │ ├── misc001.cc │ ├── misc001.cc.expected │ ├── misc001.cc.noopt.expected │ ├── misc002.cc │ ├── misc002.cc.expected │ ├── misc002.cc.noopt.expected │ ├── misc003.cc │ ├── misc003.cc.expected │ ├── misc003.cc.noopt.expected │ ├── misc004.cc │ ├── misc004.cc.expected │ ├── misc004.cc.noopt.expected │ ├── negative_switch_case.c │ ├── negative_switch_case.c.expected │ ├── negative_switch_case.c.noopt.expected │ ├── negative_switch_case.cc │ ├── negative_switch_case.cc.expected │ ├── negative_switch_case.cc.noopt.expected │ ├── nested_array_with_named_constant_size_rewrite.cc │ ├── nested_array_with_named_constant_size_rewrite.cc.expected │ ├── nested_array_with_named_constant_size_rewrite.cc.noopt.expected │ ├── new_expr_array_size.cc │ ├── new_expr_array_size.cc.expected │ ├── new_expr_array_size.cc.noopt.expected │ ├── nodiscard.cc │ ├── nodiscard.cc.expected │ ├── nodiscard.cc.noopt.expected │ ├── nodiscard_macro.cc │ ├── nodiscard_macro.cc.expected │ ├── nodiscard_macro.cc.noopt.expected │ ├── noexcept.cc │ ├── noexcept.cc.expected │ ├── noexcept.cc.noopt.expected │ ├── noexcept2.cc │ ├── noexcept2.cc.expected │ ├── noexcept2.cc.noopt.expected │ ├── non_const_sized_array.c │ ├── non_const_sized_array.c.expected │ ├── non_const_sized_array.c.noopt.expected │ ├── non_const_sized_array.cc │ ├── non_const_sized_array.cc.expected │ ├── non_const_sized_array.cc.noopt.expected │ ├── noreturn.cc │ ├── noreturn.cc.expected │ ├── noreturn.cc.noopt.expected │ ├── parens.cc │ ├── parens.cc.expected │ ├── parens.cc.noopt.expected │ ├── positive_int_as_minus_one.c │ ├── positive_int_as_minus_one.c.expected │ ├── positive_int_as_minus_one.c.noopt.expected │ ├── positive_int_as_minus_one.cc │ ├── positive_int_as_minus_one.cc.expected │ ├── positive_int_as_minus_one.cc.noopt.expected │ ├── post_inc_volatile.c │ ├── post_inc_volatile.c.expected │ ├── post_inc_volatile.c.noopt.expected │ ├── post_inc_volatile.cc │ ├── post_inc_volatile.cc.expected │ ├── post_inc_volatile.cc.noopt.expected │ ├── pre_dec_assign.cc │ ├── pre_dec_assign.cc.expected │ ├── pre_dec_assign.cc.noopt.expected │ ├── preprocessor_if.c │ ├── preprocessor_if.c.expected │ ├── preprocessor_if.c.noopt.expected │ ├── printing.c │ ├── printing.c.expected │ ├── printing.c.noopt.expected │ ├── printing.cc │ ├── printing.cc.expected │ ├── printing.cc.noopt.expected │ ├── signed_int_constants.cc │ ├── signed_int_constants.cc.expected │ ├── signed_int_constants.cc.noopt.expected │ ├── sizeof_template.cc │ ├── sizeof_template.cc.expected │ ├── sizeof_template.cc.noopt.expected │ ├── sizeof_template2.cc │ ├── sizeof_template2.cc.expected │ ├── sizeof_template2.cc.noopt.expected │ ├── space_needed_after_macro.c │ ├── space_needed_after_macro.c.expected │ ├── space_needed_after_macro.c.noopt.expected │ ├── space_needed_after_macro2.c │ ├── space_needed_after_macro2.c.expected │ ├── space_needed_after_macro2.c.noopt.expected │ ├── static_assert_rewrite.cc │ ├── static_assert_rewrite.cc.expected │ ├── static_assert_rewrite.cc.noopt.expected │ ├── static_constexpr_array.cc │ ├── static_constexpr_array.cc.expected │ ├── static_constexpr_array.cc.noopt.expected │ ├── static_initializer.c │ ├── static_initializer.c.expected │ ├── static_initializer.c.noopt.expected │ ├── static_initializer.cc │ ├── static_initializer.cc.expected │ ├── static_initializer.cc.noopt.expected │ ├── struct_field_array_constant_size_rewrite.cc │ ├── struct_field_array_constant_size_rewrite.cc.expected │ ├── struct_field_array_constant_size_rewrite.cc.noopt.expected │ ├── structured_binding.cc │ ├── structured_binding.cc.expected │ ├── structured_binding.cc.noopt.expected │ ├── switch_cases1.c │ ├── switch_cases1.c.expected │ ├── switch_cases1.c.noopt.expected │ ├── switch_cases2.c │ ├── switch_cases2.c.expected │ ├── switch_cases2.c.noopt.expected │ ├── template.cc │ ├── template.cc.expected │ ├── template.cc.noopt.expected │ ├── template_instantiation.cc │ ├── template_instantiation.cc.expected │ ├── template_instantiation.cc.noopt.expected │ ├── template_instantiation_const_expr.cc │ ├── template_instantiation_const_expr.cc.expected │ ├── template_instantiation_const_expr.cc.noopt.expected │ ├── template_instantiation_nested_const_expr.cc │ ├── template_instantiation_nested_const_expr.cc.expected │ ├── template_instantiation_nested_const_expr.cc.noopt.expected │ ├── template_instantiation_non_integer_expr.cc │ ├── template_instantiation_non_integer_expr.cc.expected │ ├── template_instantiation_non_integer_expr.cc.noopt.expected │ ├── typedef.c │ ├── typedef.c.expected │ ├── typedef.c.noopt.expected │ ├── typedef.cc │ ├── typedef.cc.expected │ ├── typedef.cc.noopt.expected │ ├── unary.c │ ├── unary.c.expected │ ├── unary.c.noopt.expected │ ├── unary.cc │ ├── unary.cc.expected │ ├── unary.cc.noopt.expected │ ├── unary_logical_not.c │ ├── unary_logical_not.c.expected │ ├── unary_logical_not.c.noopt.expected │ ├── unary_logical_not.cc │ ├── unary_logical_not.cc.expected │ ├── unary_logical_not.cc.noopt.expected │ ├── unary_minus.c │ ├── unary_minus.c.expected │ ├── unary_minus.c.noopt.expected │ ├── unary_minus.cc │ ├── unary_minus.cc.expected │ ├── unary_minus.cc.noopt.expected │ ├── unary_operator_opt.c │ ├── unary_operator_opt.c.expected │ ├── unary_operator_opt.c.noopt.expected │ ├── unsigned_int.c │ ├── unsigned_int.c.expected │ ├── unsigned_int.c.noopt.expected │ ├── unsigned_int.cc │ ├── unsigned_int.cc.expected │ ├── unsigned_int.cc.noopt.expected │ ├── user_defined_literals.cc │ ├── user_defined_literals.cc.expected │ ├── user_defined_literals.cc.noopt.expected │ ├── using.cc │ ├── using.cc.expected │ ├── using.cc.noopt.expected │ ├── vector_returns_temporary.cc │ ├── vector_returns_temporary.cc.expected │ ├── vector_returns_temporary.cc.noopt.expected │ ├── volatile.c │ ├── volatile.c.expected │ ├── volatile.c.noopt.expected │ ├── volatile.cc │ ├── volatile.cc.expected │ └── volatile.cc.noopt.expected └── third_party ├── .gitignore ├── clang+llvm └── .gitignore ├── googletest └── CMakeLists.txt └── protobuf └── CMakeLists.txt /.github/workflows/c_apps.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | on: 17 | pull_request: 18 | branches: 19 | - main 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | os: 27 | - ubuntu-22.04 28 | config: 29 | - Release 30 | 31 | runs-on: ${{ matrix.os }} 32 | env: 33 | OS: ${{ matrix.os }} 34 | CONFIG: ${{ matrix.config }} 35 | steps: 36 | 37 | - name: cancel_previous 38 | uses: styfle/cancel-workflow-action@0.8.0 39 | with: 40 | access_token: ${{ github.token }} 41 | 42 | - name: get_actions 43 | run: | 44 | mkdir -p ./../.github/actions/ 45 | pushd ./../.github/actions/ 46 | git clone https://github.com/actions/setup-python.git 47 | pushd setup-python/ 48 | git checkout v2 49 | popd 50 | git clone https://github.com/actions/checkout.git 51 | pushd checkout/ 52 | git checkout v2 53 | popd 54 | popd 55 | shell: bash 56 | 57 | - name: checkout 58 | uses: ./../.github/actions/checkout 59 | with: 60 | submodules: true 61 | 62 | - name: setup_python 63 | uses: ./../.github/actions/setup-python 64 | with: 65 | python-version: 3.9 66 | architecture: x64 67 | 68 | - name: build_step_nix 69 | run: | 70 | .github/workflows/c_apps.sh 71 | shell: bash 72 | -------------------------------------------------------------------------------- /.github/workflows/cxx_apps.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | on: 17 | pull_request: 18 | branches: 19 | - main 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | os: 27 | - ubuntu-22.04 28 | config: 29 | - Release 30 | 31 | runs-on: ${{ matrix.os }} 32 | env: 33 | OS: ${{ matrix.os }} 34 | CONFIG: ${{ matrix.config }} 35 | steps: 36 | 37 | - name: cancel_previous 38 | uses: styfle/cancel-workflow-action@0.8.0 39 | with: 40 | access_token: ${{ github.token }} 41 | 42 | - name: get_actions 43 | run: | 44 | mkdir -p ./../.github/actions/ 45 | pushd ./../.github/actions/ 46 | git clone https://github.com/actions/setup-python.git 47 | pushd setup-python/ 48 | git checkout v2 49 | popd 50 | git clone https://github.com/actions/checkout.git 51 | pushd checkout/ 52 | git checkout v2 53 | popd 54 | popd 55 | shell: bash 56 | 57 | - name: checkout 58 | uses: ./../.github/actions/checkout 59 | with: 60 | submodules: true 61 | 62 | - name: setup_python 63 | uses: ./../.github/actions/setup-python 64 | with: 65 | python-version: 3.9 66 | architecture: x64 67 | 68 | - name: build_step_nix 69 | run: | 70 | .github/workflows/cxx_apps.sh 71 | shell: bash 72 | -------------------------------------------------------------------------------- /.github/workflows/dev_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -x 18 | set -e 19 | set -u 20 | 21 | 22 | help | head 23 | 24 | uname 25 | 26 | case "$(uname)" in 27 | "Linux") 28 | NINJA_OS="linux" 29 | df -h 30 | sudo swapoff -a 31 | sudo rm -f /swapfile 32 | sudo apt clean 33 | # shellcheck disable=SC2046 34 | docker rmi $(docker image ls -aq) 35 | df -h 36 | ;; 37 | 38 | *) 39 | echo "Unknown OS: only Linux is supported for the dev_build workflow" 40 | exit 1 41 | ;; 42 | esac 43 | 44 | # Get cmake-format and cmake-lint 45 | pip install cmakelang 46 | 47 | export PATH="${HOME}/bin:$PATH" 48 | mkdir -p "${HOME}/bin" 49 | pushd "${HOME}/bin" 50 | # Install ninja. 51 | curl -fsSL -o ninja-build.zip "https://github.com/ninja-build/ninja/releases/download/v1.11.0/ninja-${NINJA_OS}.zip" 52 | unzip ninja-build.zip 53 | ls 54 | popd 55 | 56 | # Install clang. 57 | DREDD_LLVM_TAG=$(./scripts/llvm_tag.sh) 58 | pushd ./third_party/clang+llvm 59 | curl -fsSL -o clang+llvm.tar.xz "https://github.com/llvm/llvm-project/releases/download/llvmorg-${DREDD_LLVM_TAG}/clang+llvm-${DREDD_LLVM_TAG}-x86_64-linux-gnu-ubuntu-22.04.tar.xz" 60 | tar xf clang+llvm.tar.xz 61 | mv clang+llvm-${DREDD_LLVM_TAG}-x86_64-linux-gnu-ubuntu-22.04/* . 62 | rm clang+llvm.tar.xz 63 | popd 64 | 65 | # Source the dev shell to download clang-tidy and other tools. 66 | # Developers should *run* the dev shell, but we want to continue executing this script. 67 | export DREDD_SKIP_BASH=1 68 | 69 | source ./dev_shell.sh.template 70 | 71 | check_all.sh 72 | -------------------------------------------------------------------------------- /.github/workflows/dev_build.yml: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | 16 | on: 17 | pull_request: 18 | branches: 19 | - main 20 | 21 | jobs: 22 | build: 23 | strategy: 24 | fail-fast: false 25 | matrix: 26 | os: 27 | - ubuntu-22.04 28 | config: 29 | - Release 30 | 31 | runs-on: ${{ matrix.os }} 32 | env: 33 | OS: ${{ matrix.os }} 34 | CONFIG: ${{ matrix.config }} 35 | steps: 36 | 37 | - name: cancel_previous 38 | uses: styfle/cancel-workflow-action@0.8.0 39 | with: 40 | access_token: ${{ github.token }} 41 | 42 | - name: get_actions 43 | run: | 44 | mkdir -p ./../.github/actions/ 45 | pushd ./../.github/actions/ 46 | git clone https://github.com/actions/setup-python.git 47 | pushd setup-python/ 48 | git checkout v2 49 | popd 50 | git clone https://github.com/actions/checkout.git 51 | pushd checkout/ 52 | git checkout v2 53 | popd 54 | popd 55 | shell: bash 56 | 57 | - name: checkout 58 | uses: ./../.github/actions/checkout 59 | with: 60 | submodules: true 61 | 62 | - name: setup_python 63 | uses: ./../.github/actions/setup-python 64 | with: 65 | python-version: 3.9 66 | architecture: x64 67 | 68 | - name: build_step_nix 69 | run: | 70 | .github/workflows/dev_build.sh 71 | shell: bash 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # CLion project 2 | cmake-build-* 3 | .idea 4 | 5 | # Backup files 6 | *~ 7 | *.bak 8 | 9 | # Prerequisites 10 | *.d 11 | 12 | # Compiled Object files 13 | *.slo 14 | *.lo 15 | *.o 16 | *.obj 17 | 18 | # Precompiled Headers 19 | *.gch 20 | *.pch 21 | 22 | # Compiled Dynamic libraries 23 | *.so 24 | *.dylib 25 | *.dll 26 | 27 | # Compiled Static libraries 28 | *.lai 29 | *.la 30 | *.a 31 | *.lib 32 | 33 | # Executables 34 | *.exe 35 | *.out 36 | *.app 37 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "third_party/googletest/googletest"] 2 | path = third_party/googletest/googletest 3 | url = https://github.com/google/googletest.git 4 | [submodule "third_party/protobuf/protobuf"] 5 | path = third_party/protobuf/protobuf 6 | url = https://github.com/protocolbuffers/protobuf.git 7 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # This is the official list of The Dredd Project Authors for copyright 2 | # purposes. This file is distinct from the CONTRIBUTORS files. For 3 | # example, Imperial College London employees are listed in 4 | # CONTRIBUTORS but not here, because Imperial College London holds the 5 | # copyright. 6 | 7 | Imperial College London 8 | James Lee-Jones 9 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | # This is the list of contributors of code to the Dredd project 2 | # repository. The AUTHORS file lists the copyright holders; this file 3 | # lists people. For example, Imperial College London employees are 4 | # listed here but not in AUTHORS, because Imperial College London 5 | # holds the copyright. 6 | 7 | Imperial College London 8 | Alastair F. Donaldson 9 | 10 | Independent contributors 11 | James Lee-Jones 12 | -------------------------------------------------------------------------------- /examples/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.13) 16 | 17 | project(math) 18 | 19 | # This can be used to disable the building of tests, which assume that the math 20 | # example is located in a certain place in the Dredd repository. It is useful to 21 | # be able to disable tests for this example so that its source code can be moved 22 | # elsewhere and mutated as part of end-to-end testsing of Dredd. 23 | set(DREDD_EXAMPLES_MATH_BUILD_TESTS 24 | ON 25 | CACHE BOOL "Enable building of tests?") 26 | 27 | add_subdirectory(math) 28 | 29 | if(DREDD_EXAMPLES_MATH_BUILD_TESTS) 30 | set(DREDD_GOOGLETEST_REPO_DIR 31 | "${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest/googletest") 32 | add_subdirectory(mathtest) 33 | add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../../third_party/googletest" 34 | "${CMAKE_CURRENT_BINARY_DIR}/third_party/googletest") 35 | endif() 36 | -------------------------------------------------------------------------------- /examples/math/math/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_library( 16 | math STATIC 17 | include/math/trig.h include/math/exp.h include/math/number_theoretic.h 18 | src/exp.cc src/trig.cc src/number_theoretic.cc) 19 | 20 | target_include_directories(math PUBLIC include) 21 | -------------------------------------------------------------------------------- /examples/math/math/include/math/exp.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MATH_EXP_H 16 | #define MATH_EXP_H 17 | 18 | namespace math { 19 | 20 | double ExpN(const double &x, const int &n); 21 | long double Pow(const double &base, const int &exp); 22 | long double Log2(const int &x); 23 | long double Log(const int &a, const int &b); 24 | 25 | } // namespace math 26 | 27 | #endif // MATH_EXP_H 28 | -------------------------------------------------------------------------------- /examples/math/math/include/math/number_theoretic.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MATH_NUMBERTHEORETIC_H 16 | #define MATH_NUMBERTHEORETIC_H 17 | 18 | namespace math { 19 | 20 | int Ceil(const double &x); 21 | double Mod(const double &x); 22 | long long int Factorial(const int &x); 23 | long long int Comb(const int &n, const int &k); 24 | 25 | } // namespace math 26 | 27 | #endif // MATH_NUMBERTHEORETIC_H 28 | -------------------------------------------------------------------------------- /examples/math/math/include/math/trig.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef MATH_TRIG_H 16 | #define MATH_TRIG_H 17 | 18 | namespace math { 19 | 20 | double SinN(const double &x, const int &n); 21 | double CosN(const double &x, const int &n); 22 | double TanN(const double &x, const int &n); 23 | double SecN(const double &x, const int &n); 24 | double CosecN(const double &x, const int &n); 25 | double CotN(const double &x, const int &n); 26 | 27 | } // namespace math 28 | 29 | #endif // MATH_TRIG_H 30 | -------------------------------------------------------------------------------- /examples/math/math/src/number_theoretic.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "math/number_theoretic.h" 16 | #include 17 | 18 | namespace math { 19 | 20 | /** 21 | * Calculate the ceiling of the input. 22 | * 23 | * @param x the number to apply the ceiling operator to. 24 | * @return x if x is an interger, or the ceiling of x if it is a decimal. 25 | */ 26 | int Ceil(const double &x) { 27 | int y = (int)x; 28 | return (x == y) ? y : y + 1; 29 | } 30 | 31 | /** 32 | * Calculates the absolute value of the input. 33 | * 34 | * @param x the value to take the absolute value of. 35 | * @return x if x is positive or -x if x is negative. 36 | */ 37 | double Mod(const double &x) { return x < 0 ? -x : x; } 38 | 39 | /** 40 | * Calculate the factorial of a number. 41 | * 42 | * @param x the number to take the factorial of. 43 | * @return the factorial of x, equivalent to x! 44 | */ 45 | long long int Factorial(const int &x) { 46 | if (x < 0) 47 | throw std::out_of_range("Can only take factorial of non-negative values."); 48 | 49 | long long int sum = 1; 50 | 51 | for (int i = 2; i <= x; ++i) { 52 | sum *= i; 53 | } 54 | 55 | return sum; 56 | } 57 | 58 | /** 59 | * Calculates n choose k 60 | * 61 | * Calculate the number of ways to choose k items from a sample of n. 62 | * 63 | * @param n the total number of items. 64 | * @param k the sample size. 65 | * @return the number of ways to choose k items from a sample of n. 66 | */ 67 | long long int Comb(const int &n, const int &k) { 68 | if (n < 0 || k < 0) 69 | throw std::out_of_range("n and k must be positive."); 70 | return Factorial(n) / (Factorial(k) * Factorial(n - k)); 71 | } 72 | 73 | } // namespace math -------------------------------------------------------------------------------- /examples/math/mathtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_executable( 16 | mathtest include_private/include/mathtest/test_funcs.h src/test_funcs.cc 17 | src/exp_test.cc src/trig_test.cc src/number_theoretic_test.cc) 18 | target_link_libraries(mathtest PRIVATE math gtest_main) 19 | target_include_directories(mathtest PRIVATE include_private/include) 20 | 21 | add_test(NAME mathtest COMMAND mathtest) 22 | -------------------------------------------------------------------------------- /examples/math/mathtest/include_private/include/mathtest/test_funcs.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License./ 14 | 15 | #ifndef MATHTEST_TEST_FUNCS_H 16 | #define MATHTEST_TEST_FUNCS_H 17 | 18 | #include "gtest/gtest.h" 19 | 20 | namespace math { 21 | namespace math_test { 22 | 23 | ::testing::AssertionResult IsWithin(double val, double correct, 24 | double percentageDifference); 25 | 26 | } // namespace math_test 27 | } // namespace math 28 | 29 | #endif // MATHTEST_TEST_FUNCS_H 30 | -------------------------------------------------------------------------------- /examples/math/mathtest/src/test_funcs.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License./ 14 | 15 | #include "mathtest/test_funcs.h" 16 | #include "gtest/gtest.h" 17 | 18 | namespace math { 19 | namespace math_test { 20 | 21 | ::testing::AssertionResult IsWithin(double val, double correct, 22 | double percentageDifference) { 23 | if (val < 0 && correct < 0) 24 | val *= -1, correct *= -1; 25 | if ((val >= correct * (1 - percentageDifference)) && 26 | (val <= correct * (1 + percentageDifference))) 27 | return ::testing::AssertionSuccess(); 28 | else 29 | return ::testing::AssertionFailure() 30 | << val << " is not within " << percentageDifference * 100 << "% of " 31 | << correct; 32 | } 33 | 34 | } // namespace math_test 35 | } // namespace math -------------------------------------------------------------------------------- /examples/simple/pi.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | 17 | static double CalculatePi() { 18 | double sum = 0.0; 19 | int numerator = -1; 20 | 21 | for (int d = 1; d < 1000000; d += 2) { 22 | numerator *= -1; 23 | sum += numerator / double(d); 24 | } 25 | 26 | return sum * 4; 27 | } 28 | 29 | int main() { std::cout << CalculatePi() << std::endl; } 30 | -------------------------------------------------------------------------------- /examples/threaded/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.13) 16 | 17 | project(threaded) 18 | 19 | add_compile_options(-fsanitize=thread) 20 | add_link_options(-fsanitize=thread) 21 | 22 | add_executable( 23 | threaded 24 | include/consumer.h 25 | include/locked_queue.h 26 | include/producer.h 27 | src/consumer.cc 28 | src/locked_queue.cc 29 | src/main.cc 30 | src/producer.cc) 31 | 32 | target_include_directories(threaded PRIVATE include) 33 | -------------------------------------------------------------------------------- /examples/threaded/include/consumer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef CONSUMER_H_ 16 | #define CONSUMER_H_ 17 | 18 | #include "locked_queue.h" 19 | 20 | #include 21 | 22 | void Consumer(queue::LockedQueue &producer_to_consumers, 23 | queue::LockedQueue &consumers_to_producer, size_t num_elems, 24 | size_t num_consumers); 25 | 26 | #endif // CONSUMER_H_ 27 | -------------------------------------------------------------------------------- /examples/threaded/include/locked_queue.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LOCKED_QUEUE_H_ 16 | #define LOCKED_QUEUE_H_ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | namespace queue { 24 | 25 | class LockedQueue { 26 | public: 27 | explicit LockedQueue(size_t capacity); 28 | 29 | void Enq(const int &elem); 30 | 31 | int Deq(); 32 | 33 | private: 34 | std::vector contents_; 35 | size_t count_; 36 | size_t head_; 37 | size_t tail_; 38 | std::mutex mutex_; 39 | std::condition_variable not_full_; 40 | std::condition_variable not_empty_; 41 | }; 42 | 43 | } // namespace queue 44 | 45 | #endif // LOCKED_QUEUE_H_ 46 | -------------------------------------------------------------------------------- /examples/threaded/include/producer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef PRODUCER_H_ 16 | #define PRODUCER_H_ 17 | 18 | #include 19 | 20 | #include "locked_queue.h" 21 | 22 | void Producer(queue::LockedQueue &producer_to_consumers, 23 | queue::LockedQueue &consumers_to_producer, size_t num_elems, 24 | size_t num_consumers, int &result); 25 | 26 | #endif // PRODUCER_H_ 27 | -------------------------------------------------------------------------------- /examples/threaded/src/consumer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "consumer.h" 16 | 17 | #include 18 | 19 | void Consumer(queue::LockedQueue &producer_to_consumers, 20 | queue::LockedQueue &consumers_to_producer, size_t num_elems, 21 | size_t num_consumers) { 22 | assert((num_elems % num_consumers) == 0); 23 | int local_result = 0; 24 | for (size_t j = 0; j < num_elems / num_consumers; j++) { 25 | local_result += producer_to_consumers.Deq(); 26 | } 27 | consumers_to_producer.Enq(local_result); 28 | } 29 | -------------------------------------------------------------------------------- /examples/threaded/src/locked_queue.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "locked_queue.h" 16 | 17 | namespace queue { 18 | 19 | LockedQueue::LockedQueue(size_t capacity) : count_(0), head_(0), tail_(0) { 20 | contents_.resize(capacity); 21 | } 22 | 23 | void LockedQueue::Enq(const int &elem) { 24 | std::unique_lock lock(mutex_); 25 | not_full_.wait(lock, [this]() -> bool { return count_ < contents_.size(); }); 26 | contents_[tail_] = elem; 27 | tail_ = (tail_ + 1) % contents_.size(); 28 | count_++; 29 | not_empty_.notify_one(); 30 | } 31 | 32 | int LockedQueue::Deq() { 33 | std::unique_lock lock(mutex_); 34 | not_empty_.wait(lock, [this]() -> bool { return count_ > 0; }); 35 | const int &result = contents_[head_]; 36 | head_ = (head_ + 1) % contents_.size(); 37 | count_--; 38 | not_full_.notify_one(); 39 | return result; 40 | } 41 | 42 | } // namespace queue 43 | -------------------------------------------------------------------------------- /examples/threaded/src/main.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include 16 | #include 17 | #include 18 | 19 | #include "consumer.h" 20 | #include "locked_queue.h" 21 | #include "producer.h" 22 | 23 | int main() { 24 | #define NUM_ELEMS 8192 25 | queue::LockedQueue producer_to_consumers(1024); 26 | queue::LockedQueue consumers_to_producer(8); 27 | int result = 0; 28 | std::vector threads; 29 | 30 | threads.emplace_back(Producer, std::ref(producer_to_consumers), 31 | std::ref(consumers_to_producer), NUM_ELEMS, 8, 32 | std::ref(result)); 33 | 34 | for (size_t i = 0; i < 8; i++) { 35 | threads.emplace_back(Consumer, std::ref(producer_to_consumers), 36 | std::ref(consumers_to_producer), NUM_ELEMS, 8); 37 | } 38 | 39 | for (auto &thread : threads) { 40 | thread.join(); 41 | } 42 | 43 | std::cout << result << std::endl; 44 | return 0; 45 | } 46 | -------------------------------------------------------------------------------- /examples/threaded/src/producer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "producer.h" 16 | 17 | #include 18 | 19 | void Producer(queue::LockedQueue &producer_to_consumers, 20 | queue::LockedQueue &consumers_to_producer, size_t num_elems, 21 | size_t num_consumers, int &result) { 22 | assert((num_elems % num_consumers) == 0); 23 | for (int i = 0; i < num_elems; i++) { 24 | producer_to_consumers.Enq(1); 25 | } 26 | result = 0; 27 | for (int i = 0; i < num_consumers; i++) { 28 | result += consumers_to_producer.Deq(); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /scripts/check_all.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | check_headers.py 22 | check_format.sh 23 | check_cmakelint.sh 24 | check_cpplint.sh 25 | check_clean_build.sh 26 | check_single_file_tests.sh 27 | check_execute_tests.sh 28 | check_bespoke_tests.sh 29 | -------------------------------------------------------------------------------- /scripts/check_bespoke_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | if [ -z "${DREDD_SKIP_CHECK_COMPILE_COMMANDS+x}" ] 22 | then 23 | DREDD_INSTALLED_EXECUTABLE="${DREDD_REPO_ROOT}/third_party/clang+llvm/bin/dredd" 24 | 25 | cd "${DREDD_REPO_ROOT}" 26 | 27 | if [ -z "${DREDD_SKIP_COPY_EXECUTABLE+x}" ] 28 | then 29 | # Ensure that Dredd is in its installed location. This depends on a 30 | # debug build being available 31 | cp temp/build-Debug/src/dredd/dredd "${DREDD_INSTALLED_EXECUTABLE}" 32 | fi 33 | 34 | # Avoid copying Dredd to its installed location when invoking the script that 35 | # checks a single test. 36 | export DREDD_SKIP_COPY_EXECUTABLE=1 37 | 38 | # Consider each single-file test case 39 | for f in test/bespoke/* 40 | do 41 | [[ -e "$f" ]] || break 42 | if [ -d "${f}" ] 43 | then 44 | check_one_bespoke_test.py "${f}" 45 | fi 46 | done 47 | fi 48 | -------------------------------------------------------------------------------- /scripts/check_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | cd temp/ 23 | 24 | for CONFIG in Debug Release; do 25 | mkdir -p "build-${CONFIG}/" 26 | pushd "build-${CONFIG}/" 27 | 28 | cmake \ 29 | -G Ninja \ 30 | ../.. \ 31 | "-DCMAKE_BUILD_TYPE=${CONFIG}" 32 | 33 | cmake --build . --config "${CONFIG}" 34 | 35 | # Run the unit tests 36 | ./src/libdreddtest/libdreddtest 37 | 38 | check_compile_commands.sh compile_commands.json 39 | 40 | popd 41 | done 42 | -------------------------------------------------------------------------------- /scripts/check_clang_tidy.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | COMPILE_COMMANDS="$(realpath "${1}")" 22 | shift 23 | 24 | cd "${DREDD_REPO_ROOT}" 25 | 26 | dredd_cc_files.sh | xargs -t clang-tidy -p="${COMPILE_COMMANDS}" 27 | -------------------------------------------------------------------------------- /scripts/check_clean_build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | cd temp/ 23 | 24 | rm -rf build-*/ 25 | 26 | check_build.sh 27 | -------------------------------------------------------------------------------- /scripts/check_cmakelint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | 23 | for f in $(dredd_cmake_files.sh) 24 | do 25 | cmake-lint "$f" 26 | done 27 | -------------------------------------------------------------------------------- /scripts/check_compile_commands.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | if [ -z "${DREDD_SKIP_CHECK_COMPILE_COMMANDS+x}" ] 22 | then 23 | check_cppcheck.sh "${1}" 24 | check_iwyu.sh "${1}" 25 | check_clang_tidy.sh "${1}" 26 | fi 27 | -------------------------------------------------------------------------------- /scripts/check_cppcheck.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | COMPILE_COMMANDS="$(realpath "${1}")" 22 | shift 23 | 24 | cd "${DREDD_REPO_ROOT}" 25 | 26 | cppcheck \ 27 | --project="${COMPILE_COMMANDS}" \ 28 | --file-filter="$(pwd)/src/"'*' \ 29 | --check-level=exhaustive \ 30 | --error-exitcode=2 \ 31 | --enable=all \ 32 | --inline-suppr \ 33 | --suppress=unusedFunction \ 34 | --suppress=missingIncludeSystem \ 35 | --suppress=missingInclude \ 36 | --suppress=unmatchedSuppression \ 37 | --suppress=syntaxError \ 38 | --suppress=useStlAlgorithm \ 39 | --suppress=preprocessorErrorDirective 40 | -------------------------------------------------------------------------------- /scripts/check_cpplint.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | 23 | dredd_source_files.sh | xargs -t python3 "${CPPLINT_PY}" 24 | -------------------------------------------------------------------------------- /scripts/check_execute_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2024 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | if [ -z "${DREDD_SKIP_CHECK_COMPILE_COMMANDS+x}" ] 22 | then 23 | DREDD_INSTALLED_EXECUTABLE="${DREDD_REPO_ROOT}/third_party/clang+llvm/bin/dredd" 24 | 25 | cd "${DREDD_REPO_ROOT}" 26 | 27 | if [ -z "${DREDD_SKIP_COPY_EXECUTABLE+x}" ] 28 | then 29 | # Ensure that Dredd is in its installed location. This depends on a 30 | # debug build being available 31 | cp temp/build-Debug/src/dredd/dredd "${DREDD_INSTALLED_EXECUTABLE}" 32 | fi 33 | 34 | # Avoid copying Dredd to its installed location when invoking the script that 35 | # checks a single test. 36 | export DREDD_SKIP_COPY_EXECUTABLE=1 37 | 38 | # Consider each single-file test case 39 | for f in test/execute/* 40 | do 41 | [[ -e "$f" ]] || break 42 | if [ -d "${f}" ] 43 | then 44 | check_one_execute_test.py "${f}" 45 | fi 46 | done 47 | fi 48 | -------------------------------------------------------------------------------- /scripts/check_format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | 23 | if ! cmake-format --version 24 | then 25 | echo "cmake-format is not installed." 26 | exit 1 27 | fi 28 | 29 | dredd_source_files.sh | xargs -t clang-format --dry-run --Werror 30 | for f in $(dredd_cmake_files.sh) 31 | do 32 | cmake-format --first-comment-is-literal TRUE --check "$f" 33 | done 34 | 35 | examples_source_files.sh | xargs -t clang-format --dry-run --Werror 36 | for f in $(examples_cmake_files.sh) 37 | do 38 | cmake-format --first-comment-is-literal TRUE --check "$f" 39 | done 40 | 41 | clang-format ./src/libdredd/include/libdredd/protobufs/dredd.proto --dry-run --Werror 42 | -------------------------------------------------------------------------------- /scripts/check_iwyu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | COMPILE_COMMANDS="$(realpath "${1}")" 22 | shift 23 | 24 | cd "${DREDD_REPO_ROOT}" 25 | 26 | # iwyu does not give a non-zero exit code. 27 | # We use awk. 28 | 29 | # Allow spaces to split cpp files: 30 | # shellcheck disable=SC2046 31 | iwyu_tool.py \ 32 | -p="${COMPILE_COMMANDS}" \ 33 | $(dredd_cc_files.sh) \ 34 | -- \ 35 | -Xiwyu --no_fwd_decls \ 36 | -Xiwyu --mapping_file="${DREDD_REPO_ROOT}/src/iwyu.imp" \ 37 | | awk '/should add these lines:/{ exit_code = 1; } { print; } END { if (exit_code) { print "include-what-you-use error; see above."; exit 1; } }' 38 | -------------------------------------------------------------------------------- /scripts/check_json.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | import json 18 | import sys 19 | 20 | json.loads(open(sys.argv[1], 'r').read()) 21 | -------------------------------------------------------------------------------- /scripts/check_single_file_tests.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | if [ -z "${DREDD_SKIP_CHECK_COMPILE_COMMANDS+x}" ] 22 | then 23 | DREDD_INSTALLED_EXECUTABLE="${DREDD_REPO_ROOT}/third_party/clang+llvm/bin/dredd" 24 | 25 | cd "${DREDD_REPO_ROOT}" 26 | 27 | if [ -z "${DREDD_SKIP_COPY_EXECUTABLE+x}" ] 28 | then 29 | # Ensure that Dredd is in its installed location. This depends on a 30 | # debug build being available 31 | cp temp/build-Debug/src/dredd/dredd "${DREDD_INSTALLED_EXECUTABLE}" 32 | fi 33 | 34 | # Avoid copying Dredd to its installed location when invoking the script that 35 | # checks a single test. 36 | export DREDD_SKIP_COPY_EXECUTABLE=1 37 | 38 | # Consider each single-file test case 39 | for f in test/single_file/*.cc test/single_file/*.c 40 | do 41 | [[ -e "$f" ]] || break 42 | check_one_single_file_test.sh "${f}" 43 | done 44 | fi 45 | -------------------------------------------------------------------------------- /scripts/dredd_cc_files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | test -d src/ 22 | 23 | find ./src/ -iname '*.cc' -print 24 | -------------------------------------------------------------------------------- /scripts/dredd_cmake_files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | test -d src/ 22 | 23 | find ./src/ -iname 'CMakeLists.txt' -print 24 | echo ./CMakeLists.txt 25 | echo ./third_party/googletest/CMakeLists.txt 26 | echo ./third_party/protobuf/CMakeLists.txt 27 | -------------------------------------------------------------------------------- /scripts/dredd_source_files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | test -d src/ 22 | 23 | find ./src/ '(' -iname '*.cc' -o -iname '*.h' ')' -print 24 | -------------------------------------------------------------------------------- /scripts/examples_cmake_files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | test -d examples/ 22 | 23 | find ./examples/ -iname 'CMakeLists.txt' -print 24 | echo ./CMakeLists.txt 25 | -------------------------------------------------------------------------------- /scripts/examples_source_files.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | test -d examples/ 22 | 23 | find ./examples/ '(' -iname '*.cc' -o -iname '*.h' ')' -print 24 | -------------------------------------------------------------------------------- /scripts/fix_format.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | cd "${DREDD_REPO_ROOT}" 22 | 23 | dredd_source_files.sh | xargs clang-format -i --verbose 24 | for f in $(dredd_cmake_files.sh) 25 | do 26 | cmake-format --first-comment-is-literal TRUE -i "$f" 27 | done 28 | 29 | examples_source_files.sh | xargs clang-format -i --verbose 30 | for f in $(examples_cmake_files.sh) 31 | do 32 | cmake-format --first-comment-is-literal TRUE -i "$f" 33 | done 34 | 35 | clang-format -i ./src/libdredd/include/libdredd/protobufs/dredd.proto 36 | -------------------------------------------------------------------------------- /scripts/interesting.py.template: -------------------------------------------------------------------------------- 1 | #!/usr/bin/python3 2 | 3 | # Copyright 2023 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | # Interestingness test for use with C-Reduce. 18 | 19 | import shutil 20 | import subprocess 21 | import sys 22 | 23 | # Replace with the name of the file you want to reduce. 24 | filename = "prog.cc" 25 | # Replace this with the message you expect to see in an interesting test case. 26 | message = "Assertion `!isNull() && \"Cannot retrieve a NULL type pointer\"' failed" 27 | # Replace with the path to your dredd checkout. 28 | dredd_root = "/home/afd/dev/dredd" 29 | 30 | shutil.copy(filename, "temp.cc") 31 | 32 | cmd = [dredd_root + "/third_party/clang+llvm/bin/dredd", "temp.cc", "--mutation-info-file", "info.json", "--"] 33 | result = subprocess.run(cmd, capture_output=True) 34 | if result.returncode == 0: 35 | sys.exit(1) 36 | 37 | if message not in result.stderr.decode('utf-8'): 38 | sys.exit(2) 39 | 40 | sys.exit(0) 41 | -------------------------------------------------------------------------------- /scripts/llvm_tag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | echo "17.0.6" 22 | -------------------------------------------------------------------------------- /scripts/regenerate_one_single_file_expectation.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | export DREDD_REGENERATE_TEST_CASE=1 22 | check_one_single_file_test.sh "${1}" 23 | -------------------------------------------------------------------------------- /scripts/regenerate_single_file_expectations.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Copyright 2022 The Dredd Project Authors 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # https://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | set -e 18 | set -u 19 | set -x 20 | 21 | export DREDD_REGENERATE_TEST_CASE=1 22 | check_single_file_tests.sh 23 | -------------------------------------------------------------------------------- /src/.clang-format: -------------------------------------------------------------------------------- 1 | --- 2 | Language: Cpp 3 | BasedOnStyle: Google 4 | DerivePointerAlignment: false 5 | SortIncludes: true 6 | ... 7 | Language: Proto 8 | -------------------------------------------------------------------------------- /src/.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: > 3 | -*, 4 | llvm-header-guard, 5 | cppcoreguidelines-*, 6 | clang-analyser-*, 7 | google-*, 8 | modernize-*, 9 | portability-*, 10 | readability-*, 11 | misc-*, 12 | -google-objc-*, 13 | -modernize-use-trailing-return-type, 14 | -cppcoreguidelines-init-variables, 15 | -cppcoreguidelines-pro-bounds-array-to-pointer-decay, 16 | -cppcoreguidelines-pro-bounds-pointer-arithmetic, 17 | -cppcoreguidelines-pro-type-vararg, 18 | -readability-simplify-boolean-expr, 19 | -readability-use-anyofallof, 20 | -misc-no-recursion, 21 | -misc-include-cleaner, 22 | 23 | # It is quite common to implement a method as a series of checks 24 | # with returns, with a final return true at the end. This check 25 | # forces the final "if(c) { return false} return true;" to be 26 | # turned into "return !c", which isn't always clearer. 27 | #-readability-simplify-boolean-expr, 28 | 29 | # In this project we often think that using a good old for loop is 30 | # more readable than using a lambda, especially if you want to be 31 | # able to early-exit from the loop. 32 | #-readability-use-anyofallof, 33 | 34 | # Recursion is used a lot by design 35 | #-misc-no-recursion, 36 | 37 | WarningsAsErrors: '*' 38 | HeaderFilterRegex: '.*dredd.*' 39 | AnalyzeTemporaryDtors: false 40 | FormatStyle: file 41 | ... 42 | -------------------------------------------------------------------------------- /src/CPPLINT.cfg: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | set noparent 16 | filter=-readability/nolint,-build/c++11,-build/header_guard,-runtime/references 17 | root=. 18 | -------------------------------------------------------------------------------- /src/dredd/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | add_executable( 16 | dredd include_private/include/dredd/log_failed_files_diagnostic_consumer.h 17 | src/main.cc src/log_failed_files_diagnostic_consumer.cc) 18 | target_include_directories(dredd PRIVATE include_private/include) 19 | target_include_directories(dredd SYSTEM PRIVATE ${CMAKE_BINARY_DIR}/src) 20 | target_include_directories( 21 | dredd SYSTEM PRIVATE ${CMAKE_SOURCE_DIR}/third_party/protobuf/protobuf/src) 22 | target_link_libraries(dredd PRIVATE libdredd protobuf::libprotobuf) 23 | -------------------------------------------------------------------------------- /src/dredd/include_private/include/dredd/log_failed_files_diagnostic_consumer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DREDD_LOG_FAILED_FILES_DIAGNOSTIC_CONSUMER_H 16 | #define DREDD_LOG_FAILED_FILES_DIAGNOSTIC_CONSUMER_H 17 | 18 | #include 19 | #include 20 | 21 | #include "clang/Basic/Diagnostic.h" 22 | 23 | // This diagnostic consumer logs the names of all files that exhibit errors. 24 | class LogFailedFilesDiagnosticConsumer : public clang::DiagnosticConsumer { 25 | public: 26 | void clear() override {} 27 | 28 | void BeginSourceFile(const clang::LangOptions& lang_opts, 29 | const clang::Preprocessor* preprocessor) override { 30 | (void)lang_opts; 31 | (void)preprocessor; 32 | } 33 | 34 | void EndSourceFile() override {} 35 | 36 | void finish() override {} 37 | 38 | [[nodiscard]] bool IncludeInDiagnosticCounts() const override { return true; } 39 | 40 | void HandleDiagnostic(clang::DiagnosticsEngine::Level diag_level, 41 | const clang::Diagnostic& info) override; 42 | 43 | [[nodiscard]] const std::set& GetFilesWithErrors() const { 44 | return files_with_errors; 45 | } 46 | 47 | private: 48 | // Any file that exhibits an error will have its name stored in this set. 49 | std::set files_with_errors; 50 | }; 51 | 52 | #endif // DREDD_LOG_FAILED_FILES_DIAGNOSTIC_CONSUMER_H 53 | -------------------------------------------------------------------------------- /src/dredd/include_private/include/dredd/protobufs/protobuf_serialization.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef DREDD_PROTOBUFS_PROTOBUF_SERIALIZATION_H 16 | #define DREDD_PROTOBUFS_PROTOBUF_SERIALIZATION_H 17 | 18 | #if defined(__clang__) 19 | #pragma clang diagnostic push 20 | #pragma clang diagnostic ignored "-Wunknown-warning-option" // Must come first 21 | #pragma clang diagnostic ignored "-Wreserved-identifier" 22 | #pragma clang diagnostic ignored "-Wreserved-macro-identifier" 23 | #pragma clang diagnostic ignored "-Wweak-vtables" 24 | #pragma clang diagnostic ignored "-Winconsistent-missing-destructor-override" 25 | #pragma clang diagnostic ignored "-Wsuggest-destructor-override" 26 | #pragma clang diagnostic ignored "-Wreserved-id-macro" 27 | #elif defined(__GNUC__) 28 | #pragma GCC diagnostic push 29 | #elif defined(_MSC_VER) 30 | #pragma warning(push) 31 | #pragma warning(disable : 4623) 32 | #pragma warning(disable : 4946) 33 | #endif 34 | 35 | // The following should be the only place in the project where protobuf files 36 | // related to serialization are are directly included. This is so that they can 37 | // be compiled in a manner where warnings are ignored. 38 | #include "google/protobuf/stubs/status.h" 39 | #include "google/protobuf/util/json_util.h" 40 | 41 | #if defined(__clang__) 42 | #pragma clang diagnostic pop 43 | #elif defined(__GNUC__) 44 | #pragma GCC diagnostic pop 45 | #elif defined(_MSC_VER) 46 | #pragma warning(pop) 47 | #endif 48 | 49 | #endif // DREDD_PROTOBUFS_PROTOBUF_SERIALIZATION_H 50 | -------------------------------------------------------------------------------- /src/dredd/src/log_failed_files_diagnostic_consumer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "dredd/log_failed_files_diagnostic_consumer.h" 16 | 17 | #include "clang/Basic/Diagnostic.h" 18 | #include "clang/Basic/FileEntry.h" 19 | #include "clang/Basic/SourceLocation.h" 20 | #include "clang/Basic/SourceManager.h" 21 | #include "llvm/ADT/StringRef.h" 22 | 23 | void LogFailedFilesDiagnosticConsumer::HandleDiagnostic( 24 | clang::DiagnosticsEngine::Level diag_level, const clang::Diagnostic& info) { 25 | if (diag_level == clang::DiagnosticsEngine::Error || 26 | diag_level == clang::DiagnosticsEngine::Fatal) { 27 | auto file_id = info.getSourceManager().getMainFileID(); 28 | if (file_id.isValid()) { 29 | files_with_errors.insert( 30 | info.getSourceManager().getFileEntryForID(file_id)->getName().str()); 31 | } 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/iwyu.imp: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [ 16 | # libc++. 17 | { symbol: ["std::ofstream", "private", "", "public"] }, 18 | { symbol: ["std::stringstream", "private", "", "public"] }, 19 | 20 | # Googletest "gtest/gtest.h" 21 | { include: ["", "private", "\"gtest/gtest.h\"", "public"] }, 22 | { include: ["", "private", "\"gtest/gtest.h\"", "public"] }, 23 | 24 | # Protobuf 25 | { include: ["", "private", "\"libdredd/protobufs/dredd_protobufs.h\"", "public"] }, 26 | { include: ["", "private", "\"dredd/protobufs/protobuf_serialization.h\"", "public"] }, 27 | { include: ["", "private", "\"dredd/protobufs/protobuf_serialization.h\"", "public"] }, 28 | 29 | ] 30 | -------------------------------------------------------------------------------- /src/libdredd/include/libdredd/mutation.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBDREDD_MUTATION_H 16 | #define LIBDREDD_MUTATION_H 17 | 18 | #include 19 | #include 20 | 21 | #include "clang/AST/ASTContext.h" 22 | #include "clang/Lex/Preprocessor.h" 23 | #include "clang/Rewrite/Core/Rewriter.h" 24 | #include "libdredd/options.h" 25 | #include "libdredd/protobufs/dredd_protobufs.h" 26 | 27 | namespace dredd { 28 | 29 | // Interface that source code mutations should implement. 30 | class Mutation { 31 | public: 32 | Mutation() = default; 33 | 34 | Mutation(const Mutation&) = delete; 35 | 36 | Mutation& operator=(const Mutation&) = delete; 37 | 38 | Mutation(Mutation&&) = delete; 39 | 40 | Mutation& operator=(Mutation&&) = delete; 41 | 42 | virtual ~Mutation(); 43 | 44 | // The |first_mutation_id_in_file| argument can be subtracted from 45 | // |mutation_id| to turn it from a global mutation id (across all files) into 46 | // a local mutation id with respect to the particular source file being 47 | // mutated. 48 | // 49 | // The |dredd_declarations| argument provides a set of declarations that will 50 | // be added to the start of the source file being mutated. This allows 51 | // avoiding redundant repeat declarations. 52 | virtual protobufs::MutationGroup Apply( 53 | clang::ASTContext& ast_context, const clang::Preprocessor& preprocessor, 54 | const Options& options, int first_mutation_id_in_file, int& mutation_id, 55 | clang::Rewriter& rewriter, 56 | std::unordered_set& dredd_declarations) const = 0; 57 | }; 58 | 59 | } // namespace dredd 60 | 61 | #endif // LIBDREDD_MUTATION_H 62 | -------------------------------------------------------------------------------- /src/libdredd/include/libdredd/new_mutate_frontend_action_factory.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBDREDD_NEW_MUTATE_FRONTEND_ACTION_FACTORY_H 16 | #define LIBDREDD_NEW_MUTATE_FRONTEND_ACTION_FACTORY_H 17 | 18 | #include 19 | #include 20 | 21 | #include "clang/Tooling/Tooling.h" 22 | #include "libdredd/options.h" 23 | #include "libdredd/protobufs/dredd_protobufs.h" 24 | 25 | namespace dredd { 26 | 27 | std::unique_ptr 28 | NewMutateFrontendActionFactory( 29 | const Options& options, int& mutation_id, 30 | std::optional& mutation_info); 31 | 32 | } // namespace dredd 33 | 34 | #endif // LIBDREDD_NEW_MUTATE_FRONTEND_ACTION_FACTORY_H 35 | -------------------------------------------------------------------------------- /src/libdredd/include/libdredd/options.h: -------------------------------------------------------------------------------- 1 | // Copyright 2024 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBDREDD_OPTIONS_H 16 | #define LIBDREDD_OPTIONS_H 17 | 18 | namespace dredd { 19 | 20 | class Options { 21 | public: 22 | Options(bool optimise_mutations, bool dump_asts, 23 | bool only_track_mutant_coverage, bool show_ast_node_types) 24 | : optimise_mutations_(optimise_mutations), 25 | dump_asts_(dump_asts), 26 | only_track_mutant_coverage_(only_track_mutant_coverage), 27 | show_ast_node_types_(show_ast_node_types) {} 28 | 29 | Options() : Options(true, false, false, false) {} 30 | 31 | [[nodiscard]] bool GetOptimiseMutations() const { 32 | return optimise_mutations_; 33 | } 34 | 35 | [[nodiscard]] bool GetOnlyTrackMutantCoverage() const { 36 | return only_track_mutant_coverage_; 37 | } 38 | 39 | [[nodiscard]] bool GetDumpAsts() const { return dump_asts_; } 40 | 41 | [[nodiscard]] bool GetShowAstNodeTypes() const { 42 | return show_ast_node_types_; 43 | } 44 | 45 | private: 46 | // True if and only if Dredd's optimisations are enabled. 47 | bool optimise_mutations_; 48 | 49 | // True if and only if the AST being consumed should be dumped; useful for 50 | // debugging. 51 | bool dump_asts_; 52 | 53 | // True if and only if instrumentation should track whether mutants are 54 | // reached, rather than allowing mutants to be enabled. 55 | bool only_track_mutant_coverage_; 56 | 57 | // True if and only if a comment showing the type of each mutated AST node 58 | // should be emitted. This is useful for debugging. 59 | bool show_ast_node_types_; 60 | }; 61 | 62 | } // namespace dredd 63 | 64 | #endif // LIBDREDD_OPTIONS_H 65 | -------------------------------------------------------------------------------- /src/libdredd/src/mutation.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #include "libdredd/mutation.h" 16 | 17 | namespace dredd { 18 | 19 | Mutation::~Mutation() = default; 20 | 21 | } // namespace dredd 22 | -------------------------------------------------------------------------------- /src/libdreddtest/.clang-tidy: -------------------------------------------------------------------------------- 1 | --- 2 | Checks: > 3 | -cppcoreguidelines-owning-memory, 4 | -cppcoreguidelines-avoid-non-const-global-variables, 5 | -readability-function-cognitive-complexity, 6 | 7 | InheritParentConfig: true 8 | ... 9 | -------------------------------------------------------------------------------- /src/libdreddtest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | if(DREDD_WARNING_SUPPRESSIONS) 16 | if(MSVC) 17 | 18 | else() 19 | add_compile_options(-Wno-global-constructors) 20 | endif() 21 | endif() 22 | 23 | add_executable( 24 | libdreddtest 25 | include_private/include/libdreddtest/gtest.h src/mutation_remove_stmt_test.cc 26 | src/mutation_replace_binary_operator_test.cc 27 | src/mutation_replace_expr_test.cc src/mutation_replace_unary_operator_test.cc) 28 | 29 | target_link_libraries(libdreddtest PRIVATE libdredd gtest_main 30 | protobuf::libprotobuf) 31 | target_include_directories(libdreddtest PRIVATE include_private/include) 32 | 33 | target_include_directories(libdreddtest SYSTEM PRIVATE ${CMAKE_BINARY_DIR}/src) 34 | 35 | add_test(NAME libdreddtest COMMAND libdreddtest) 36 | -------------------------------------------------------------------------------- /src/libdreddtest/include_private/include/libdreddtest/gtest.h: -------------------------------------------------------------------------------- 1 | // Copyright 2022 The Dredd Project Authors 2 | // 3 | // Licensed under the Apache License, Version 2.0 (the "License"); 4 | // you may not use this file except in compliance with the License. 5 | // You may obtain a copy of the License at 6 | // 7 | // http://www.apache.org/licenses/LICENSE-2.0 8 | // 9 | // Unless required by applicable law or agreed to in writing, software 10 | // distributed under the License is distributed on an "AS IS" BASIS, 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | // See the License for the specific language governing permissions and 13 | // limitations under the License. 14 | 15 | #ifndef LIBDREDDTEST_GTEST_H 16 | #define LIBDREDDTEST_GTEST_H 17 | 18 | // This header file serves to act as a barrier between the gtest header file 19 | // and test files that include them. It uses compiler pragmas to disable 20 | // diagnostics, in order to ignore warnings generated during the processing of 21 | // the header file without having to compromise on freedom from warnings 22 | // elsewhere in the project. 23 | 24 | #if defined(__clang__) 25 | #pragma clang diagnostic push 26 | #elif defined(__GNUC__) 27 | #pragma GCC diagnostic push 28 | #elif defined(_MSC_VER) 29 | #pragma warning(push) 30 | #pragma warning(disable : 4388) 31 | #pragma warning(disable : 4668) 32 | #endif 33 | 34 | #include "gtest/gtest.h" // IWYU pragma: export 35 | 36 | #if defined(__clang__) 37 | #pragma clang diagnostic pop 38 | #elif defined(__GNUC__) 39 | #pragma GCC diagnostic pop 40 | #elif defined(_MSC_VER) 41 | #pragma warning(pop) 42 | #endif 43 | 44 | #endif // LIBDREDDTEST_GTEST_H 45 | -------------------------------------------------------------------------------- /temp/.gitignore: -------------------------------------------------------------------------------- 1 | 2 | * 3 | !/.gitignore 4 | -------------------------------------------------------------------------------- /test/README.md: -------------------------------------------------------------------------------- 1 | Dredd end-to-end tests 2 | ====================== 3 | 4 | There are three kinds of test: 5 | 6 | - Single file tests, which checks that Dredd produces expected source code when applied to a single file, and that the mutated source code compiles. The mutated code is not executed. 7 | 8 | - Execute tests, which check that a Dredd-mutated program produces given expected results when executed with and without mutants enabled. This is useful to ensure that certain outputs are always observed, no matter what optimisations are in place. 9 | 10 | - Bespoke tests, for testing other functionality. 11 | 12 | See README files in each subdirectory for more details. 13 | -------------------------------------------------------------------------------- /test/bespoke/README.md: -------------------------------------------------------------------------------- 1 | Dredd *execute* tests 2 | ===================== 3 | 4 | There is one subdirectory per test. 5 | 6 | Each subdirectory must contain: 7 | 8 | - `test.py` - a Python script that should return if and only if the test is successful. 9 | 10 | - Any other files required to support the bespoke test. 11 | 12 | See the script that runs `bespoke` tests to see how these tests are invoked. 13 | -------------------------------------------------------------------------------- /test/bespoke/mutant_tracking/example.c: -------------------------------------------------------------------------------- 1 | int main(int argc, char** argv) { 2 | if (argc == 1) { 3 | return 0; 4 | } else { 5 | return argc * 10; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /test/bespoke/nonexistent-file/test.py: -------------------------------------------------------------------------------- 1 | import os 2 | import subprocess 3 | import sys 4 | from pathlib import Path 5 | 6 | DREDD_REPO_ROOT = os.environ['DREDD_REPO_ROOT'] 7 | DREDD_INSTALLED_EXECUTABLE = Path(DREDD_REPO_ROOT, 'third_party', 'clang+llvm', 'bin', 'dredd') 8 | 9 | 10 | def main(): 11 | cmd = [DREDD_INSTALLED_EXECUTABLE, 'tomutate.c', '--'] 12 | result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 13 | # We expect an error due to a non-existent file. 14 | assert result.returncode != 0 15 | stderr_output = result.stderr.decode('utf-8') 16 | # Unless Clang's diagnostics change, these are fragments of the error 17 | # messages that are expected: 18 | assert "no such file or directory" in stderr_output 19 | assert "no input files" in stderr_output 20 | assert "unable to handle compilation, expected exactly one compiler job" in stderr_output 21 | return 0 22 | 23 | 24 | if __name__ == '__main__': 25 | sys.exit(main()) 26 | -------------------------------------------------------------------------------- /test/bespoke/skip_bad_files/bad1.c: -------------------------------------------------------------------------------- 1 | invalid code 2 | -------------------------------------------------------------------------------- /test/bespoke/skip_bad_files/bad2.c: -------------------------------------------------------------------------------- 1 | invalid code 2 | -------------------------------------------------------------------------------- /test/bespoke/skip_bad_files/good1.c: -------------------------------------------------------------------------------- 1 | int foo(); 2 | 3 | int main() { 4 | return foo(); 5 | } 6 | -------------------------------------------------------------------------------- /test/bespoke/skip_bad_files/good2.c: -------------------------------------------------------------------------------- 1 | int foo() { 2 | return 42; 3 | } 4 | -------------------------------------------------------------------------------- /test/bespoke/skip_bad_files/test.py: -------------------------------------------------------------------------------- 1 | import json 2 | import os 3 | import re 4 | import subprocess 5 | import sys 6 | from pathlib import Path 7 | 8 | DREDD_REPO_ROOT = os.environ['DREDD_REPO_ROOT'] 9 | DREDD_INSTALLED_EXECUTABLE = Path(DREDD_REPO_ROOT, 'third_party', 'clang+llvm', 'bin', 'dredd') 10 | 11 | 12 | def run_successfully(cmd): 13 | return result 14 | 15 | 16 | def main(): 17 | cmd = [DREDD_INSTALLED_EXECUTABLE, 18 | '--mutation-info-file', 19 | 'info.json', 20 | 'good1.c', 21 | 'bad1.c', 22 | 'good2.c', 23 | 'bad2.c', 24 | '--'] 25 | result = subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 26 | # Dredd should return non-zero, due to 'bad1.c' and 'bad2.c' 27 | assert result.returncode != 0 28 | error_output = result.stderr.decode('utf-8') 29 | pattern = "The following files were not mutated due to compile-time errors; see above for details:\s+[^\s]+bad1\.c\s+[^\s]+bad2\.c" 30 | match = re.search(pattern, error_output) 31 | assert match is not None 32 | dictionary = json.load(open('info.json')) 33 | info_for_files = dictionary['infoForFiles'] 34 | assert len(info_for_files) == 2 35 | assert info_for_files[0]['filename'].endswith('good1.c') 36 | assert info_for_files[1]['filename'].endswith('good2.c') 37 | 38 | 39 | if __name__ == '__main__': 40 | sys.exit(main()) 41 | -------------------------------------------------------------------------------- /test/execute/README.md: -------------------------------------------------------------------------------- 1 | Dredd *execute* tests 2 | ===================== 3 | 4 | There is one subdirectory per test. 5 | 6 | Each subdirectory must contain: 7 | 8 | - `harness.c(c)` - a C or C++ file with a `main`, that should print a single line of output. 9 | 10 | - `tomutate.c(c)` - a C or C++ file that will be mutated. The harness should call functions of this file. 11 | 12 | - `original.txt` - A file containing the single line of output that should be printed by the harness when no mutants are enabled. 13 | 14 | - `mutants.txt` - A file containing various outputs that should be 15 | expected when mutants are used. Each line can feature a comment, of 16 | the form `;` - the content of the line from the semi-colon onward 17 | will be ignored. This allows one to document why particular outputs 18 | are expected for particular mutants. 19 | 20 | See the script that runs `execute` tests for precise details of how they work. 21 | -------------------------------------------------------------------------------- /test/execute/add/harness.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int add(int, int); 4 | 5 | int main() { 6 | printf("%d\n", add(7, 3)); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/execute/add/mutants.txt: -------------------------------------------------------------------------------- 1 | 2 ; a / b 2 | 21 ; a * b 3 | 1 ; a % b 4 | 4 ; a - b 5 | 7 ; a 6 | 3 ; b 7 | 8 | 0 ; !(a + b) 9 | -11 ; ~(a + b) 10 | -10 ; -(a + b) 11 | 0 ; 0 12 | 1 ; 1 13 | -1 ; -1 14 | 15 | 3 ; !a + b 16 | -5 ; ~a + b 17 | -4 ; -a + b 18 | 3 ; 0 + b 19 | 4 ; 1 + b 20 | 2 ; -1 + b 21 | 22 | 11 ; ++a + b 23 | 9 ; --a + b 24 | 25 | 7 ; a + !b 26 | 3 ; a + ~b 27 | 4 ; a + -b 28 | 7 ; a + 0 29 | 8 ; a + 1 30 | 6 ; a + -1 31 | 32 | 11 ; a + ++b 33 | 9 ; a + --b 34 | -------------------------------------------------------------------------------- /test/execute/add/original.txt: -------------------------------------------------------------------------------- 1 | 10 2 | -------------------------------------------------------------------------------- /test/execute/add/tomutate.c: -------------------------------------------------------------------------------- 1 | int add(int x, int y) { 2 | return x + y; 3 | } 4 | -------------------------------------------------------------------------------- /test/execute/bit_overflow_c/harness.c: -------------------------------------------------------------------------------- 1 | void print_33_nums(); 2 | 3 | int main() { 4 | print_33_nums(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/execute/bit_overflow_c/original.txt: -------------------------------------------------------------------------------- 1 | 0_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_ -------------------------------------------------------------------------------- /test/execute/bit_overflow_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_33_nums() { 4 | printf("0_"); 5 | printf("1_"); 6 | printf("2_"); 7 | printf("3_"); 8 | printf("4_"); 9 | printf("5_"); 10 | printf("6_"); 11 | printf("7_"); 12 | printf("8_"); 13 | printf("9_"); 14 | printf("10_"); 15 | printf("11_"); 16 | printf("12_"); 17 | printf("13_"); 18 | printf("14_"); 19 | printf("15_"); 20 | printf("16_"); 21 | printf("17_"); 22 | printf("18_"); 23 | printf("19_"); 24 | printf("20_"); 25 | printf("21_"); 26 | printf("22_"); 27 | printf("23_"); 28 | printf("24_"); 29 | printf("25_"); 30 | printf("26_"); 31 | printf("27_"); 32 | printf("28_"); 33 | printf("29_"); 34 | printf("30_"); 35 | printf("31_"); 36 | printf("32_"); 37 | } -------------------------------------------------------------------------------- /test/execute/bit_overflow_cc/harness.cc: -------------------------------------------------------------------------------- 1 | void print_33_nums(); 2 | 3 | int main() { 4 | print_33_nums(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/execute/bit_overflow_cc/original.txt: -------------------------------------------------------------------------------- 1 | 0_1_2_3_4_5_6_7_8_9_10_11_12_13_14_15_16_17_18_19_20_21_22_23_24_25_26_27_28_29_30_31_32_ -------------------------------------------------------------------------------- /test/execute/bit_overflow_cc/tomutate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void print_33_nums() { 4 | std::cout << "0_"; 5 | std::cout << "1_"; 6 | std::cout << "2_"; 7 | std::cout << "3_"; 8 | std::cout << "4_"; 9 | std::cout << "5_"; 10 | std::cout << "6_"; 11 | std::cout << "7_"; 12 | std::cout << "8_"; 13 | std::cout << "9_"; 14 | std::cout << "10_"; 15 | std::cout << "11_"; 16 | std::cout << "12_"; 17 | std::cout << "13_"; 18 | std::cout << "14_"; 19 | std::cout << "15_"; 20 | std::cout << "16_"; 21 | std::cout << "17_"; 22 | std::cout << "18_"; 23 | std::cout << "19_"; 24 | std::cout << "20_"; 25 | std::cout << "21_"; 26 | std::cout << "22_"; 27 | std::cout << "23_"; 28 | std::cout << "24_"; 29 | std::cout << "25_"; 30 | std::cout << "26_"; 31 | std::cout << "27_"; 32 | std::cout << "28_"; 33 | std::cout << "29_"; 34 | std::cout << "30_"; 35 | std::cout << "31_"; 36 | std::cout << "32_"; 37 | } 38 | -------------------------------------------------------------------------------- /test/execute/constant_function_argument/harness.cc: -------------------------------------------------------------------------------- 1 | void foo(); 2 | 3 | int main() { 4 | foo(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/execute/constant_function_argument/mutants.txt: -------------------------------------------------------------------------------- 1 | 0 ; replace b with 0 2 | 1 ; replace b with 1 3 | -1 ; replace b with -1 4 | -------------------------------------------------------------------------------- /test/execute/constant_function_argument/original.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/execute/constant_function_argument/tomutate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() { 4 | const int b = 2; 5 | __builtin_frame_address(b); 6 | std::cout << b << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/constant_sized_array/harness.cc: -------------------------------------------------------------------------------- 1 | void foo(); 2 | 3 | int main() { 4 | foo(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/execute/constant_sized_array/mutants.txt: -------------------------------------------------------------------------------- 1 | 0 ; replace b with 0 2 | 1 ; replace b with 1 3 | -1 ; replace b with -1 4 | -------------------------------------------------------------------------------- /test/execute/constant_sized_array/original.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/execute/constant_sized_array/tomutate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() { 4 | const int b = 2; 5 | int a[b + b]{10, 11, 12, 13}; 6 | std::cout << b << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_1/harness.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | unsigned int foo(); 4 | 5 | int main() { 6 | std::cout << foo() << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_1/mutants.txt: -------------------------------------------------------------------------------- 1 | 0 ; Replace 42 with 0 2 | 1 ; Replace 42 with 1 3 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_1/original.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_1/tomutate.cc: -------------------------------------------------------------------------------- 1 | unsigned int glob; 2 | 3 | struct S { 4 | 5 | ~S() { 6 | glob = 12; 7 | } 8 | 9 | unsigned int& operator[](int) { 10 | return glob; 11 | } 12 | }; 13 | 14 | unsigned int foo() { 15 | glob = 42; 16 | return S()[0]; 17 | } 18 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_2/harness.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int foo(); 4 | 5 | int main() { 6 | std::cout << foo() << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_2/mutants.txt: -------------------------------------------------------------------------------- 1 | 0 ; Replace 42 or overall expression with 0 2 | 1 ; Replace 42 or overall expression with 1 3 | -1 ; Replace overall expression with -1 4 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_2/original.txt: -------------------------------------------------------------------------------- 1 | 42 2 | -------------------------------------------------------------------------------- /test/execute/materialized_temporary_2/tomutate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct S { 4 | unsigned f; 5 | ~S() { 6 | f = 12; 7 | } 8 | }; 9 | 10 | struct T { 11 | std::optional g; 12 | std::optional getg() const { return g; } 13 | }; 14 | 15 | unsigned bar(std::optional g) { 16 | return g->f; 17 | } 18 | 19 | int foo() { 20 | T x; 21 | x.g = S{42}; 22 | return bar(S{x.getg()->f}); 23 | } 24 | -------------------------------------------------------------------------------- /test/execute/nomutants/harness.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void empty(); 4 | 5 | int main() { 6 | empty(); 7 | return 0; 8 | } 9 | -------------------------------------------------------------------------------- /test/execute/nomutants/mutants.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mc-imperial/dredd/cfb3f8a053ce7a8863ffe9e0f0d31a788254cf74/test/execute/nomutants/mutants.txt -------------------------------------------------------------------------------- /test/execute/nomutants/original.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mc-imperial/dredd/cfb3f8a053ce7a8863ffe9e0f0d31a788254cf74/test/execute/nomutants/original.txt -------------------------------------------------------------------------------- /test/execute/nomutants/tomutate.c: -------------------------------------------------------------------------------- 1 | void empty() { 2 | } 3 | -------------------------------------------------------------------------------- /test/execute/static_assert_rewrite/harness.cc: -------------------------------------------------------------------------------- 1 | void foo(); 2 | 3 | int main() { 4 | foo(); 5 | return 0; 6 | } 7 | -------------------------------------------------------------------------------- /test/execute/static_assert_rewrite/mutants.txt: -------------------------------------------------------------------------------- 1 | 0 ; replace b with 0 2 | 1 ; replace b with 1 3 | -1 ; replace b with -1 4 | -------------------------------------------------------------------------------- /test/execute/static_assert_rewrite/original.txt: -------------------------------------------------------------------------------- 1 | 2 2 | -------------------------------------------------------------------------------- /test/execute/static_assert_rewrite/tomutate.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void foo() { 4 | const int b = 2; 5 | static_assert(b); 6 | std::cout << b << std::endl; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/switch_cases/harness.c: -------------------------------------------------------------------------------- 1 | void switch_cases(int c); 2 | 3 | int main() { 4 | switch_cases(1); 5 | switch_cases(2); 6 | switch_cases(3); 7 | switch_cases(4); 8 | switch_cases(5); 9 | return 0; 10 | } 11 | -------------------------------------------------------------------------------- /test/execute/switch_cases/mutants.txt: -------------------------------------------------------------------------------- 1 | d_e_b_c_e_b_c_e_b_c_e_d_e_ ; remove printf("a_") 2 | a_e_a_e_a_e_a_e_a_e_ ; remove entire switch 3 | a_d_e_a_c_e_a_c_e_a_c_e_a_d_e_ ; remove printf("b_") 4 | a_d_e_a_b_e_a_b_e_a_b_e_a_d_e_ ; remove printf("c_") 5 | a_d_e_a_b_c_d_e_a_b_c_d_e_a_b_c_d_e_a_d_e_ ; remove break 6 | a_e_a_b_c_e_a_b_c_e_a_b_c_e_a_e_ ; remove printf("d_") 7 | a_d_a_b_c_a_b_c_a_b_c_a_d_ ; remove printf("e_") 8 | -------------------------------------------------------------------------------- /test/execute/switch_cases/original.txt: -------------------------------------------------------------------------------- 1 | a_d_e_a_b_c_e_a_b_c_e_a_b_c_e_a_d_e_ 2 | -------------------------------------------------------------------------------- /test/execute/switch_cases/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void switch_cases(int c) { 4 | printf("a_"); 5 | switch (c) { 6 | case 2: 7 | case 3: 8 | case 4: 9 | printf("b_"); 10 | printf("c_"); 11 | break; 12 | case 5: 13 | default: 14 | printf("d_"); 15 | } 16 | printf("e_"); 17 | } 18 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero == 0) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if(0 == zero) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (ten == 0) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | if (0 == ten) { 20 | printf("0_"); 21 | } else { 22 | printf("1_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_eq_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a == two_b) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if (one == ten) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (onehundred == zero) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero >= 0) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if(0 >= zero) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (ten >= 0) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | if (0 >= ten) { 20 | printf("0_"); 21 | } else { 22 | printf("1_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ge_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a >= two_b) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if (one >= ten) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (onehundred >= zero) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero > 0) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if(0 > zero) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (ten > 0) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | if (0 > ten) { 20 | printf("0_"); 21 | } else { 22 | printf("1_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_gt_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a > two_b) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if (one > ten) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (onehundred > zero) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero <= 0) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if(0 <= zero) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (ten <= 0) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | if (0 <= ten) { 20 | printf("1_"); 21 | } else { 22 | printf("0_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_le_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a <= two_b) { 5 | printf("1_"); 6 | } else { 7 | printf("0_"); 8 | } 9 | if (one <= ten) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (onehundred <= zero) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero < 0) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if(0 < zero) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (ten < 0) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | if (0 < ten) { 20 | printf("1_"); 21 | } else { 22 | printf("0_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_lt_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a < two_b) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if (one < ten) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (onehundred < zero) { 15 | printf("0_"); 16 | } else { 17 | printf("1_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_0_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned ten); 3 | 4 | int main() { 5 | doit(0, 10); 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_0_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_0_ 2 | 1_1_0_1_ 3 | 1_0_1_1_ 4 | 0_1_1_1_ 5 | 1_1_1_ 6 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_0_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_0_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned ten) { 4 | if(zero != 0) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if(0 != zero) { 10 | printf("0_"); 11 | } else { 12 | printf("1_"); 13 | } 14 | if (ten != 0) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | if (0 != ten) { 20 | printf("1_"); 21 | } else { 22 | printf("0_"); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_c/harness.c: -------------------------------------------------------------------------------- 1 | void doit(unsigned zero, 2 | unsigned one, 3 | unsigned two_a, 4 | unsigned two_b, 5 | unsigned ten, 6 | unsigned onehundred); 7 | 8 | int main() { 9 | doit(0, 1, 2, 2, 10, 100); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_c/mutants.txt: -------------------------------------------------------------------------------- 1 | 1_1_0_ 2 | 1_0_1_ 3 | 0_1_1_ 4 | 1_1_ 5 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_c/original.txt: -------------------------------------------------------------------------------- 1 | 1_1_1_ 2 | -------------------------------------------------------------------------------- /test/execute/unsigned_comparison_ne_c/tomutate.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void doit(unsigned zero, unsigned one, unsigned two_a, unsigned two_b, unsigned ten, unsigned onehundred) { 4 | if(two_a != two_b) { 5 | printf("0_"); 6 | } else { 7 | printf("1_"); 8 | } 9 | if (one != ten) { 10 | printf("1_"); 11 | } else { 12 | printf("0_"); 13 | } 14 | if (onehundred != zero) { 15 | printf("1_"); 16 | } else { 17 | printf("0_"); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /test/single_file/README.md: -------------------------------------------------------------------------------- 1 | This provides a way of confirming that Dredd behaves as expected on a 2 | set of single-file test cases. 3 | 4 | Whenever a new feature is added to Dredd, or a defect is discovered 5 | when using Dredd, a test case should be added to this test set in 6 | response. The test case should ensure that Dredd produces the expected 7 | output on a given input program. 8 | 9 | A test case consists of a `.c` or `.cc` file and a corresponding `.expected` 10 | file. 11 | 12 | The `check_single_file_tests.sh` script can be used to run Dredd on 13 | all single-file test cases, confirming that results are as expected 14 | and that every mutated file compiles. 15 | 16 | A change in Dredd may require many of the `.expected` file to be 17 | updated. If you are confident that the change is a good one, the 18 | `regenerate_single_file_expectations.sh` can be used to update all 19 | such files based on Dredd's current behaviour. 20 | -------------------------------------------------------------------------------- /test/single_file/add.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | int y = 2; 4 | return x + y + x; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/add.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | int y = 2; 4 | return x + y + x; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/add_float.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | float x = 5.235; 3 | float y = 754.34623; 4 | float z; 5 | z = x + y; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/add_float.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | float x = 5.235; 3 | float y = 754.34623; 4 | float z; 5 | z = x + y; 6 | return 0; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/add_mul.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | int y = 2; 4 | return x + y * x; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/add_mul.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | int y = 2; 4 | return x + y * x; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/add_type_aliases.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | unsigned a; 6 | uint32_t b; 7 | int c; 8 | int32_t d; 9 | unsigned long e; 10 | size_t f; 11 | long g; 12 | int64_t h; 13 | uint64_t i; 14 | 15 | a + a; 16 | b + b; 17 | c + c; 18 | d + d; 19 | e + e; 20 | f + f; 21 | g + g; 22 | h + h; 23 | i + i; 24 | } 25 | -------------------------------------------------------------------------------- /test/single_file/add_type_aliases.c.expected: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | unsigned a; 6 | uint32_t b; 7 | int c; 8 | int32_t d; 9 | unsigned long e; 10 | size_t f; 11 | long g; 12 | int64_t h; 13 | uint64_t i; 14 | 15 | a + a; 16 | b + b; 17 | c + c; 18 | d + d; 19 | e + e; 20 | f + f; 21 | g + g; 22 | h + h; 23 | i + i; 24 | } 25 | -------------------------------------------------------------------------------- /test/single_file/add_type_aliases.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | unsigned a; 6 | uint32_t b; 7 | int c; 8 | int32_t d; 9 | unsigned long e; 10 | size_t f; 11 | long g; 12 | int64_t h; 13 | uint64_t i; 14 | 15 | a + a; 16 | b + b; 17 | c + c; 18 | d + d; 19 | e + e; 20 | f + f; 21 | g + g; 22 | h + h; 23 | i + i; 24 | } 25 | -------------------------------------------------------------------------------- /test/single_file/add_type_aliases.cc.expected: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int main() { 5 | unsigned a; 6 | uint32_t b; 7 | int c; 8 | int32_t d; 9 | unsigned long e; 10 | size_t f; 11 | long g; 12 | int64_t h; 13 | uint64_t i; 14 | 15 | a + a; 16 | b + b; 17 | c + c; 18 | d + d; 19 | e + e; 20 | f + f; 21 | g + g; 22 | h + h; 23 | i + i; 24 | } 25 | -------------------------------------------------------------------------------- /test/single_file/adl.cc: -------------------------------------------------------------------------------- 1 | namespace bar { 2 | void foo(int x); 3 | 4 | enum {B = 1}; 5 | 6 | struct C { 7 | operator int(); 8 | friend void baz(int x); 9 | }; 10 | } 11 | 12 | void func() { 13 | // All of these calls rely on ADL 14 | foo(bar::B); 15 | foo((bar::B)); 16 | bar::C c; 17 | foo(c); 18 | foo((c)); 19 | baz(c); 20 | baz((c)); 21 | } 22 | -------------------------------------------------------------------------------- /test/single_file/array_with_named_constant_size_rewrite.cc: -------------------------------------------------------------------------------- 1 | int a() { 2 | const int b = 2; 3 | int c[b + b]{}; 4 | return b; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/array_with_named_constant_size_rewrite2.cc: -------------------------------------------------------------------------------- 1 | int a() { 2 | const int b = 2; 3 | int c[b + b]; 4 | return b; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/assign.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x; 3 | volatile int y; 4 | x = 2; 5 | y = 4; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/assign.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x; 3 | volatile int y; 4 | x = 2; 5 | y = 4; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/assign_null.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/assign_null.c.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/assign_null.c.noopt.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/assign_null.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/assign_null.cc.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/assign_null.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | int* x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/auto.cc: -------------------------------------------------------------------------------- 1 | int foo(int x) { 2 | // It is important that "y" is not mutated in "auto y" 3 | if (auto y = x) { 4 | return y; 5 | } 6 | return 2; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/basic.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/basic.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 3) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { 53 | if (!__dredd_some_mutation_enabled) return arg; 54 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; 55 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; 56 | return arg; 57 | } 58 | 59 | int main() { 60 | if (!__dredd_enabled_mutation(2)) { return __dredd_replace_expr_int_zero(0, 0); } 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/basic.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | return 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/basic.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 3) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { 56 | if (!__dredd_some_mutation_enabled) return arg; 57 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; 58 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; 59 | return arg; 60 | } 61 | 62 | int main() { 63 | if (!__dredd_enabled_mutation(2)) { return __dredd_replace_expr_int_zero(0, 0); } 64 | } 65 | -------------------------------------------------------------------------------- /test/single_file/binary_both_zero.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 + 0; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/binary_lhs_zero.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 + 8; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/binary_long_long_and_long_name_clash.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 5LL && 4L; 3 | 4L && 5LL; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/binary_long_long_and_long_name_clash.c.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | 5LL && 4L; 3 | 4L && 5LL; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/binary_no_arg_replacement.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 - 7; 3 | int y = 5 / 1; 4 | int z = -1 * 3; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/binary_operands_both_zero.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 + 0; 3 | x = 0 + 1; 4 | x = 1 + 0; 5 | x = 0 + -1; 6 | x = -1 + 0; 7 | x = 1 + -1; 8 | x = -1 + 1; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/binary_operands_both_zero.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 + 0; 3 | x = 0 + 1; 4 | x = 1 + 0; 5 | x = 0 + -1; 6 | x = -1 + 0; 7 | x = 1 + -1; 8 | x = -1 + 1; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/binary_redundant_name_clash.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 + 5; 3 | int y = 5 + 0; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/binary_rhs_zero.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 5 + 0; 3 | return x; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/bitfield.c: -------------------------------------------------------------------------------- 1 | struct S { 2 | int a : 3; 3 | int b : 3; 4 | }; 5 | 6 | void foo() { 7 | struct S myS; 8 | myS.a = myS.b; 9 | myS.a = -myS.b; 10 | myS.a++; 11 | --myS.b; 12 | } 13 | -------------------------------------------------------------------------------- /test/single_file/bitfield.cc: -------------------------------------------------------------------------------- 1 | struct S { 2 | int a : 3; 3 | int b : 3; 4 | }; 5 | 6 | void foo() { 7 | S myS; 8 | myS.a = myS.b; 9 | myS.a = -myS.b; 10 | myS.a++; 11 | --myS.b; 12 | } 13 | -------------------------------------------------------------------------------- /test/single_file/bitfield_reference_passing.cc: -------------------------------------------------------------------------------- 1 | template void bloop(T& x) { } 2 | 3 | struct foo { 4 | int b : 2; 5 | }; 6 | 7 | int main() { 8 | const foo d = foo(); 9 | bloop(d.b); 10 | } 11 | -------------------------------------------------------------------------------- /test/single_file/bitfield_reference_passing.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | template void bloop(T& x) { } 56 | 57 | struct foo { 58 | int b : 2; 59 | }; 60 | 61 | int main() { 62 | const foo d = foo(); 63 | if (!__dredd_enabled_mutation(0)) { bloop(d.b); } 64 | } 65 | -------------------------------------------------------------------------------- /test/single_file/bitfield_reference_passing.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | template void bloop(T& x) { } 56 | 57 | struct foo { 58 | int b : 2; 59 | }; 60 | 61 | int main() { 62 | const foo d = foo(); 63 | if (!__dredd_enabled_mutation(0)) { bloop(d.b); } 64 | } 65 | -------------------------------------------------------------------------------- /test/single_file/bool_assignment.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | bool x = true; 3 | bool y = false; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/boolean_not_insertion_optimisation.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x = 1 && 0; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/boolean_not_insertion_optimisation.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | bool x = true; 3 | x = false; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/braced_initialization.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | char test {24}; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/builtin_frame_address.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | __builtin_frame_address(0); 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/builtin_frame_address.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | void foo() { 56 | if (!__dredd_enabled_mutation(0)) { __builtin_frame_address(0); } 57 | } 58 | -------------------------------------------------------------------------------- /test/single_file/builtin_frame_address.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | void foo() { 56 | if (!__dredd_enabled_mutation(0)) { __builtin_frame_address(0); } 57 | } 58 | -------------------------------------------------------------------------------- /test/single_file/builtin_frame_address_with_argument_rewrite.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | const int x = 42; 3 | __builtin_frame_address(x); 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/comma.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | int y = 2; 4 | return x, y; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/comma_initialization.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = (1,0); 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/comma_initialization.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int b((1,0)); 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/comma_side_effects.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0; 3 | x = (0, x++); 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/comma_side_effects.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0; 3 | x = (0, x++); 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/comment.cc: -------------------------------------------------------------------------------- 1 | void g(); 2 | 3 | void f() 4 | { 5 | g() /* something */ ; 6 | g() // something 7 | ; 8 | 9 | if(true) { 10 | 11 | } 12 | // something 13 | if(true) { 14 | 15 | } /* something */ 16 | } 17 | -------------------------------------------------------------------------------- /test/single_file/comment_at_start_of_file.cc: -------------------------------------------------------------------------------- 1 | // Hello 2 | 3 | int main() { 4 | return 42; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/const_expr.cc: -------------------------------------------------------------------------------- 1 | double foo(const double &x) { 2 | return x; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_expr_function.cc: -------------------------------------------------------------------------------- 1 | constexpr int Max(int a, int b) { return a > b ? a : b; } 2 | 3 | int main() { 4 | Max(5,4); 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/const_expr_function_call.cc: -------------------------------------------------------------------------------- 1 | constexpr int Max(int a, int b) { return a > b ? a : b; } 2 | 3 | int foo() { 4 | return Max(5,4); 5 | } 6 | 7 | int main() {} 8 | -------------------------------------------------------------------------------- /test/single_file/const_init.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | [[clang::require_constant_initialization]] static int x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_init.cc.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | [[clang::require_constant_initialization]] static int x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_init.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | int main() { 2 | [[clang::require_constant_initialization]] static int x = 0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_sized_array_int.c: -------------------------------------------------------------------------------- 1 | void foo() { 2 | int A[1 + 3] = {0}; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_sized_array_int.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 2) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { 53 | if (!__dredd_some_mutation_enabled) return arg; 54 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; 55 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; 56 | return arg; 57 | } 58 | 59 | void foo() { 60 | int A[1 + 3] = {__dredd_replace_expr_int_zero(0, 0)}; 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/const_sized_array_int.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | int A[1 + 3] = {0}; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/const_sized_array_int.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 2) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { 56 | if (!__dredd_some_mutation_enabled) return arg; 57 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; 58 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; 59 | return arg; 60 | } 61 | 62 | void foo() { 63 | int A[4] = {__dredd_replace_expr_int_zero(0, 0)}; 64 | } 65 | -------------------------------------------------------------------------------- /test/single_file/constexpr.cc: -------------------------------------------------------------------------------- 1 | // Checks that operator mutations are not applied to constexprs. 2 | namespace foo { 3 | constexpr int a = -2 + ~3; 4 | }; 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr.cc.expected: -------------------------------------------------------------------------------- 1 | // Checks that operator mutations are not applied to constexprs. 2 | namespace foo { 3 | constexpr int a = -2 + ~3; 4 | }; 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // Checks that operator mutations are not applied to constexprs. 2 | namespace foo { 3 | constexpr int a = -2 + ~3; 4 | }; 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr_array.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | const int a = 4; 3 | constexpr char b[a]{}; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr_if1.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | template void foo() { 4 | if constexpr (a) { 5 | std::cout << "Hi"; 6 | }; 7 | } 8 | 9 | int main() { 10 | foo<0>; 11 | } 12 | -------------------------------------------------------------------------------- /test/single_file/constexpr_if1.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 2) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #include 56 | 57 | template void foo() { 58 | if (!__dredd_enabled_mutation(1)) { if constexpr (a) { 59 | if (!__dredd_enabled_mutation(0)) { std::cout << "Hi"; } 60 | }; } 61 | } 62 | 63 | int main() { 64 | foo<0>; 65 | } 66 | -------------------------------------------------------------------------------- /test/single_file/constexpr_if1.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 3) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #include 56 | 57 | template void foo() { 58 | if (!__dredd_enabled_mutation(1)) { if constexpr (a) { 59 | if (!__dredd_enabled_mutation(0)) { std::cout << "Hi"; } 60 | }; } 61 | } 62 | 63 | int main() { 64 | if (!__dredd_enabled_mutation(2)) { foo<0>; } 65 | } 66 | -------------------------------------------------------------------------------- /test/single_file/constexpr_if2.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | if constexpr (1 == 2) { 3 | return 42; 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/constexpr_initializer.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | constexpr int a = 1 + 2; 3 | constexpr int b = a + a; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr_initializer.cc.expected: -------------------------------------------------------------------------------- 1 | void foo() { 2 | constexpr int a = 1 + 2; 3 | constexpr int b = a + a; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/constexpr_initializer.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | void foo() { 2 | constexpr int a = 1 + 2; 3 | constexpr int b = a + a; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/construct_struct_from_enum_constant.cc: -------------------------------------------------------------------------------- 1 | struct foo { 2 | foo(int) {}; 3 | operator int(); 4 | }; 5 | 6 | enum baz { bar }; 7 | 8 | int main() { 9 | 0 ? foo(0) : baz::bar; 10 | } 11 | -------------------------------------------------------------------------------- /test/single_file/decltype_cast.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | unsigned x = (decltype(1)) 'a'; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/decltype_cast_function_call.cc: -------------------------------------------------------------------------------- 1 | long bar() { 2 | return 1LL; 3 | } 4 | 5 | void foo() { 6 | unsigned x = (decltype(bar())) 'a'; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/default_param.cc: -------------------------------------------------------------------------------- 1 | // We do not want the default parameter to be mutated since a lambda 2 | // is not allowed in that context. 3 | void foo(int x = 42) { 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/default_param.cc.expected: -------------------------------------------------------------------------------- 1 | // We do not want the default parameter to be mutated since a lambda 2 | // is not allowed in that context. 3 | void foo(int x = 42) { 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/default_param.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // We do not want the default parameter to be mutated since a lambda 2 | // is not allowed in that context. 3 | void foo(int x = 42) { 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/define_at_start_of_file.c: -------------------------------------------------------------------------------- 1 | #define API 2 | API int func1(); 3 | 4 | int main() { int a = 1; } 5 | -------------------------------------------------------------------------------- /test/single_file/define_at_start_of_file.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 3) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | static int __dredd_replace_expr_int_one(int arg, int local_mutation_id) { 53 | if (!__dredd_some_mutation_enabled) return arg; 54 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~(arg); 55 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return 0; 56 | if (__dredd_enabled_mutation(local_mutation_id + 2)) return -1; 57 | return arg; 58 | } 59 | 60 | #define API 61 | API int func1(); 62 | 63 | int main() { int a = __dredd_replace_expr_int_one(1, 0); } 64 | -------------------------------------------------------------------------------- /test/single_file/define_in_first_decl.c: -------------------------------------------------------------------------------- 1 | #define TYPE int 2 | 3 | TYPE foo() { 4 | return 1 + 2; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/define_in_first_decl.cc: -------------------------------------------------------------------------------- 1 | #define TYPE int 2 | 3 | TYPE foo() { 4 | return 1 + 2; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/do_not_mutate_under_alignof.cc: -------------------------------------------------------------------------------- 1 | int foo(int* x, int y) { 2 | // No mutation inside the `alignof` should occur 3 | return alignof(x[y + 3]) + alignof(y); 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/do_not_mutate_under_sizeof.c: -------------------------------------------------------------------------------- 1 | int foo(int* x, int y) { 2 | // No mutation inside the `sizeof` should occur 3 | return sizeof(x[y + 3]) + sizeof(y); 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/dredd_prelude_start.cc: -------------------------------------------------------------------------------- 1 | class foo { 2 | public: 3 | virtual void bar() = 0; 4 | }; 5 | 6 | class a : foo { 7 | void bar() override; 8 | }; 9 | 10 | void __dredd_prelude_start(); 11 | 12 | void a::bar() { 13 | int x = 2; 14 | } 15 | -------------------------------------------------------------------------------- /test/single_file/enum.c: -------------------------------------------------------------------------------- 1 | enum A { 2 | X, 3 | Y 4 | }; 5 | 6 | void foo() { 7 | enum A myA = X; 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/enum.c.expected: -------------------------------------------------------------------------------- 1 | enum A { 2 | X, 3 | Y 4 | }; 5 | 6 | void foo() { 7 | enum A myA = X; 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/expr_lvalue.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 5; 3 | int y = x; 4 | int z; 5 | z = 6; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/expr_lvalue.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 5; 3 | int y = x; 4 | int z; 5 | z = 6; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.c: -------------------------------------------------------------------------------- 1 | #define E (1, 2, 3) 2 | 3 | void foo(int, int, int); 4 | 5 | int main() { 6 | foo E; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | #define E (1, 2, 3) 53 | 54 | void foo(int, int, int); 55 | 56 | int main() { 57 | if (!__dredd_enabled_mutation(0)) { foo E; } 58 | } 59 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.c.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | #define E (1, 2, 3) 53 | 54 | void foo(int, int, int); 55 | 56 | int main() { 57 | if (!__dredd_enabled_mutation(0)) { foo E; } 58 | } 59 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.cc: -------------------------------------------------------------------------------- 1 | #define E (1, 2, 3) 2 | 3 | void foo(int, int, int); 4 | 5 | int main() { 6 | foo E; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #define E (1, 2, 3) 56 | 57 | void foo(int, int, int); 58 | 59 | int main() { 60 | if (!__dredd_enabled_mutation(0)) { foo E; } 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/expr_macro.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #define E (1, 2, 3) 56 | 57 | void foo(int, int, int); 58 | 59 | int main() { 60 | if (!__dredd_enabled_mutation(0)) { foo E; } 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/float_binary_opts.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | double x = 0.0 + 5.32; 3 | double y = 5.234 + 2.352; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/float_binary_opts.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | double x = 0.0 + 5.32; 3 | double y = 5.234 + 2.352; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/float_unary_opt.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | double x = -1.0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/float_unary_opt.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | double x = -1.0; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/floats.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | double a = 1.0; 3 | double x = 5.32; 4 | x += 0.5; 5 | float y = 64343.7; 6 | y -= 1.2; 7 | double z = x * 5.5; 8 | return z + x; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/floats.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | double a = 1.0; 3 | double x = 5.32; 4 | x += 0.5; 5 | float y = 64343.7; 6 | y -= 1.2; 7 | double z = x * 5.5; 8 | return z + x; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/initializer.c: -------------------------------------------------------------------------------- 1 | void foo(int a, int b) { 2 | int x = a + b; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/initializer.cc: -------------------------------------------------------------------------------- 1 | void foo(int a, int b) { 2 | int x = a + b; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/initializer_list.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | struct A { 4 | size_t x; 5 | size_t y; 6 | }; 7 | 8 | void foo(A arg); 9 | 10 | void bar() { 11 | foo({0, 0}); 12 | } 13 | -------------------------------------------------------------------------------- /test/single_file/initializer_list_long_to_short.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class foo { 4 | public: 5 | foo(std::initializer_list) {} 6 | }; 7 | 8 | int main() { 9 | foo{(long) 2}; 10 | } 11 | -------------------------------------------------------------------------------- /test/single_file/initializer_list_narrower.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | class foo { 4 | public: 5 | foo(std::initializer_list) {} 6 | }; 7 | 8 | int main() { 9 | foo{+2}; 10 | } 11 | -------------------------------------------------------------------------------- /test/single_file/initializer_list_narrower_nested.cc: -------------------------------------------------------------------------------- 1 | struct foo { 2 | short x; 3 | short y; 4 | }; 5 | 6 | void baz() { 7 | foo bar[] = {{1, 2}}; 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/initializer_list_parenthesis.cc: -------------------------------------------------------------------------------- 1 | struct foo { 2 | short x; 3 | short y; 4 | short z; 5 | }; 6 | 7 | void baz() { 8 | foo bar = {1, (2), (((3)))}; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/initializer_list_with_templates.cc: -------------------------------------------------------------------------------- 1 | #include 2 | class a { 3 | public: 4 | a(int); 5 | virtual void b(); 6 | }; 7 | template class c : a { 8 | using a::a; 9 | void b() { 10 | struct { 11 | short d; 12 | } e{0}; 13 | } 14 | }; 15 | 16 | void f() { std::make_shared>(2); } 17 | -------------------------------------------------------------------------------- /test/single_file/initializers_outside_functions.cc: -------------------------------------------------------------------------------- 1 | int x = 1 + 2; 2 | 3 | namespace { 4 | int y = x + x; 5 | 6 | class A { 7 | int z = y + y; 8 | void foo() { 9 | class B { 10 | int w = !x; 11 | }; 12 | } 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /test/single_file/initializers_outside_functions.cc.expected: -------------------------------------------------------------------------------- 1 | int x = 1 + 2; 2 | 3 | namespace { 4 | int y = x + x; 5 | 6 | class A { 7 | int z = y + y; 8 | void foo() { 9 | class B { 10 | int w = !x; 11 | }; 12 | } 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /test/single_file/initializers_outside_functions.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | int x = 1 + 2; 2 | 3 | namespace { 4 | int y = x + x; 5 | 6 | class A { 7 | int z = y + y; 8 | void foo() { 9 | class B { 10 | int w = !x; 11 | }; 12 | } 13 | }; 14 | } 15 | -------------------------------------------------------------------------------- /test/single_file/lambda_capture.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | int x = 2; 3 | // It is important that "x" is not mutated in "[x]" 4 | auto f = [x]() { return x; }; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/left_shift_opt.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 << 1; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/left_shift_opt.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 0 << 1; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/logical_and.c: -------------------------------------------------------------------------------- 1 | int foo(int a, int b) { 2 | return a && b; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/logical_and.cc: -------------------------------------------------------------------------------- 1 | int foo(int a, int b) { 2 | bool c = a; 3 | return c && b; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/logical_and_div.cc: -------------------------------------------------------------------------------- 1 | int foo(int a, int b) { 2 | return (b != 0) && (a / b); 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/logical_or.c: -------------------------------------------------------------------------------- 1 | int foo(int a, int b) { 2 | return a || b; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/logical_or.cc: -------------------------------------------------------------------------------- 1 | int foo(int a, int b) { 2 | bool c = a; 3 | return c || b; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/macro_pasting.c: -------------------------------------------------------------------------------- 1 | #define MINUS - 2 | #define ONE 1 3 | 4 | int a () { 5 | return MINUS ONE; 6 | } 7 | 8 | #define ADD_SUFFIX(X) X##L 9 | 10 | #define NUM_L -ADD_SUFFIX(2) 11 | 12 | int b () { 13 | return NUM_L; 14 | } 15 | 16 | #define ADD_PARENS(X) (X) 17 | 18 | #define NUM_PARENS ADD_PARENS(5) 19 | 20 | int c() { 21 | return NUM_PARENS; 22 | } 23 | -------------------------------------------------------------------------------- /test/single_file/misc001.cc: -------------------------------------------------------------------------------- 1 | template class a { 2 | void operator+() { a b(this); } 3 | }; 4 | -------------------------------------------------------------------------------- /test/single_file/misc001.cc.expected: -------------------------------------------------------------------------------- 1 | template class a { 2 | void operator+() { a b(this); } 3 | }; 4 | -------------------------------------------------------------------------------- /test/single_file/misc001.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | template class a { 2 | void operator+() { a b(this); } 3 | }; 4 | -------------------------------------------------------------------------------- /test/single_file/misc002.cc: -------------------------------------------------------------------------------- 1 | void f() { 2 | if (8 == 24) 3 | ; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/misc003.cc: -------------------------------------------------------------------------------- 1 | void f(){ 2 | try { 3 | } catch (...) { 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/misc003.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | void f(){ 56 | if (!__dredd_enabled_mutation(0)) { try { 57 | } catch (...) { 58 | } } 59 | } 60 | -------------------------------------------------------------------------------- /test/single_file/misc003.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 1) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | void f(){ 56 | if (!__dredd_enabled_mutation(0)) { try { 57 | } catch (...) { 58 | } } 59 | } 60 | -------------------------------------------------------------------------------- /test/single_file/misc004.cc: -------------------------------------------------------------------------------- 1 | #if defined(__GLIBC__) && !defined(__FreeBSD_kernel__) && defined(__CONFIG_H__) 2 | # error test.h must be #included before system headers 3 | #endif 4 | 5 | void __dredd_prelude_start(); 6 | 7 | int main() { 8 | int x = 1 + 2; 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/negative_switch_case.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | switch(0) { 3 | case -1: 4 | break; 5 | default: 6 | break; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/negative_switch_case.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 5) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | static int __dredd_replace_expr_int_zero(int arg, int local_mutation_id) { 53 | if (!__dredd_some_mutation_enabled) return arg; 54 | if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1; 55 | if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1; 56 | return arg; 57 | } 58 | 59 | int main() { 60 | if (!__dredd_enabled_mutation(4)) { switch(__dredd_replace_expr_int_zero(0, 0)) { 61 | case -1: 62 | if (!__dredd_enabled_mutation(2)) { break; } 63 | default: 64 | if (!__dredd_enabled_mutation(3)) { break; } 65 | } } 66 | } 67 | -------------------------------------------------------------------------------- /test/single_file/negative_switch_case.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | switch(0) { 3 | case -1: 4 | break; 5 | default: 6 | break; 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/nested_array_with_named_constant_size_rewrite.cc: -------------------------------------------------------------------------------- 1 | void a() { 2 | const int a = 1; 3 | const int b = 2; 4 | const int c = 3; 5 | static int d[a][b][c][a][b][c]; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/new_expr_array_size.cc: -------------------------------------------------------------------------------- 1 | class foo { 2 | public: 3 | foo(int x) {} 4 | }; 5 | 6 | int main() { 7 | new foo[2]{4, 5}; 8 | } 9 | -------------------------------------------------------------------------------- /test/single_file/nodiscard.cc: -------------------------------------------------------------------------------- 1 | [[nodiscard]] static int foo() { 2 | return 42; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/nodiscard_macro.cc: -------------------------------------------------------------------------------- 1 | #define NODISCARD [[nodiscard]] 2 | 3 | NODISCARD static int foo() { 4 | return 42; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/noexcept.cc: -------------------------------------------------------------------------------- 1 | void foo() noexcept(true); 2 | -------------------------------------------------------------------------------- /test/single_file/noexcept.cc.expected: -------------------------------------------------------------------------------- 1 | void foo() noexcept(true); 2 | -------------------------------------------------------------------------------- /test/single_file/noexcept.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | void foo() noexcept(true); 2 | -------------------------------------------------------------------------------- /test/single_file/noexcept2.cc: -------------------------------------------------------------------------------- 1 | template void b() noexcept(noexcept(a())); 2 | -------------------------------------------------------------------------------- /test/single_file/noexcept2.cc.expected: -------------------------------------------------------------------------------- 1 | template void b() noexcept(noexcept(a())); 2 | -------------------------------------------------------------------------------- /test/single_file/noexcept2.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | template void b() noexcept(noexcept(a())); 2 | -------------------------------------------------------------------------------- /test/single_file/non_const_sized_array.c: -------------------------------------------------------------------------------- 1 | void foo() { 2 | volatile int x = 5; 3 | int A[x + x]; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/non_const_sized_array.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | volatile int x = 5; 3 | int A[x + x]; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/noreturn.cc: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | [[noreturn]] static int foo() { 5 | std::cout << "Aborting\n"; 6 | std::abort(); 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/noreturn.cc.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 2) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #include 56 | #include 57 | 58 | [[noreturn]] static int foo() { 59 | if (!__dredd_enabled_mutation(0)) { std::cout << "Aborting\n"; } 60 | if (!__dredd_enabled_mutation(1)) { std::abort(); } 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/noreturn.cc.noopt.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | #ifdef _MSC_VER 18 | #define thread_local __declspec(thread) 19 | #elif __APPLE__ 20 | #define thread_local __thread 21 | #endif 22 | 23 | static thread_local bool __dredd_some_mutation_enabled = true; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local bool initialized = false; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | bool some_mutation_enabled = false; 29 | const char* dredd_environment_variable = std::getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable != nullptr) { 31 | std::string contents(dredd_environment_variable); 32 | while (true) { 33 | size_t pos = contents.find(","); 34 | std::string token = (pos == std::string::npos ? contents : contents.substr(0, pos)); 35 | if (!token.empty()) { 36 | int value = std::stoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 2) { 39 | enabled_bitset[local_value / 64] |= (static_cast(1) << (local_value % 64)); 40 | some_mutation_enabled = true; 41 | } 42 | } 43 | if (pos == std::string::npos) { 44 | break; 45 | } 46 | contents.erase(0, pos + 1); 47 | } 48 | } 49 | initialized = true; 50 | __dredd_some_mutation_enabled = some_mutation_enabled; 51 | } 52 | return (enabled_bitset[local_mutation_id / 64] & (static_cast(1) << (local_mutation_id % 64))) != 0; 53 | } 54 | 55 | #include 56 | #include 57 | 58 | [[noreturn]] static int foo() { 59 | if (!__dredd_enabled_mutation(0)) { std::cout << "Aborting\n"; } 60 | if (!__dredd_enabled_mutation(1)) { std::abort(); } 61 | } 62 | -------------------------------------------------------------------------------- /test/single_file/parens.cc: -------------------------------------------------------------------------------- 1 | int foo(int x) { 2 | return ((x)); 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/positive_int_as_minus_one.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | unsigned int x = 4294967295; 3 | int y = x - 20; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/positive_int_as_minus_one.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | unsigned int x = 4294967295; 3 | int y = x - 20; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/post_inc_volatile.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | volatile int x = 9; 3 | volatile int y = 43; 4 | int z; 5 | z = x++ + y++; 6 | return z; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/post_inc_volatile.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | volatile int x = 9; 3 | volatile int y = 43; 4 | int z; 5 | z = x++ + y++; 6 | return z; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/pre_dec_assign.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 5; 3 | --x = 2; 4 | volatile int y = 8; 5 | --y = 6; 6 | return x; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/preprocessor_if.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | 3 | int ABC; 4 | 5 | ABC = 2 6 | #if 1 7 | | 5 8 | #endif 9 | ; 10 | 11 | } 12 | -------------------------------------------------------------------------------- /test/single_file/printing.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | printf("%s\n", "A\n"); 5 | printf("%s\n", "B\n"); 6 | printf("%s\n", "C\n"); 7 | printf("%s\n", "D\n"); 8 | printf("%s\n", "E\n"); 9 | printf("%s\n", "F\n"); 10 | printf("%s\n", "G\n"); 11 | } 12 | -------------------------------------------------------------------------------- /test/single_file/printing.c.expected: -------------------------------------------------------------------------------- 1 | // DREDD PRELUDE START 2 | // If this has been inserted at an inappropriate place in a source file, 3 | // declare a placeholder function with the following signature to 4 | // mandate where the prelude should be placed: 5 | // 6 | // void __dredd_prelude_start(); 7 | // 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | 15 | #ifdef _MSC_VER 16 | #define thread_local __declspec(thread) 17 | #elif __APPLE__ 18 | #define thread_local __thread 19 | #else 20 | #include 21 | #endif 22 | 23 | static thread_local int __dredd_some_mutation_enabled = 1; 24 | static bool __dredd_enabled_mutation(int local_mutation_id) { 25 | static thread_local int initialized = 0; 26 | static thread_local uint64_t enabled_bitset[1]; 27 | if (!initialized) { 28 | int some_mutation_enabled = 0; 29 | const char* dredd_environment_variable = getenv("DREDD_ENABLED_MUTATION"); 30 | if (dredd_environment_variable) { 31 | char* temp = malloc(strlen(dredd_environment_variable) + 1); 32 | strcpy(temp, dredd_environment_variable); 33 | char* token; 34 | token = strtok(temp, ","); 35 | while(token) { 36 | int value = atoi(token); 37 | int local_value = value - 0; 38 | if (local_value >= 0 && local_value < 7) { 39 | enabled_bitset[local_value / 64] |= ((uint64_t) 1 << (local_value % 64)); 40 | some_mutation_enabled = 1; 41 | } 42 | token = strtok(NULL, ","); 43 | } 44 | free(temp); 45 | } 46 | initialized = 1; 47 | __dredd_some_mutation_enabled = some_mutation_enabled; 48 | } 49 | return enabled_bitset[local_mutation_id / 64] & ((uint64_t) 1 << (local_mutation_id % 64)); 50 | } 51 | 52 | #include 53 | 54 | int main() { 55 | if (!__dredd_enabled_mutation(0)) { printf("%s\n", "A\n"); } 56 | if (!__dredd_enabled_mutation(1)) { printf("%s\n", "B\n"); } 57 | if (!__dredd_enabled_mutation(2)) { printf("%s\n", "C\n"); } 58 | if (!__dredd_enabled_mutation(3)) { printf("%s\n", "D\n"); } 59 | if (!__dredd_enabled_mutation(4)) { printf("%s\n", "E\n"); } 60 | if (!__dredd_enabled_mutation(5)) { printf("%s\n", "F\n"); } 61 | if (!__dredd_enabled_mutation(6)) { printf("%s\n", "G\n"); } 62 | } 63 | -------------------------------------------------------------------------------- /test/single_file/printing.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | std::cout << "A\n"; 5 | std::cout << "B\n"; 6 | std::cout << "C\n"; 7 | std::cout << "D\n"; 8 | std::cout << "E\n"; 9 | std::cout << "F\n"; 10 | std::cout << "G\n"; 11 | } 12 | -------------------------------------------------------------------------------- /test/single_file/signed_int_constants.cc: -------------------------------------------------------------------------------- 1 | void foo(int a) { 2 | const int x = 0; 3 | const int y = 1; 4 | const int z = -1; 5 | const int w = 2; 6 | const int v = a; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/sizeof_template.cc: -------------------------------------------------------------------------------- 1 | template void b() { a(sizeof(a)); } 2 | -------------------------------------------------------------------------------- /test/single_file/sizeof_template2.cc: -------------------------------------------------------------------------------- 1 | bool f(int); 2 | 3 | template struct b { 4 | bool c() { return f(sizeof(a)); } 5 | }; 6 | -------------------------------------------------------------------------------- /test/single_file/space_needed_after_macro.c: -------------------------------------------------------------------------------- 1 | #define BEGIN x = 2 | 3 | int main() { 4 | int x, y; 5 | BEGIN(y); 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/space_needed_after_macro2.c: -------------------------------------------------------------------------------- 1 | #define BEGIN_ x = 2 | 3 | int main() { 4 | int x, y; 5 | BEGIN_(y); 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/static_assert_rewrite.cc: -------------------------------------------------------------------------------- 1 | int foo() { 2 | const int a = 42; 3 | static_assert(a); 4 | return a; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/static_constexpr_array.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | const int a = 4; 3 | static constexpr char b[a]{}; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/static_initializer.c: -------------------------------------------------------------------------------- 1 | void foo() { 2 | static int a = 1 + 2; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/static_initializer.c.expected: -------------------------------------------------------------------------------- 1 | void foo() { 2 | static int a = 1 + 2; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/static_initializer.c.noopt.expected: -------------------------------------------------------------------------------- 1 | void foo() { 2 | static int a = 1 + 2; 3 | } 4 | -------------------------------------------------------------------------------- /test/single_file/static_initializer.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | int b = 0; 3 | int c = 0; 4 | static int a = b + c; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/struct_field_array_constant_size_rewrite.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | const int a = 42; 3 | struct b { 4 | int bar[a]; 5 | }; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/structured_binding.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | int a[2] = {1, 2}; 3 | if (true) { 4 | auto [x, y] = a; 5 | auto& [xr, yr] = a; 6 | xr = y++; 7 | yr = x++; 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/switch_cases1.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x = 10; 5 | switch (x) { 6 | case 2: 7 | printf("bar\n"); 8 | printf("buz\n"); 9 | default: 10 | printf("baz\n"); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /test/single_file/switch_cases2.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | int x = 10; 5 | switch (x) { 6 | case 2: 7 | case 3: 8 | case 4: 9 | printf("bar\n"); 10 | printf("buz\n"); 11 | case 5: 12 | default: 13 | printf("baz\n"); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /test/single_file/template.cc: -------------------------------------------------------------------------------- 1 | template 2 | T foo(T a) { 3 | return a + 2; 4 | } 5 | 6 | void foo() { 7 | int x; 8 | x = foo(3); 9 | } 10 | -------------------------------------------------------------------------------- /test/single_file/template_instantiation.cc: -------------------------------------------------------------------------------- 1 | template void foo() { 2 | int A[N] = {0}; 3 | } 4 | 5 | int main() { 6 | foo<1 + 2>(); 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/template_instantiation_const_expr.cc: -------------------------------------------------------------------------------- 1 | template 2 | class bar {}; 3 | 4 | void foo() { 5 | const int count = 42; 6 | bar a; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/template_instantiation_nested_const_expr.cc: -------------------------------------------------------------------------------- 1 | template 2 | class bar {}; 3 | 4 | void foo() { 5 | const int count = 42; 6 | bar, count> a; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/template_instantiation_non_integer_expr.cc: -------------------------------------------------------------------------------- 1 | template struct b; 2 | template b d; 3 | 4 | void foo() { 5 | int x = 42; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/typedef.c: -------------------------------------------------------------------------------- 1 | typedef struct S { 2 | int x; 3 | } SomeS; 4 | 5 | void foo() { 6 | 1 + 2; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/typedef.c.expected: -------------------------------------------------------------------------------- 1 | typedef struct S { 2 | int x; 3 | } SomeS; 4 | 5 | void foo() { 6 | 1 + 2; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/typedef.cc: -------------------------------------------------------------------------------- 1 | typedef struct S { 2 | int x; 3 | } SomeS; 4 | 5 | void foo() { 6 | 1 + 2; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/typedef.cc.expected: -------------------------------------------------------------------------------- 1 | typedef struct S { 2 | int x; 3 | } SomeS; 4 | 5 | void foo() { 6 | 1 + 2; 7 | } 8 | -------------------------------------------------------------------------------- /test/single_file/unary.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 3; 3 | float y = 3.532; 4 | x++; 5 | y++; 6 | ++x; 7 | ++y; 8 | --x; 9 | --y; 10 | x--; 11 | y--; 12 | return -x; 13 | } 14 | -------------------------------------------------------------------------------- /test/single_file/unary.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 3; 3 | float y = 3.532; 4 | x++; 5 | y++; 6 | ++x; 7 | ++y; 8 | --x; 9 | --y; 10 | x--; 11 | y--; 12 | return -x; 13 | } 14 | -------------------------------------------------------------------------------- /test/single_file/unary_logical_not.c: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int main() { 4 | bool y = true; 5 | return !y; 6 | } 7 | -------------------------------------------------------------------------------- /test/single_file/unary_logical_not.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | bool y = true; 3 | return !y; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/unary_minus.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | return -x; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/unary_minus.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = 1; 3 | return -x; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/unary_operator_opt.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | int x = ~0; 3 | int y = ~1; 4 | int z = ~(-1); 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/unsigned_int.c: -------------------------------------------------------------------------------- 1 | int main() { 2 | unsigned int x = !0; 3 | unsigned int y = ~7; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/unsigned_int.cc: -------------------------------------------------------------------------------- 1 | int main() { 2 | unsigned int x = !0; 3 | unsigned int y = ~7; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/user_defined_literals.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | // Number wraps integer, enforcing explicit casting 4 | struct Number { 5 | 6 | uint32_t value = {}; 7 | 8 | explicit Number(unsigned long long int v) : value(static_cast(v)) {} 9 | 10 | }; 11 | 12 | using u32 = Number; 13 | 14 | inline u32 operator""_u(unsigned long long int value) { 15 | return u32(static_cast(value)); 16 | } 17 | 18 | int main() { 19 | 20 | u32 foo = 1_u; 21 | 22 | return 0; 23 | } 24 | -------------------------------------------------------------------------------- /test/single_file/using.cc: -------------------------------------------------------------------------------- 1 | using blah = int; 2 | 3 | void foo() { 4 | 1 + 2; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/using.cc.expected: -------------------------------------------------------------------------------- 1 | using blah = int; 2 | 3 | void foo() { 4 | 1 + 2; 5 | } 6 | -------------------------------------------------------------------------------- /test/single_file/vector_returns_temporary.cc: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | std::vector bar() { 4 | std::vector res(4); 5 | return res; 6 | } 7 | 8 | int main() { 9 | unsigned foo = bar()[0]; 10 | } 11 | -------------------------------------------------------------------------------- /test/single_file/volatile.c: -------------------------------------------------------------------------------- 1 | void foo() { 2 | volatile int a; 3 | a += 2; 4 | } 5 | -------------------------------------------------------------------------------- /test/single_file/volatile.cc: -------------------------------------------------------------------------------- 1 | void foo() { 2 | volatile int a; 3 | a += 2; 4 | } 5 | -------------------------------------------------------------------------------- /third_party/.gitignore: -------------------------------------------------------------------------------- 1 | # Projects built by Dredd's CI, which it can be convenient to 2 | # check out locally. 3 | curl 4 | llvm-project 5 | SPIRV-Tools 6 | zstd 7 | -------------------------------------------------------------------------------- /third_party/clang+llvm/.gitignore: -------------------------------------------------------------------------------- 1 | * 2 | -------------------------------------------------------------------------------- /third_party/googletest/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.13) 16 | 17 | # 18 | # Project: googletest-distribution 19 | # 20 | # Provides targets: gtest, gtest_main. 21 | # 22 | if(NOT TARGET gtest) 23 | if(NOT IS_DIRECTORY ${DREDD_GOOGLETEST_REPO_DIR}) 24 | message( 25 | FATAL_ERROR 26 | "Could not find googletest-distribution at \ 27 | ${DREDD_GOOGLETEST_REPO_DIR}. " 28 | "Try fetching submodules or set DREDD_GOOGLETEST_REPO_DIR.") 29 | endif() 30 | 31 | set(BUILD_GMOCK 32 | OFF 33 | CACHE BOOL "Builds the googlemock subproject") 34 | 35 | set(INSTALL_GTEST 36 | OFF 37 | CACHE BOOL "Enable installation of googletest. \ 38 | (Projects embedding googletest may want to turn this OFF.)") 39 | 40 | # cmake-lint: disable=C0103 41 | set(gtest_force_shared_crt 42 | ON 43 | CACHE BOOL "Use shared (DLL) run-time lib even when Google Test \ 44 | is built as static lib.") 45 | 46 | add_subdirectory(${DREDD_GOOGLETEST_REPO_DIR} EXCLUDE_FROM_ALL) 47 | endif() 48 | -------------------------------------------------------------------------------- /third_party/protobuf/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Copyright 2022 The Dredd Project Authors 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | cmake_minimum_required(VERSION 3.13) 16 | 17 | # 18 | # Project: protobuf 19 | # 20 | # Provides targets: protobuf::protoc, protobuf::libprotobuf. 21 | # 22 | if(NOT TARGET protobuf) 23 | if(NOT IS_DIRECTORY ${DREDD_PROTOBUF_REPO_DIR}) 24 | message( 25 | FATAL_ERROR "Could not find protobuf at ${DREDD_PROTOBUF_REPO_DIR}. " 26 | "Try fetching submodules or set DREDD_PROTOBUF_REPO_DIR.") 27 | endif() 28 | 29 | # cmake-lint: disable=C0103 30 | set(protobuf_BUILD_TESTS 31 | OFF 32 | CACHE BOOL "Disable protobuf tests") 33 | set(protobuf_MSVC_STATIC_RUNTIME 34 | OFF 35 | CACHE BOOL "Do not build protobuf static runtime") 36 | 37 | add_subdirectory(${DREDD_PROTOBUF_REPO_DIR} EXCLUDE_FROM_ALL) 38 | endif() 39 | --------------------------------------------------------------------------------