Skip to content

[embedded] Add -no-allocations test for UnsafeMutablePointer.allocate(), improve diag messsage #70710

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

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSIL.def
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ ERROR(embedded_swift_metatype,none,
ERROR(embedded_swift_allocating_type,none,
"cannot use allocating type %0 in -no-allocations mode", (Type))
ERROR(embedded_swift_allocating,none,
"cannot use allocating type in -no-allocations mode", ())
"cannot use allocating operation in -no-allocations mode", ())
NOTE(performance_called_from,none,
"called from here", ())

Expand Down
4 changes: 4 additions & 0 deletions test/embedded/no-allocations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,7 @@ public func use_an_array() -> Int {
let a = [1, 2, 3] // expected-error {{cannot use allocating type '_ContiguousArrayStorage<Int>' in -no-allocations mode}}
return a.count
}

public func use_unsafepointer_allocate() -> UnsafeMutablePointer<UInt8> {
return UnsafeMutablePointer<UInt8>.allocate(capacity: 10) // expected-error {{cannot use allocating operation in -no-allocations mode}}
}