#144 __builtin_return returns bad result

OTHER
closed
Danny Smith
gcc (462)
later
Known_bugs
2013-01-30
2002-05-28
No

Hello,

I am using new version of gcc3.1,
Please see my example.
It works properly on gcc2.95-2 and gcc 2.95-3

$ gcc -v
Reading specs from d:/mingw_new1/bin/../lib/gcc-
lib/mingw32/3.1/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-ld -
-with-gnu-as --host=
mingw32 --target=mingw32 --prefix=/mingw --enable-
threads --disable-nls --enable
-languages=f77,c++,objc,ada --disable-win32-registry --
disable-shared
Thread model: win32
gcc version 3.1
$ cat bug.m
#include <objc/objc-api.h>
#include <objc/Object.h>

@interface MyObject : Object
- (void *) print:(void *) value;
@end

@implementation MyObject
- (void *) print:(void *) value
{
printf("-[MyObject print: 0x%x]\n",value);
return (void*)((int)value+1);
}
@end

id objc_msg_send_named(id object, char *opname, ...)
{
SEL op = sel_get_uid (opname);
Method* m = class_get_instance_method(object-
>class_pointer, op);
IMP imp = objc_msg_lookup (object, op);
arglist_t args;
retval_t result;

if (!m) return nil;

args = __builtin_apply_args();
result = __builtin_apply((apply_t)imp, args,
method_get_sizeof_arguments (m));
__builtin_return (result);
}

int main()
{
MyObject * obj = [MyObject new];
void * addr = (void*)0xFFFFFFEF;

printf("-[obj print:0x%x] : 0x%x\n",addr,[obj print:(void
*)addr]);

printf("objc_msg_send_named :0x%
x\n",objc_msg_send_named(obj,"print:",addr));

return 0;
}
$ gcc bug.m -lobjc
$ a.exe
-[MyObject print: 0xffffffef]
-[obj print:0xffffffef] : 0xfffffff0
-[MyObject print: 0xffffffef]
objc_msg_send_named :0x3d5af6

# 0x3d5af6 it is incorrect result, I expect 0xfffffff0
# And if I comment this line " if (!m) return nil;"
# then test works properly

$ a.exe
-[MyObject print: 0xffffffef]
-[obj print:0xffffffef] : 0xfffffff0
-[MyObject print: 0xffffffef]
objc_msg_send_named :0xfffffff0

Thanks a lot.
Aleksey

Discussion

  • Danny Smith
    Danny Smith
    2002-05-28

    Logged In: YES
    user_id=11494

    I've confirmed the bug. Thanks for the report and the
    testcase.

    I'm rebuilding gcc now to test for a posssible fix to the
    bug.

    Danny

     
  • Danny Smith
    Danny Smith
    2002-05-30

    Logged In: YES
    user_id=11494

    Sorry, that bug is not going to be easy to fix. If you
    search the GCC archives, you'll see that __builtin_aplly
    and friends has caused problems for some time on
    several systems. I think with 3.1 the problem affects
    most sytems, particuarly when used with variable sized
    structures. See for example this thread:
    http://gcc.gnu.org/ml/gcc-bugs/2002-
    03/msg00988.html

    I'll keep this bug in mind, but it mayt pay to follow up
    on ObjC list or GCC lists.

    Danny

     
  • Earnie Boyd
    Earnie Boyd
    2002-08-05

    • priority: 5 --> 1
    • status: open --> closed-remind
     
  • Earnie Boyd
    Earnie Boyd
    2013-01-30

    • status: closed-remind --> closed
    • resolution: --> later
    • category: --> Known_bugs
    • milestone: Feature_requests --> OTHER