Skip to content

Commit 2cf7ef5

Browse files
committed
[IRGen] Fix FixedArray of fixedSize 1 elt addring.
When a `FixedArray`'s fixed size is 1, it looks like `[1 x %Ty]`. Given an array's address, performing an operation on each element's address entail's indexing into the array to each element's index to produce an element's address for each index. That is true even when the array consists of a single element. In that case, produce an address for that single element by indexing to index 0 into each passed-in array. rdar://151726387
1 parent eb8da5e commit 2cf7ef5

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

lib/IRGen/GenArray.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,15 @@ class ArrayTypeInfoBase : public BaseTypeInfo {
5353
return;
5454
}
5555
if (fixedSize == 1) {
56-
// only one element to operate on
57-
return body(addrs);
56+
auto zero = llvm::ConstantInt::get(IGF.IGM.IntPtrTy, 0);
57+
// only one element to operate on; index to it in each array
58+
SmallVector<Address, 2> eltAddrs;
59+
eltAddrs.reserve(addrs.size());
60+
for (auto index : indices(addrs)) {
61+
eltAddrs.push_back(Element.indexArray(IGF, addrs[index], zero,
62+
getElementSILType(IGF.IGM, T)));
63+
}
64+
return body(eltAddrs);
5865
}
5966

6067
auto arraySize = getArraySize(IGF, T);
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// RUN: %target-swift-frontend -parse-sil -emit-ir %s
2+
3+
sil_stage canonical
4+
5+
import Builtin
6+
import Swift
7+
8+
struct O {
9+
var arr: Builtin.FixedArray<1, I>
10+
struct I {
11+
var eyes: SIMD64<Int8>
12+
var neighs: String
13+
}
14+
}
15+
16+
sil @copy : $@convention(thin) (@in_guaranteed O) -> (@out O) {
17+
entry(%out : $*O, %in : $*O):
18+
copy_addr %in to [init] %out : $*O
19+
%retval = tuple ()
20+
return %retval : $()
21+
}

0 commit comments

Comments
 (0)