Skip to content

Commit 565e92e

Browse files
nate-chandlermeg-gupta
authored andcommitted
[SIL] Builtins that read/write mem may access ptr.
When an instruction `mayReadOrWriteMemory`, the `mayAccessPointer` predicate relies on the `visitAccessedAddress` utility to determine whether an instruction may access a pointer. That utility doesn't (and can't, without changing the representation of the builtin) visit `RawPointer` operands as used by memmove/memcpy builtins. Previously, this resulted `mayAccessPointer` returning `false` for such builtins. Here, this is fixed by making the predicate handle `BuiltinInsts` separately. Instead of just always returning `true` in the face of a builtin, rely on the BuiltinInfo associated with a BuiltinInst and use `mayReadOrWriteMemory`. rdar://120656227
1 parent ce24269 commit 565e92e

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/SIL/Utils/MemAccessUtils.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,10 @@ bool swift::isLetAddress(SILValue address) {
439439
bool swift::mayAccessPointer(SILInstruction *instruction) {
440440
if (!instruction->mayReadOrWriteMemory())
441441
return false;
442+
if (isa<BuiltinInst>(instruction)) {
443+
// Consider all builtins that read/write memory to access pointers.
444+
return true;
445+
}
442446
bool retval = false;
443447
visitAccessedAddress(instruction, [&retval](Operand *operand) {
444448
auto accessStorage = AccessStorage::compute(operand->get());

test/SILOptimizer/deinit_barrier.sil

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,18 @@ entry:
139139
%retval = tuple ()
140140
return %retval : $()
141141
}
142+
143+
// CHECK-LABEL: begin running test {{.*}} on rdar120656227: is-deinit-barrier
144+
// CHECK: builtin "int_memmove_RawPointer_RawPointer_Int64"
145+
// CHECK: true
146+
// CHECK-LABEL: end running test {{.*}} on rdar120656227: is-deinit-barrier
147+
sil [ossa] @rdar120656227 : $@convention(thin) (Builtin.RawPointer, Builtin.RawPointer) -> () {
148+
bb0(%42 : $Builtin.RawPointer, %9 : $Builtin.RawPointer):
149+
%14 = integer_literal $Builtin.Int64, 27
150+
%28 = integer_literal $Builtin.Int1, 1
151+
specify_test "is-deinit-barrier @instruction"
152+
%43 = builtin "int_memmove_RawPointer_RawPointer_Int64"(%42 : $Builtin.RawPointer, %9 : $Builtin.RawPointer, %14 : $Builtin.Int64, %28 : $Builtin.Int1) : $()
153+
%68 = tuple ()
154+
return %68 : $()
155+
}
156+

0 commit comments

Comments
 (0)