Skip to content

Commit 65e3907

Browse files
committed
Add a feature for Builtin.assumeAlignment
Fixes rdar://86785846
1 parent c9c0794 commit 65e3907

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
5858
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()", true)
5959
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
6060
LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
61+
LANGUAGE_FEATURE(BuiltinAssumeAlignment, 0, "Builtin.assumeAlignment", true)
6162

6263
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2891,6 +2891,10 @@ static bool usesFeatureBuiltinStackAlloc(Decl *decl) {
28912891
return false;
28922892
}
28932893

2894+
static bool usesFeatureBuiltinAssumeAlignment(Decl *decl) {
2895+
return false;
2896+
}
2897+
28942898
/// Determine the set of "new" features used on a given declaration.
28952899
///
28962900
/// Note: right now, all features we check for are "new". At some point, we'll

stdlib/public/core/UnsafeRawPointer.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,11 +357,15 @@ public struct UnsafeRawPointer: _Pointer {
357357

358358
let rawPointer = (self + offset)._rawValue
359359

360+
#if compiler(>=5.5) && $BuiltinAssumeAlignment
360361
// TODO: to support misaligned raw loads, simply remove this assumption.
361362
let alignedPointer =
362363
Builtin.assumeAlignment(rawPointer,
363364
MemoryLayout<T>.alignment._builtinWordValue)
364365
return Builtin.loadRaw(alignedPointer)
366+
#else
367+
return Builtin.loadRaw(rawPointer)
368+
#endif
365369
}
366370

367371
}
@@ -909,11 +913,15 @@ public struct UnsafeMutableRawPointer: _Pointer {
909913

910914
let rawPointer = (self + offset)._rawValue
911915

916+
#if compiler(>=5.5) && $BuiltinAssumeAlignment
912917
// TODO: to support misaligned raw loads, simply remove this assumption.
913918
let alignedPointer =
914919
Builtin.assumeAlignment(rawPointer,
915920
MemoryLayout<T>.alignment._builtinWordValue)
916921
return Builtin.loadRaw(alignedPointer)
922+
#else
923+
return Builtin.loadRaw(rawPointer)
924+
#endif
917925
}
918926

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

0 commit comments

Comments
 (0)