Assume this code snippet:
int test(int input){
// using asm() manually populate the `return register` with `input` and return.
}
int main(){
return test(-1);
}
Assume we write our own assembly code to populate the return register under test.
The 64 bit return register is set to -1 sign extended to 64 bits which is 0xFFFFFFFFFFFFFFFF but the return type is a 32 bit int (i.e the expected value in register should be 0xFFFFFFFF).
My question is, according to C, is it the responsibility of test() to return the correct
value in the register OR is it the responsibility of callee (main in this case) to cast the returned value correctly and truncate it if needed?
Or in other words, is test supposed to make sure the register value is set to 0xFFFFFFFF and not 0xFFFFFFFFFFFFFFFF before returning?