File tree Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Expand file tree Collapse file tree 4 files changed +65
-0
lines changed Original file line number Diff line number Diff line change @@ -1655,6 +1655,10 @@ AlignedGroupEntry::fixedAlignment(IRGenModule &IGM) const {
1655
1655
if (_fixedAlignment.has_value ())
1656
1656
return *_fixedAlignment;
1657
1657
1658
+ if (fixedTypeInfo) {
1659
+ return *(_fixedAlignment = (*fixedTypeInfo)->getFixedAlignment ());
1660
+ }
1661
+
1658
1662
Alignment currentAlignment = Alignment (
1659
1663
std::max ((Alignment::int_type)1 , minimumAlignment));
1660
1664
for (auto *entry : entries) {
Original file line number Diff line number Diff line change 1
1
#ifndef SWIFT_TEST_CTYPES_H
2
2
#define SWIFT_TEST_CTYPES_H
3
3
4
+ #include <stdint.h>
5
+
4
6
struct BigAlignment {
5
7
_Alignas(16 ) float foo [4 ];
6
8
char b ;
7
9
};
8
10
11
+ #pragma pack(push, 4)
12
+ struct UnderAligned {
13
+ int64_t bar ;
14
+ };
15
+ #pragma pack(pop)
16
+
9
17
#endif
Original file line number Diff line number Diff line change @@ -49,6 +49,16 @@ public struct CTypeAligned {
49
49
}
50
50
}
51
51
52
+ public struct CTypeUnderAligned {
53
+ let w : Int32 = 0
54
+ let x : UnderAligned ? = UnderAligned ( )
55
+ let y : SimpleClass
56
+
57
+ public init ( _ y: SimpleClass ) {
58
+ self . y = y
59
+ }
60
+ }
61
+
52
62
public struct GenericStruct < T> {
53
63
let x : Int = 0
54
64
let y : T
Original file line number Diff line number Diff line change @@ -1223,6 +1223,49 @@ func testCTypeAligned() {
1223
1223
1224
1224
testCTypeAligned ( )
1225
1225
1226
+ func testCTypeUnderAligned( ) {
1227
+ let ptr = UnsafeMutablePointer< CTypeUnderAligned> . allocate( capacity: 1 )
1228
+
1229
+ // initWithCopy
1230
+ do {
1231
+ let x = CTypeUnderAligned ( SimpleClass ( x: 23 ) )
1232
+ testInit ( ptr, to: x)
1233
+ }
1234
+
1235
+ // assignWithTake
1236
+ do {
1237
+ let y = CTypeUnderAligned ( SimpleClass ( x: 1 ) )
1238
+
1239
+ // CHECK-NEXT: Before deinit
1240
+ print ( " Before deinit " )
1241
+
1242
+ // CHECK-NEXT: SimpleClass deinitialized!
1243
+ testAssign ( ptr, from: y)
1244
+ }
1245
+
1246
+ // assignWithCopy
1247
+ do {
1248
+ var z = CTypeUnderAligned ( SimpleClass ( x: 5 ) )
1249
+
1250
+ // CHECK-NEXT: Before deinit
1251
+ print ( " Before deinit " )
1252
+
1253
+ // CHECK-NEXT: SimpleClass deinitialized!
1254
+ testAssignCopy ( ptr, from: & z)
1255
+ }
1256
+
1257
+ // CHECK-NEXT: Before deinit
1258
+ print ( " Before deinit " )
1259
+
1260
+ // destroy
1261
+ // CHECK-NEXT: SimpleClass deinitialized!
1262
+ testDestroy ( ptr)
1263
+
1264
+ ptr. deallocate ( )
1265
+ }
1266
+
1267
+ testCTypeUnderAligned ( )
1268
+
1226
1269
#if os(macOS)
1227
1270
func testObjc( ) {
1228
1271
let ptr = UnsafeMutablePointer< ObjcWrapper> . allocate( capacity: 1 )
You can’t perform that action at this time.
0 commit comments