Watch, Follow, &
Connect with Us
Public Report
Report From: Delphi-BCB/Compiler/Delphi/Code Generation/Optimization    [ Add a report in this area ]  
Report #:  116752   Status: Closed
[iOS device] Bad ARM code generation when using Unsigned Integers and Optimization
Project:  Delphi Build #:  18.0.4854.59655
Version:    18.0 Submitted By:   Erik van Bilsen
Report Type:  Basic functionality failure Date Reported:  6/21/2013 8:36:56 AM
Severity:    Serious / Highly visible problem Last Updated: 4/15/2014 6:43:35 PM
Platform:    Apple mobile OS Internal Tracking #:   40185
Resolution: Fixed (Resolution Comments) Resolved in Build: : XE6
Duplicate of:  None
Voting and Rating
Overall Rating: No Ratings Yet
0.00 out of 5
Total Votes: None
Description
[iOS device] Bad ARM code generation when using Unsigned Integers and Optimization

In certain situations, code that uses unsigned integers (like Cardinal or UInt32) behaves differently on an iOS device when compiled with Optimization turned On vs Off.

This issue does not happen on the iOS simulator (or Mac or Windows).
This issue also does not happen when using Signed integers instead of Unsigned integers.

See Steps for details
Steps to Reproduce:
1. Compile the following project with Optimization turned OFF.
---------------------------------------------------------
program UnsignedIntegerOptimization;

uses
  System.StartUpCopy,
  System.SysUtils,
  iOSapi.Foundation,
  Macapi.ObjectiveC;

{$R *.res}

procedure Log(const Msg: UnicodeString);
begin
  NSLog((NSSTR(Msg) as ILocalObject).GetObjectID);
end;

procedure Run;
var
  B: Boolean;
  I: Cardinal;
begin
  Log('START TEST');
  B := False;
  for I := 0 to 3 + Ord(B) do
    Log('TEST VALUE ' + I.ToString);
  Log('END TEST');
end;

begin
  Run;
end.
---------------------------------------------------------

2. Run the project on an iOS device (not the simulator). The output is as expected:
----------
START TEST
TEST VALUE 0
TEST VALUE 1
TEST VALUE 2
TEST VALUE 3
END TEST
----------

3. Now compile the same project with Optimization turned ON. Now, the loop contents isn't executed at all and the output is:
----------
START TEST
END TEST
----------

4. Changing the type of I from Cardinal to Integer will fix the problem. But still, the code should work with a Cardinal type.
Workarounds
None
Attachment
None
Comments

None

Server Response from: ETNACODE01