Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-5438] Something is up with do/try/catch on the port to Android #48012

Closed
johnno1962 opened this issue Jul 11, 2017 · 4 comments
Closed

[SR-5438] Something is up with do/try/catch on the port to Android #48012

johnno1962 opened this issue Jul 11, 2017 · 4 comments
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime

Comments

@johnno1962
Copy link
Contributor

Previous ID SR-5438
Radar None
Original Reporter @johnno1962
Type Bug
Status Closed
Resolution Done
Environment

http://johnholdsworth.com/android_toolchain.tgz

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug, Android, Runtime
Assignee None
Priority Medium

md5: 811dce9ad8c11216c611c20e8ee4b825

relates to:

  • SR-5414 ImageInspectionELF.cpp:getSectionInfo crashes on Android

Issue Description:

I’ve been chipping away at getting Swift to work on Android and found that there are problems with the implementation of do/try/catch when swift is run an Android device.

The following example program:

import Foundation

print("Hello, Android")

do {
      print("HERE1")
      try { throw NSError(domain:"Oh", code:-1) }()
}
catch let err as Error {
      print("HERE2")
}

print("DONE")

Produces this output on Linux/macOS:

Hello, Android
HERE1
HERE2
DONE

Whereas on Android following the instructions from https://github.com/apple/swift/blob/master/docs/Android.md

produces the following output:

Hello, Android
HERE1
DONE

This is causing crashes in corefoundation where errors should have been trapped and code goes down the wrong path as a result. This is from a version of Swift from master about a month ago. I’ll be building from a more up to date version soon and will close this report if this is resolved.

@johnno1962
Copy link
Contributor Author

I’ve updated https://bugs.swift.org/browse/SR-5414 which is thhe only other known problem with the Swift runtime which I though might be related to this problem. This seems not to be the case. It just seems thrown exceptions are not caught at all on the Android port of Swift.

@johnno1962
Copy link
Contributor Author

If I alter the code to the following:

import Foundation

print("Hello, Android")

do {
      print("HERE1")
      try { throw NSError(domain:"Oh", code:-1) }()
      print("HERE!")
}
//catch let err as Error {
catch {
      print("HERE2")
}

print("DONE”)

You can see the throw isn’t working at all

Hello, Android
HERE1
HERE!
DONE

@johnno1962
Copy link
Contributor Author

I’ve raised a PR on swift-llvm apple/swift-llvm#55 to resolve this. The problem was r8 was being saved and restored on entry/return from functions that throw. This was overwriting the value for r8 which was intended to be the object being thrown resulting in calling code failing to catch the exception.

@johnno1962
Copy link
Contributor Author

{{ ldr r0, [r11, #-40]
bl swift_willThrow
ldr r0, [r11, #-40]
mov r8, r0
sub sp, r11, #8
pop {r8, r10, r11, pc}
}}

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android Platform: Android bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. compiler The Swift compiler in itself runtime The Swift Runtime
Projects
None yet
Development

No branches or pull requests

1 participant