Bug 18719 - Code behaves differently with LLVM option on
Summary: Code behaves differently with LLVM option on
Alias: None
Product: iOS
Classification: Xamarin
Component: General ()
Version: 7.2.0
Hardware: PC Mac OS
: High normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
Depends on:
Reported: 2014-04-01 19:08 UTC by John Miller [MSFT]
Modified: 2014-11-18 22:15 UTC (History)
5 users (show)

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

Repro Project (1.65 MB, application/zip)
2014-04-01 19:08 UTC, John Miller [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 John Miller [MSFT] 2014-04-01 19:08:36 UTC
Created attachment 6451 [details]
Repro Project

Sample project provided that shows the issue. 

With the LLVM compiler option turned on, the code does not behave as expected. 

Observable.Interval(TimeSpan.FromSeconds(1), TaskPoolScheduler.Default)
.Select(x => DateTime.UtcNow.Second % 2 == 0)
.Do(_ =>
    UIApplication.SharedApplication.BeginInvokeOnMainThread(() => { button.SetTitle("VALUE=" + _.ToString(), UIControlState.Normal); });
.Select(x =>
    // BUG
    // If the code below is commented, the result of the Select will ALWAYS be the same (like if the ! operator is ignored)...
    // BUT : If the code below is UNcommented, we have the reverse bool as expected...
    // IMPORTANT : 
    // - LLVM MUST BE ACTIVATED to reproduce
    // - MUST RUN ON A REAL DEVICE (cannot reproduce on simulator)


//	try
//	{
//		buttonWidth += 1;
//	}
//	catch (Exception)
//	{
//		UIApplication.SharedApplication.BeginInvokeOnMainThread(
//		() =>
//		{
//			button2.SetTitle("ERR", UIControlState.Normal);
//		});
//			throw;
//		}

    return !x;
.Do(_ =>
    UIApplication.SharedApplication.BeginInvokeOnMainThread(() => { button2.SetTitle("!VALUE=" + _.ToString(), UIControlState.Normal); });
Comment 1 Sebastien Pouliot 2014-04-01 20:27:54 UTC
Is this really 7.2.1 (alpha only) ? and if so does it happen in earlier versions (e.g. stable 7.2.0) ?

The easiest way to get exact version information is to use the "Xamarin Studio" menu, "About Xamarin Studio" item, "Show Details" button and copy/paste the version informations (you can use the "Copy Information" button).
Comment 2 John Miller [MSFT] 2014-04-01 20:40:58 UTC

Sorry, you were correct it was with in the stable channel. I updated the report.
Comment 3 Miguel de Icaza [MSFT] 2014-04-07 11:55:35 UTC
Reopened, now that we have the new information
Comment 4 Dillon Buchananq 2014-07-20 15:48:38 UTC
I'm not sure if this is the exact same bug but I am noticing similar effects using Reactive Extensions. I have an example project here (https://github.com/thedillonb/XamarinLLVMIssue) which exhibits the issue. I am using a MVVM framework (ReactiveUI) that is build upon Reactive Extensions, the issue I'm seeing is that when LLVM compiliation is disabled, the "CanExecute" method on the Command object returns "true" like it should. However, if I enable LLVM then all of a sudden the same "CanExecute" method returns "false". This issue is also described here: https://github.com/reactiveui/ReactiveUI/issues/381 where one of the owners indicated that his exact issue (a year ago) was altered when LLVM was enabled/disabled.
Comment 5 Dillon Buchananq 2014-07-20 15:49:31 UTC
I should also note that I am running Xamarin iOS 7.2.6
Comment 6 Dillon Buchananq 2014-07-28 00:08:05 UTC
Any news on this issue from the Xamarin team?
Comment 7 Zoltan Varga 2014-07-29 06:57:34 UTC
I can't reproduce this with mt master. This is probably a dup of:
Comment 8 Zoltan Varga 2014-11-18 22:15:36 UTC