mc-imperial / dredd

Framework for evaluating C/C++ compiler testing tools
Apache License 2.0
11 stars 3 forks source link

dredd apply mutation to expression used in variable initialisation with `const` qualifier #263

Closed JonathanFoo0523 closed 1 month ago

JonathanFoo0523 commented 1 month ago

Applying dredd to the following file

void a() {
  const int b = 2;
  int c[b]{};
}

produce

void a() {
  const int b = __dredd_replace_expr_int_constant(42, 0);
  int c[b]{};
}

This result in compilation error:

variable-sized object may not be initialized
afd commented 1 month ago

This is a tough one. It would seem rather restrictive to never mutate the initializer expressions for constants just in case they are used as sizes for arrays. But understanding which constants are used for such purposes could be difficult.

afd commented 1 month ago

In the AST (obtained using --dump-asts) the array c has size 2, rather than size b. It looks like the front-end has rewritten b as 2. Therefore there's actually no way we can detect this via AST analysis.

One possibility would be to rewrite b to 2 as part of the mutation process, so that the declared constant b is decoupled from its use as an array size.

That would be a non-trivial change, though.