- Notifications
You must be signed in to change notification settings - Fork 10.6k
Closed
Closed
Copy link
Labels
Description
swift_slowAlloc()
et al. should be marked returns-nonnull to improve codegen.
Since swift_slowAlloc()
crashes if malloc()
(or equivalent) fails, we can guarantee it never returns nullptr
. We can make that guarantee by adding the GNU/clang returns_nonnull
attribute, which tells the compiler that the annotated function can never return nullptr
. The compiler can then optimize callers further (by eliminating dead codepaths in the caller.) This is distinct from Apple's _Nonnull
extension, which (in C/C++) is advisory only and does not affect codegen.
We can also add the attribute to any function that either tail-calls swift_slowAlloc()
or is guaranteed to return the result of that function (such as swift_cxx_newObject()
or swift_allocObject()
.