This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Use Swift error registers on non-Darwin targets
ClosedPublic

Authored by modocache on Jul 25 2017, 6:20 AM.

Details

Summary

Remove a check for ARMSubtarget::isTargetDarwin when determining
whether to use Swift error registers, so that Swift errors work
properly on non-Darwin ARM32 targets (specifically Android).

Before this patch, generated code would save and restores ARM register r8 at
the entry and returns of a function that throws. As r8 is used as a virtual
return value for the object being thrown, this gets overwritten by the restore,
and calling code is unable to catch the error. In turn this caused Swift code
that used do/try/catch to work improperly on Android ARM32 targets.

Addresses Swift bug report https://bugs.swift.org/browse/SR-5438.

Patch by John Holdsworth.

Event Timeline

modocache created this revision.Jul 25 2017, 6:20 AM
aschwaighofer requested changes to this revision.Jul 25 2017, 8:15 AM
aschwaighofer added a subscriber: aschwaighofer.

The change looks good but can you add a test case to test/CodeGen/ARM/swifterror.ll that r8 is not spilled say for a target triple of 'armv7-linux-androideabi'. For example, the function params_and_return_in_reg should not spill r8 as part of CSR spilling.

You would add the following run line to that file:

; RUN: llc -verify-machineinstrs < %s -mtriple=armv7-linux-androideabi | FileCheck --check-prefix=CHECK-ANDROID %s

And then copy the check located next to the params_and_return_in_reg function but for 'CHECK-ANDROID'.

Thank you for the contribution!

This revision now requires changes to proceed.Jul 25 2017, 8:15 AM
modocache planned changes to this revision.Jul 25 2017, 9:17 AM

Yup, can do! Thanks for the suggestion.

modocache edited edge metadata.

Added some tests to test/CodeGen/ARM/swifterror.ll, also courtesy of John Holdsworth.

This revision is now accepted and ready to land.Aug 30 2017, 12:01 PM
modocache closed this revision.Aug 30 2017, 1:04 PM