Skip to content

swift_slowAlloc() _et al._ should be marked returns-nonnull to improve codegen #58686

@grynspan

Description

@grynspan

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().

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions