Skip to content

Commit b38cacb

Browse files
IRGen: Use LLVM's alloc size to compute padding between types (swiftlang#10464)
* IRGen: Use LLVM's alloc size to compute padding between types We need to subtract alignment padding when doing type layout in terms of llvm types rdar://32618125 SR-5137
1 parent 31b1ebf commit b38cacb

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

lib/IRGen/GenCall.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,9 @@ NativeConventionSchema::getCoercionTypes(
382382
packed = true;
383383
elts.push_back(type);
384384
expandedTyIndicesMap.push_back(idx - 1);
385-
lastEnd = end;
385+
lastEnd = begin + clang::CharUnits::fromQuantity(
386+
IGM.DataLayout.getTypeAllocSize(type));
387+
assert(end <= lastEnd);
386388
});
387389

388390
auto *coercionType = llvm::StructType::get(ctx, elts, packed);
@@ -419,7 +421,9 @@ NativeConventionSchema::getCoercionTypes(
419421
packed = true;
420422
elts.push_back(type);
421423
expandedTyIndicesMap.push_back(idx - 1);
422-
lastEnd = end;
424+
lastEnd = begin + clang::CharUnits::fromQuantity(
425+
IGM.DataLayout.getTypeAllocSize(type));
426+
assert(end <= lastEnd);
423427
});
424428
auto *overlappedCoercionType = llvm::StructType::get(ctx, elts, packed);
425429
return {coercionType, overlappedCoercionType};

test/Interpreter/simd.swift

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-run-simple-swift | %FileCheck %s
2+
// REQUIRES: executable_test
3+
// REQUIRES: OS=macosx
4+
5+
import simd
6+
7+
public struct Vector3f {
8+
var f3: float3
9+
init() {
10+
f3 = float3(0, 1, 2)
11+
}
12+
}
13+
14+
public struct TwoFloat {
15+
var f0 : Float
16+
var f1 : Float
17+
init() {
18+
f0 = 0.0
19+
f1 = 1.0
20+
}
21+
}
22+
23+
public func test() -> (Vector3f, TwoFloat) {
24+
let v = Vector3f()
25+
let y = TwoFloat()
26+
let r = (v, y)
27+
return r
28+
}
29+
30+
// CHECK: (main.Vector3f(f3: float3(0.0, 1.0, 2.0)), main.TwoFloat(f0: 0.0, f1: 1.0))
31+
print(test())

0 commit comments

Comments
 (0)