mc-imperial / dredd

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

Dredd mutate expression in `__builtin_frame_address()` #289

Closed JonathanFoo0523 closed 1 month ago

JonathanFoo0523 commented 1 month ago

Dredd mutates the __builtin_frame_address() in

void foo() {
    __builtin_frame_address(0);
}

to

__builtin_frame_address(__dredd_replace_expr_unsigned_int_zero(0, 0));

leading to compilation error:

argument to '__builtin_frame_address' must be a constant integer
JonathanFoo0523 commented 1 month ago

Avoiding mutation inside __builtin_frame_address() is not sufficient. Here's another example:

void foo() {
    const int x = 0;
    __builtin_frame_address(x);
}

compiles.

But the following doesn't:

void foo() {
    const int x = __dredd_replace_expr_int_zero(0, 0);
    if (!__dredd_enabled_mutation(4)) { __builtin_frame_address(x); }
}

with the same compilation error as previous.

JonathanFoo0523 commented 1 month ago

We probably need some kind of rewriting as done by #273

afd commented 1 month ago

@JonathanFoo0523 Feel free to have a go at fixing this via rewriting, as per #273 - though please see #287 first, which changes the approach of #273 a bit. If you can review #287 then we can get it merged.

JonathanFoo0523 commented 1 month ago

It seems that not all __builtin_func() calls require the argument to be a constant integer. However, we don't have an easy way to check if a function argument must be a constant integer (at least to my knowledge).

@afd, is it okay to specifically check for the __builtin_frame_address() function call and replace its argument expression? We might encounter other __builtin_func() calls that require a constant integer in the future.

afd commented 1 month ago

Yes, please check specifically for __builtin_frame_address() for now, and we can add other builtin functions that turn out to require constant arguments as and when we find them.