NSinvocation returns incorrect double result on arm64

Originator:jl.jumpertz
Number:rdar://15487407 Date Originated:16-Nov-2013 06:07 PM
Status:Fixed - Duplicate of 15441632 Resolved:iOS 7.1 beta 2 - Build: 11D5115d
Product:iOS Product Version:7.0.4 (11B554a)
Classification:1-high Reproducible:Always
 
Summary:
Invoking with NSInvocation a method returning a double (or CGFloat) value on an arm64 device returns 0 instead of the result returned by the method.

Steps to Reproduce:
1. With Xcode create an empty application
2. In the AppDelegate class, set the code as in the attached file CDVAppDelegate.m:
- define a simple method getAFloat as:

     - (CGFloat) getAFloat {
         return 1.0;
     }

 - in method application:didFinishLaunchingWithOptions: add the following code

    SEL methodSelector = @selector(getAFloat);
    NSMethodSignature* methodSignature = [self methodSignatureForSelector:methodSelector];
    NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:methodSignature];
    
    [invocation setTarget:self];
    [invocation setSelector:methodSelector];
    [invocation invoke];
    
    CGFloat returnValue = 0.0;
    [invocation getReturnValue:&returnValue];
    
    NSLog(@"Invocation return value: %f; getAFloat return value: %f", (double)returnValue, [self getAFloat]);

3. run the application


Expected Results:
The app log should display:
Invocation return value: 1.000000; getAFloat return value: 1.000000

Actual Results:
The app log actually displays:
Invocation return value: 0.000000; getAFloat return value: 1.000000

Version:
iOS version: 7.0.4 (11B554a)

Notes:
The problem may be located in the class NSMethodSignature, as displaying the description of variable methodSignature in the sample code prints an incorrect result offset:

(lldb) po methodSignature
<NSMethodSignature: 0x170079640>
    number of arguments = 2
    frame size = 224
    is special struct return? NO
    return value: -------- -------- -------- --------
        type encoding (d) 'd'
        flags {isFloat}
        modifiers {}
        frame {offset = 80, offset adjust = 248, size = 16, size adjust = 0}
        memory {offset = 0, size = 8}
    argument 0: -------- -------- -------- --------
        type encoding (@) '@'
        flags {isObject}
        modifiers {}
        frame {offset = 0, offset adjust = 0, size = 8, size adjust = 0}
        memory {offset = 0, size = 8}
    argument 1: -------- -------- -------- --------
        type encoding (:) ':'
        flags {}
        modifiers {}
        frame {offset = 8, offset adjust = 0, size = 8, size adjust = 0}
     



Configuration:
Xcode Version 5.0.2 (5A3005)
device: iPad Air (Model A1475)

-------------------------------

Additional note - 16-Nov-2013 06:07 PM

It seems confirmed that the issue lays in the NSSignature class:
When running the program in the simulator in mode "iPad retina (64 bits), the description of the methodSignature instance gives a correct offset for the return value:

po methodSignature
<NSMethodSignature: 0x109062040>
    number of arguments = 2
    frame size = 224
    is special struct return? NO
    return value: -------- -------- -------- --------
        type encoding (d) 'd'
        flags {isFloat}
        modifiers {}
        frame {offset = 16, offset adjust = 0, size = 16, size adjust = -8}
        memory {offset = 0, size = 8}
    argument 0: -------- -------- -------- --------
        type encoding (@) '@'
        flags {isObject}
        modifiers {}
        frame {offset = 0, offset adjust = 0, size = 8, size adjust = 0}
        memory {offset = 0, size = 8}
    argument 1: -------- -------- -------- --------
        type encoding (:) ':'
        flags {}
        modifiers {}
        frame {offset = 8, offset adjust = 0, size = 8, size adjust = 0}
        memory {offset = 0, size = 8}

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!