Bug 13734 - LLVM conflicts with Task.Run
Summary: LLVM conflicts with Task.Run
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 6.4.0
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
Depends on:
Reported: 2013-08-03 08:27 UTC by Neal
Modified: 2017-05-18 13:02 UTC (History)
4 users (show)

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

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 Neal 2013-08-03 08:27:11 UTC

I have a method that runs on app resume such as to synchronize device's data across a web service to a ASMX web service.  This sync method wraps its code inside a Task.Run( ()={});

With LLVM enabled, the Task.Run never runs/completes, the sync status indicator remains on "syncing".  If I turn LLVM off, it works fine.

It appears LLVM and the async await TASK parallel library are not compatible.
Comment 1 Dillon Buchananq 2013-08-05 02:12:27 UTC
I see this as well.
Comment 2 Rolf Bjarne Kvinge [MSFT] 2013-08-05 06:37:55 UTC
Would it be possible to get a test project I can use to reproduce this issue?
Comment 3 Rolf Bjarne Kvinge [MSFT] 2013-08-05 07:58:18 UTC
This can be reproduced with this test case: https://gist.github.com/thedillonb/6109830

Zoltan, can you have a look?
Comment 4 Zoltan Varga 2013-08-05 08:35:18 UTC
Simply marking the ViewDidAppear method as async is enough to cause the problem, it seems like the method is not called.
Comment 5 Zoltan Varga 2013-08-06 03:31:49 UTC
This is an llvm bug, it miscompiles the ViewDidAppear method.
Added a workaround to mono master ab92538d5ae55c7909b117fd45945affce2e561c and mono-3-2 
d98dfc7ff93fd5a99f49993e0340e039c3a69d1d. This is safe to put into 6.4.
Comment 6 Rolf Bjarne Kvinge [MSFT] 2013-08-06 04:41:17 UTC
monotouch/master-3.0: ab92538d5ae55c7909b117fd45945affce2e561c
monotouch/monotouch-6.4-series: 1c428d5d742cb307de5a06e2b29bebd0965a12cc

This fix will be in 6.4.3.
Comment 7 Zoltan Varga 2013-08-06 05:09:09 UTC
The underlying issue is not fixed, this is just a workaround.
Comment 8 Dillon Buchananq 2013-08-06 11:00:05 UTC
Is there a timeframe on when 6.4.3 will be released? Also, I beleive this issue is not specific to ViewDidAppear but any of the iOS methods: ViewDidLoad, ViewDidDisappear, etc... Will this workaround be sufficiant for these? How bad is the underlying issue in terms of time to fix?
Comment 9 Neal 2013-08-06 11:06:07 UTC
In my opinion, blaming this on LLVM is incorrect.  I didn't have any problems with LLVM in the past and I've been using it forever.  This only started when Xam.iOS 6.4 released and I implemented Task.Run methods.  It worked just fine previously.  It's something with your System.Threading.Tasks implementation in my opinion.
Comment 10 Zoltan Varga 2013-08-06 12:08:03 UTC
It is an LLVM optimization problem which is triggered by the IL code in this method.
Comment 11 Neal 2013-08-11 11:58:10 UTC
I've seen some issues now when I launch my app my root view controller's table view is not refreshing, it's coming up blank.  I think this may be something with the changes made in this case?  I'm NOT using Task.Run or LLVM at this time so something got hit in this fix I think.  

I am back on the STABLE channel now and all is working fine but you may want to do more testing on this work around as it may have side effects as described above.
Comment 12 Dillon Buchananq 2013-08-14 13:30:26 UTC
Neal, were you using the 6.4.2 hotfix release when you found that issue?
Comment 13 Neal 2013-08-14 13:54:21 UTC
No, 6.4.0 as stated in the case, the first stable release with async await.
Comment 14 Dillon Buchananq 2013-08-14 14:36:08 UTC
Sorry, my bad no specifying, I ment the issue you found 3 comments ago on "2013-08-11 11:58:10 EDT" when you tested the fix and found that your table view was not refreshing.
Comment 15 Neal 2013-08-14 14:39:53 UTC
Ahh, yes.  That is a correct statement.  I'm back to stable now (6.4.1) so I am not able to investigate that at the moment but I was seeing that behavior with the proposed fix (alpha I think it was).
Comment 16 Dillon Buchananq 2013-08-28 13:35:00 UTC
Zoltan, since 6.4.2 has been released as stable am I to assume that Neal's issue mentioned on "2013-08-11 11:58:10 EDT" has been resolved or unreproducable on your side?
Comment 17 Zoltan Varga 2013-08-28 13:40:47 UTC
Basically, LLVM would miscompile some methods, so we disabled it for those methods. This is very unlikely to break anything, so Neal's issue is probably something else.
Comment 18 Vincent Dondain [MSFT] 2017-05-18 13:02:23 UTC
Ok so @zoltan might be able to tell us if the underlying LLVM issue is now fixed (workaround not needed anymore).

Since we got a workaround I believe this bug is not relevant anymore, it was "fixed" (workaround) by Zoltan.

On the fact that when testing the hotfix release, Neal's table view was not refreshing anymore. I expect that if this was an issue we would have seen other bugs about it, I don't expect you to be able to reproduce it anymore but in any case it's not relevant to this very bug.

I'm closing this issue but feel free to reopen it if this is still an issue for you.