Skip to content

Commit 3b05c5d

Browse files
authored
Merge pull request #9237 from rjmccall/look-through-dynamically-enforced-address
2 parents 6e0cb84 + 16c500d commit 3b05c5d

File tree

2 files changed

+44
-29
lines changed

2 files changed

+44
-29
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 28 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -274,11 +274,6 @@ class LoweredValue {
274274
return kind == Kind::BoxWithAddress;
275275
}
276276

277-
Address getAddress() const {
278-
assert(kind == Kind::Address && "not an allocated address");
279-
return address.getAddress();
280-
}
281-
282277
StackAddress getStackAddress() const {
283278
assert(kind == Kind::Address && "not an allocated address");
284279
return address;
@@ -301,6 +296,17 @@ class LoweredValue {
301296
assert(kind == Kind::DynamicallyEnforcedAddress);
302297
return dynamicallyEnforcedAddress;
303298
}
299+
300+
Address getAnyAddress() const {
301+
if (kind == LoweredValue::Kind::Address) {
302+
return address.getAddress();
303+
} else if (kind == LoweredValue::Kind::ContainedAddress) {
304+
return getAddressInContainer();
305+
} else {
306+
assert(kind == LoweredValue::Kind::DynamicallyEnforcedAddress);
307+
return getDynamicallyEnforcedAddress().Addr;
308+
}
309+
}
304310

305311
void getExplosion(IRGenFunction &IGF, Explosion &ex) const;
306312

@@ -559,15 +565,7 @@ class IRGenSILFunction :
559565
/// Get the Address of a SIL value of address type, which must have been
560566
/// lowered.
561567
Address getLoweredAddress(SILValue v) {
562-
auto &&lv = getLoweredValue(v);
563-
if (lv.kind == LoweredValue::Kind::Address) {
564-
return lv.getAddress();
565-
} else if (lv.kind == LoweredValue::Kind::ContainedAddress) {
566-
return lv.getAddressInContainer();
567-
} else {
568-
assert(lv.kind == LoweredValue::Kind::DynamicallyEnforcedAddress);
569-
return lv.getDynamicallyEnforcedAddress().Addr;
570-
}
568+
return getLoweredValue(v).getAnyAddress();
571569
}
572570

573571
StackAddress getLoweredStackAddress(SILValue v) {
@@ -2623,14 +2621,13 @@ static void addIncomingSILArgumentsToPHINodes(IRGenSILFunction &IGF,
26232621
OperandValueArrayRef args) {
26242622
unsigned phiIndex = 0;
26252623
for (SILValue arg : args) {
2626-
const LoweredValue &lv = IGF.getLoweredValue(arg);
2627-
2628-
if (lv.isAddress()) {
2629-
addIncomingAddressToPHINodes(IGF, lbb, phiIndex, lv.getAddress());
2624+
if (arg->getType().isAddress()) {
2625+
addIncomingAddressToPHINodes(IGF, lbb, phiIndex,
2626+
IGF.getLoweredAddress(arg));
26302627
continue;
26312628
}
26322629

2633-
Explosion argValue = lv.getExplosion(IGF);
2630+
Explosion argValue = IGF.getLoweredExplosion(arg);
26342631
addIncomingExplosionToPHINodes(IGF, lbb, phiIndex, argValue);
26352632
}
26362633
}
@@ -4647,16 +4644,18 @@ void IRGenSILFunction::visitIsNonnullInst(swift::IsNonnullInst *i) {
46474644
// Get the value we're testing, which may be a function, an address or an
46484645
// instance pointer.
46494646
llvm::Value *val;
4650-
const LoweredValue &lv = getLoweredValue(i->getOperand());
4651-
4652-
if (i->getOperand()->getType().is<SILFunctionType>()) {
4653-
Explosion values = lv.getExplosion(*this);
4654-
val = values.claimNext(); // Function pointer.
4655-
values.claimNext(); // Ignore the data pointer.
4656-
} else if (lv.isAddress()) {
4657-
val = lv.getAddress().getAddress();
4647+
4648+
SILValue operand = i->getOperand();
4649+
auto type = operand->getType();
4650+
if (type.isAddress()) {
4651+
val = getLoweredAddress(operand).getAddress();
4652+
} else if (auto fnType = type.getAs<SILFunctionType>()) {
4653+
Explosion values = getLoweredExplosion(operand);
4654+
val = values.claimNext(); // Function pointer.
4655+
if (fnType->getRepresentation() == SILFunctionTypeRepresentation::Thick)
4656+
(void) values.claimNext(); // Ignore the data pointer.
46584657
} else {
4659-
Explosion values = lv.getExplosion(*this);
4658+
Explosion values = getLoweredExplosion(operand);
46604659
val = values.claimNext();
46614660
}
46624661

@@ -5049,7 +5048,7 @@ void IRGenSILFunction::visitCopyAddrInst(swift::CopyAddrInst *i) {
50495048
setAllocatedAddressForBuffer(i->getDest(), addr);
50505049
}
50515050
} else {
5052-
Address dest = loweredDest.getAddress();
5051+
Address dest = loweredDest.getAnyAddress();
50535052

50545053
if (i->isInitializationOfDest()) {
50555054
if (i->isTakeOfSrc()) {

test/IRGen/access_markers.sil

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import Swift
55

66
class A {
77
@sil_stored var property: Int { get set }
8+
@sil_stored var exProperty: Any { get set }
89
deinit
910
init()
1011
}
@@ -77,3 +78,18 @@ bb0(%0 : $A):
7778
%20 = tuple ()
7879
return %20 : $()
7980
}
81+
82+
// rdar://31964550
83+
// Just check that this doesn't crash.
84+
sil @testCopyAddr : $(@guaranteed A) -> () {
85+
bb0(%0 : $A):
86+
%1 = alloc_stack $Any
87+
%2 = ref_element_addr %0 : $A, #A.exProperty
88+
%3 = begin_access [dynamic] [read] %2 : $*Any
89+
copy_addr %2 to [initialization] %1 : $*Any
90+
end_access %3 : $*Any
91+
destroy_addr %1 : $*Any
92+
dealloc_stack %1 : $*Any
93+
%20 = tuple ()
94+
return %20 : $()
95+
}

0 commit comments

Comments
 (0)