Closed JonathanFoo0523 closed 1 month ago
Note that +
in +2
is required to replicate the issue. Otherwise, Dredd will not mutate the expression 2
, and thus avoid this issue.
While we can reduce this bug by avoiding mutation of expression in such case, I think this approach will further reduce the number of mutants.
Is it possible to change the prelude function to a templated version
template <typename T>
static T __dredd_replace_expr_int_like_constant(T arg, int local_mutation_id) {
if (!__dredd_some_mutation_enabled) return arg;
if (__dredd_enabled_mutation(local_mutation_id + 0)) return ~(arg);
if (__dredd_enabled_mutation(local_mutation_id + 1)) return -(arg);
if (__dredd_enabled_mutation(local_mutation_id + 2)) return 0;
if (__dredd_enabled_mutation(local_mutation_id + 3)) return 1;
if (__dredd_enabled_mutation(local_mutation_id + 4)) return -1;
return arg;
}
and mutate the fault-causing expression to:
+__dredd_replace_expr_int_like_constant<uint64_t>(2, 0)
I am worried that having templated mutator functions may end up getting very complicated and leading to unexpected issues. On the other hand, it might actually turn out to provide a simple and elegant solution to certain issues. @JonathanFoo0523 can you experiment with the template idea?
If it turns out to be non-trivial then I would prefer to work around this by detecting the special case and avoiding a mutation in that special case, and opening a "stretch goal" issue to consider a better solution in the longer term.
A slightly simpler example
#include <initializer_list>
class foo {
public:
foo(std::initializer_list<unsigned int>) {}
};
int main() {
foo{+2};
}
Another Example:
struct a {
short b;
};
a c() { return {6 * 4}; }
Applying Dredd to
change the sole statement in
main()
toThis causes the following compilation error: