------- Comment #1 from joseph at codesourcery dot com  2009-08-03 19:16 -------
Subject: Re:   New: Type-checking when returning from function
 missing

On Mon, 3 Aug 2009, pratik dot j dot ashar at intel dot com wrote:

> Function foo() returns a char to the caller. Running objdump on the compiled
> executable shows foo() doesnt do any type-checking before returning to caller,
> int main() in this case. foo() returns 0xffffff00 in eax as opposed to only 
> 00.
> ISO C99 std states and I quote "If a return statement with an expression is
> executed, the value of the expression is returned to the caller as the value 
> of
> the function call expression. If the expression has a type different from the
> return type of the function in which it appears, the value is converted as if
> by assignment to an object having the return type of the function." The link 
> to
> spec is http://www.open-std.org/jtc1/sc22/wg14/www/docs/n1336.pdf. return
> semantics mentioned on pg 153.
> 
> This bug does not manifest itself in given code since the caller does
> type-checking. We were calling foo() via a JNI bridge. Thats when we traced
> this bug.

It seems to be unclear what the x86 ABI requires for return values (see 
bug 32843, and the thread linked from there, for example).  This is 
certainly an ABI (back end) issue and nothing to do with the front ends.  
Unfortunately there is no committee maintaining the x86 ABI that can reach 
decisions on unclear issues and old ABI documents are of little value; 
determining the ABI involves examining what different implementations do.  
When this was discussed on the ia32-abi group 
<http://groups.google.com/group/ia32-abi/browse_thread/thread/f47e0106b21d9269> 
the answer was that GCC, ICC and MSVC all treat the upper bits of the 
return value as undefined, which indicates that that must be treated as 
the ABI and so your JNI bridge is buggy.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40951

Reply via email to