Skip to content

Commit 6c45865

Browse files
committed
Add more comments about this builtin
1 parent f5e10e2 commit 6c45865

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

include/swift/AST/Builtins.def

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,6 +1112,12 @@ BUILTIN_MISC_OPERATION_WITH_SILGEN(DistributedActorAsAnyActor, "distributedActor
11121112
/// Returns a raw pointer to the address of the raw layout type. This address is
11131113
/// only valid during a borrow access of the raw layout type or until the value
11141114
/// is either moved or consumed.
1115+
///
1116+
/// Note: The purpose of this builtin is to get an opaque pointer to the address
1117+
/// of the raw layout type. We explicitly do not want the optimizer looking into
1118+
/// this pointer or address thereof to start assuming things about mutability or
1119+
/// immutability. This builtin _must_ persist throughout all of SIL and must be
1120+
/// lowered away at IRGen, no sooner.
11151121
BUILTIN_MISC_OPERATION_WITH_SILGEN(AddressOfRawLayout, "addressOfRawLayout", "n", Special)
11161122

11171123
/// Builtins for instrumentation added by sanitizers during SILGen.

lib/IRGen/GenBuiltin.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1477,6 +1477,9 @@ void irgen::emitBuiltinCall(IRGenFunction &IGF, const BuiltinInfo &Builtin,
14771477
return;
14781478
}
14791479

1480+
// LLVM must not see the address generated here as 'invariant' or immutable
1481+
// ever. A raw layout's address defies all formal access, so immutable looking
1482+
// uses may actually mutate the underlying value!
14801483
if (Builtin.ID == BuiltinValueKind::AddressOfRawLayout) {
14811484
auto addr = args.claimNext();
14821485
auto value = IGF.Builder.CreateBitCast(addr, IGF.IGM.Int8PtrTy);

0 commit comments

Comments
 (0)