Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22002

gcc add unwanted parameter to function [closed]

$
0
0

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?


Viewing all articles
Browse latest Browse all 22002

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>