Skip to content

Add a feature for Builtin.assumeAlignment #40674

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
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
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,6 @@ LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()", true)
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)

#undef LANGUAGE_FEATURE
4 changes: 4 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2891,6 +2891,10 @@ static bool usesFeatureBuiltinStackAlloc(Decl *decl) {
return false;
}

static bool usesFeatureBuiltinAssumeAlignment(Decl *decl) {
return false;
}

/// Determine the set of "new" features used on a given declaration.
///
/// Note: right now, all features we check for are "new". At some point, we'll
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/core/UnsafeRawPointer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,15 @@ public struct UnsafeRawPointer: _Pointer {

let rawPointer = (self + offset)._rawValue

#if compiler(>=5.5) && $BuiltinAssumeAlignment
// TODO: to support misaligned raw loads, simply remove this assumption.
let alignedPointer =
Builtin.assumeAlignment(rawPointer,
MemoryLayout<T>.alignment._builtinWordValue)
return Builtin.loadRaw(alignedPointer)
#else
return Builtin.loadRaw(rawPointer)
#endif
}

}
Expand Down Expand Up @@ -909,11 +913,15 @@ public struct UnsafeMutableRawPointer: _Pointer {

let rawPointer = (self + offset)._rawValue

#if compiler(>=5.5) && $BuiltinAssumeAlignment
// TODO: to support misaligned raw loads, simply remove this assumption.
let alignedPointer =
Builtin.assumeAlignment(rawPointer,
MemoryLayout<T>.alignment._builtinWordValue)
return Builtin.loadRaw(alignedPointer)
#else
return Builtin.loadRaw(rawPointer)
#endif
}

/// Stores the given value's bytes into raw memory at the specified offset.
Expand Down