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 {
16551655 if (_fixedAlignment.has_value ())
16561656 return *_fixedAlignment;
16571657
1658+ if (fixedTypeInfo) {
1659+ return *(_fixedAlignment = (*fixedTypeInfo)->getFixedAlignment ());
1660+ }
1661+
16581662 Alignment currentAlignment = Alignment (
16591663 std::max ((Alignment::int_type)1 , minimumAlignment));
16601664 for (auto *entry : entries) {
Original file line number Diff line number Diff line change 11#ifndef SWIFT_TEST_CTYPES_H
22#define SWIFT_TEST_CTYPES_H
33
4+ #include <stdint.h>
5+
46struct BigAlignment {
57 _Alignas(16 ) float foo [4 ];
68 char b ;
79};
810
11+ #pragma pack(push, 4)
12+ struct UnderAligned {
13+ int64_t bar ;
14+ };
15+ #pragma pack(pop)
16+
917#endif
Original file line number Diff line number Diff line change @@ -49,6 +49,16 @@ public struct CTypeAligned {
4949 }
5050}
5151
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+
5262public struct GenericStruct < T> {
5363 let x : Int = 0
5464 let y : T
Original file line number Diff line number Diff line change @@ -1223,6 +1223,49 @@ func testCTypeAligned() {
12231223
12241224testCTypeAligned ( )
12251225
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+
12261269#if os(macOS)
12271270func testObjc( ) {
12281271 let ptr = UnsafeMutablePointer< ObjcWrapper> . allocate( capacity: 1 )
You can’t perform that action at this time.
0 commit comments