Bug 37236 - ARM64 + LLVM calls by value result in incorrect calculations
Summary: ARM64 + LLVM calls by value result in incorrect calculations
Alias: None
Product: iOS
Classification: Xamarin
Component: Mono runtime / AOT compiler ()
Version: XI 9.4 (iOS 9.2)
Hardware: PC Mac OS
: --- normal
Target Milestone: (C7)
Assignee: Zoltan Varga
Depends on:
Reported: 2015-12-22 17:51 UTC by Cody Beyer (MSFT)
Modified: 2016-03-25 01:55 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Sample and Output (28.11 KB, application/zip)
2015-12-22 17:51 UTC, Cody Beyer (MSFT)

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Cody Beyer (MSFT) 2015-12-22 17:51:10 UTC
Created attachment 14382 [details]
Sample and Output

### Description

The following sample app demonstrates an issue where calculating by value results in incorrect calculations

### Sample


### Explanation of Sample

The sample app loops twice, the first loop calculates values based on refs, the 2nd loops calculates based directly on the values. The first loop produces correct results, 2nd loop produces incorrect results

### Sample Output 


### Steps to Reproduce

1. Download sample
2. Ensure configuration is for ARM64 + LLCM
3. Open Xcode > Windows > Devices > [iPhone] > Expand Log
4. Deploy to Device

### Expected Results

The app should print numerous calculations to the log, all should result in:

Nrm = 0 0 -1

### Actual Results

The first loop produced the expected results, the 2nd loop produces incorrect calculations, such as:

Nrm = 0.8267848 0.5450354 0.1391524

### Versions

=== Xamarin Studio ===

Version 5.10.1 (build 6)
Installation UUID: 898b546d-da31-47aa-aa48-67c373406277
	Mono 4.2.1 (explicit/6dd2d0d)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 402010102

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.2 (9548)
Build 7C68

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 7322991
Branch: master
Build date: 2015-12-08 16:20:29-0500

=== Xamarin.Android ===

Version: (Business Edition)
Android SDK: /Users/codybeyer/Library/Developer/Xamarin/android-sdk-macosx
	Supported Android versions:
		4.0.3 (API level 15)
		4.4   (API level 19)
		6.0   (API level 23)

SDK Tools Version: 24.4.1
SDK Platform Tools Version: 23.0.1
SDK Build Tools Version: 23.0.1

Java SDK: /usr
java version "1.7.0_71"
Java(TM) SE Runtime Environment (build 1.7.0_71-b14)
Java HotSpot(TM) 64-Bit Server VM (build 24.71-b01, mixed mode)

=== Xamarin Android Player ===

Version: 0.6.5
Location: /Applications/Xamarin Android Player.app

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 510010006
Git revision: 0b60eecdb531933734519c13257d16a780274aab
Build date: 2015-12-04 20:28:20-05
Xamarin addins: 9876fd7c9837977178411ec7375b4352c0a0d6af
Build lane: monodevelop-lion-cycle6-baseline

=== Operating System ===

Mac OS X 10.11.2
Darwin beyerstudios.local 15.2.0 Darwin Kernel Version 15.2.0
    Fri Nov 13 19:56:56 PST 2015
    root:xnu-3248.20.55~2/RELEASE_X86_64 x86_64
Comment 1 Zoltan Varga 2015-12-23 07:13:53 UTC
This happens when the callee is llvm compiled, and the caller is not.

	struct FooStruct {
		public float a, b, c;

	void DoFoo (FooStruct s1, FooStruct s2, FooStruct s3) {
		Console.WriteLine (s3.c);
		Console.WriteLine (s3.c);
		Console.WriteLine (s3.c);
		Console.WriteLine (s3.c);

 struct LargeStruct {
	 public FooStruct x;
	 public int a, b, c, d, e, f, g, h;

	public override bool FinishedLaunching (UIApplication application, NSDictionary launchOptions)
		var arr = new LargeStruct [10, 10];
		for (int i = 0; i < 10; ++i)
			for (int j = 0; j < 10; ++j)
				arr [i, j].x = new FooStruct ();

		var s1 = new FooStruct () { a = 1, b = 1, c = 10 };
		DoFoo (s1, s1, s1);
                return true;
Comment 2 Zoltan Varga 2016-01-02 01:19:13 UTC
Should be fixed by mono 844b5e4fd4c02aa5505b9845c401a1ea2f2003d1/mono-extensions 9564d06956d3e062532e8023bccc1c1027c9b51a.
Comment 3 Brendan Zagaeski (Xamarin Team, assistant) 2016-03-25 01:55:46 UTC
Updating target milestone for verification.

Based on the versions of mono and mono-extensions referenced by the current Cycle 7 Preview of Xamarin.iOS (in the Alpha channel), it appears that the fix from Comment 2 should now exist in that preview. I did a quick preliminary verification using the test case from Comment 0, and the results looked good:

GOOD: Xamarin.iOS (fa3b68c)
BAD:  Xamarin.iOS (962a050)