Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Generate templated mutator function in C++ program #282

Open
JonathanFoo0523 opened this issue Jul 13, 2024 · 0 comments
Open

Generate templated mutator function in C++ program #282

JonathanFoo0523 opened this issue Jul 13, 2024 · 0 comments
Assignees
Labels
enhancement New feature or request

Comments

@JonathanFoo0523
Copy link
Collaborator

JonathanFoo0523 commented Jul 13, 2024

Several bugs (#264, #270) have been discovered in Dredd due to the mutation of certain expressions forcing a type on the expression.

This test case taken from the single file test of PR #267 capture this issue:

struct foo {
  foo(int) {};
  operator int();
};

enum baz { bar };

int main() { 
  0 ? foo(0) : baz::bar;
}

Here, the bar::baz constant is used to implicitly construct a C++ object, while foo() has an int operator overload. The ternary expression have a type of foo(). Dredd would mutated baz::bar; to __dredd_replace_expr_int_zero(baz::bar, 3);, which cause ambiguity on the final type of resultant expression. PR #267 addressed this issue by detecting this special case and avoid mutation on the enum constant.

We might be able to solve this issue by using templated static function. For instance,

template <typename T> 
static T __dredd_replace_expr_int_like_zero(T arg, int local_mutation_id) {
  if (!__dredd_some_mutation_enabled) return arg;
  if (__dredd_enabled_mutation(local_mutation_id + 0)) return 1;
  if (__dredd_enabled_mutation(local_mutation_id + 1)) return -1;
  return arg;
}

Since the final type of resultant expression is exposed in the AST, we can then use this information to mutate the expression:

__dredd_replace_expr_int_like_zero<foo>(baz::bar, 3)

This might offer an elegant fix for some of the bugs, while still allowing for mutation in these cases.

@JonathanFoo0523 JonathanFoo0523 self-assigned this Jul 13, 2024
@JonathanFoo0523 JonathanFoo0523 added the enhancement New feature or request label Jul 13, 2024
@JonathanFoo0523 JonathanFoo0523 changed the title Generate templated mutator function in C++ Generate templated mutator function in C++ program Jul 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant