Skip to content

IRGen: Annotate runtime calls with willreturn attribute #40089

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

Conversation

aschwaighofer
Copy link
Contributor

willreturn
This function attribute indicates that a call of this function will
either exhibit undefined behavior or comes back and continues execution
at a point in the existing call stack that includes the current
invocation. Annotated functions may still raise an exception, i.a.,
nounwind is not implied. If an invocation of an annotated function does
not return control back to a point in the call stack, the behavior is
undefined.

I conservatively did not assume that the deinit is willreturn therefore
release like operations are not marked willreturn.

rdar://73574236

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@swift-ci
Copy link
Contributor

swift-ci commented Nov 8, 2021

Build failed
Swift Test Linux Platform
Git Sha - fbe7fd7e9440642f6aefbe75abc62f38fe063ba9

@aschwaighofer aschwaighofer force-pushed the irgen_annotate_runtime_funs_with_willreturn branch from fbe7fd7 to a7c3f14 Compare November 8, 2021 22:28
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@tbkka tbkka requested a review from mikeash November 11, 2021 21:48
@mikeash
Copy link
Contributor

mikeash commented Nov 11, 2021

Some of these (e.g. swift_allocObject) can fatal error when things go wrong, is that acceptable? I don't entirely understand the practicalities of willreturn.

@aschwaighofer
Copy link
Contributor Author

If you go by the letter than we would not be allowed to mark such a function as willreturn. fatal error is a side-effect we want to observe.

Because swift_allocObject is marked as having unknown side-effects (by the virtue of not being marked as readnone, or readonly) it is okay since we already have other side-effects.

I will go and update the file to fix any confusion.

LLVM was assuming every function is willreturn up until recently.

@aschwaighofer aschwaighofer force-pushed the irgen_annotate_runtime_funs_with_willreturn branch from a7c3f14 to a049f1b Compare November 12, 2021 15:01
@aschwaighofer
Copy link
Contributor Author

Now without allocation functions and objc apis that I wasnt sure about whether they could fatalError (or similar).

@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@mikeash
Copy link
Contributor

mikeash commented Nov 12, 2021

There are some more that can allocate (mostly things that use caches, which might insert new entries and allocate memory for them) or otherwise fatal error:

swift_makeBoxUnique
swift_getTypeByMangledNameInContextInMetadataState
swift_getTypeByMangledNameInContext
swift_conformsToProtocol
swift_dynamicCast*Unconditional
swift_get*Metadata
swift_getWitnessTable
swift_getInitializedObjCClass // can potentially invoke arbitrary code if +self is overridden
swift_objc_swift3ImplicitObjCEntrypoint // has an option to fatal error

`willreturn`
This function attribute indicates that a call of this function will
either exhibit undefined behavior or comes back and continues execution
at a point in the existing call stack that includes the current
invocation. Annotated functions may still raise an exception, i.a.,
`nounwind` is not implied. If an invocation of an annotated function does
not return control back to a point in the call stack, the behavior is
undefined.

I conservatively did not assume that the deinit is willreturn therefore
release like operations are not marked `willreturn`.

rdar://73574236
@aschwaighofer aschwaighofer force-pushed the irgen_annotate_runtime_funs_with_willreturn branch from a049f1b to 2e4a869 Compare November 12, 2021 15:58
@aschwaighofer
Copy link
Contributor Author

@swift-ci Please test

@aschwaighofer aschwaighofer merged commit b90732c into swiftlang:main Nov 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants