mc-imperial / dredd

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

dredd Incorrectly Handles Macro Expansion #239

Closed JonathanFoo0523 closed 2 months ago

JonathanFoo0523 commented 3 months ago

Minimal Reproducible Example

#define BEGIN x = 

int main() {
  int x, y;
  BEGIN(y);
}

dredd output

/* DREDD PRELUDE */

#define BEGIN x = 

int main() {
  int x, y;
  if (!__dredd_enabled_mutation(6)) { BEGIN__dredd_replace_expr_int((y), 0); }
}

where BEGIN__dredd_replace_expr_int causes an error.

afd commented 2 months ago

Dredd is doing the right thing here, except that it needs to insert a space before __dredd_replace_expr_int, because otherwise this is immediately preceded by the BEGIN token.

A solution would be to find the source location loc immediately preceding the begin source location for the (y) expression, and if loc is found not to be in the main source file (which is deemed to be the case for macros) to insert a space.

Another solution would be to always insert a space, but that would seem like overkill.

I'll look into the first.