I wrote this function, lvalue is 64bit integer:
__attribute__ ((noinline)) lvalue call_method(method_t *method, lvalue *args) {
lvalue (*func)(lvalue *) = method->func;
return func(args);
}
where method->func
is something like:
static lvalue func(lvalue* args) {
return args[1];
}
however when this get compiled with -O0(or any level), the args
in func
is wrong, I checked the assembly code and it turns call_method
to something like:
void call_method(lvalue* retval, method_t *method, lvalue *args) {
lvalue (*func)(lvalue *) = method->func;
func(retval, args);
}
I am assume this is the optimization from gcc to avoid using two registers for 64bit value. It's ok when you directly call func
, but when call it by method->func
, it doesn't change the arguments for func
as it does for call_method
, so the args
in func
is actually retval
.
How can I prevent gcc from add retval
parameter to call_method
?