Skip to content

Commit 7f1fc90

Browse files
committed
LargeTypesReg2Mem: Gracefully handle the case when the Container type is deemed small but the Containee is not
rdar://123340151
1 parent d3d4bd2 commit 7f1fc90

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

lib/IRGen/LoadableByAddress.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3459,6 +3459,19 @@ class AddressAssignment {
34593459

34603460
SILValue getAddressForValue(SILValue v) {
34613461
auto it = valueToAddressMap.find(v);
3462+
3463+
// This can happen if we deem a container type small but a contained type
3464+
// big.
3465+
if (it == valueToAddressMap.end()) {
3466+
if (auto *sv = dyn_cast<SingleValueInstruction>(v)) {
3467+
auto addr = createAllocStack(v->getType());
3468+
auto builder = getBuilder(++sv->getIterator());
3469+
builder.createStore(sv->getLoc(), v, addr,
3470+
StoreOwnershipQualifier::Unqualified);
3471+
mapValueToAddress(v, addr);
3472+
return addr;
3473+
}
3474+
}
34623475
assert(it != valueToAddressMap.end());
34633476

34643477
return it->second;

test/IRGen/Inputs/large_c.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,14 @@ struct SamplesType {
2929
void* Z;
3030
void* AA;
3131
};
32+
33+
34+
typedef struct _ContainedType {
35+
unsigned int f1;
36+
float f2;
37+
} __attribute__((packed)) ContainedType;
38+
39+
typedef struct _ContainerType {
40+
char x1;
41+
ContainedType l[10];
42+
} __attribute__((packed)) ContainerType;

test/IRGen/loadable_by_address_reg2mem.sil

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,3 +229,22 @@ bb0(%0 : $SamplesType):
229229
%t = tuple ()
230230
return %t : $()
231231
}
232+
233+
// In this test case Container type is identified as not large but contained
234+
// type is.
235+
sil @test9 : $@convention(thin) () -> () {
236+
bb0:
237+
%0 = alloc_stack $_ContainerType
238+
%1 = load %0 : $*_ContainerType
239+
%2 = alloc_stack $(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
240+
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
241+
242+
%3 = struct_extract %1 : $_ContainerType, #_ContainerType.l
243+
store %3 to %2 : $*(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
244+
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
245+
dealloc_stack %2 : $*(_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType,
246+
_ContainedType, _ContainedType, _ContainedType, _ContainedType, _ContainedType)
247+
dealloc_stack %0 : $*_ContainerType
248+
%t = tuple ()
249+
return %t : $()
250+
}

0 commit comments

Comments
 (0)