Skip to content

Commit c1f99b5

Browse files
committed
Cap type alignment in Swift at 16.
rdar://31411216
1 parent 140ee56 commit c1f99b5

20 files changed

+86
-36
lines changed

include/swift/ABI/MetadataValues.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,9 @@ enum class NominalTypeKind : uint32_t {
110110
#include "MetadataKind.def"
111111
};
112112

113+
/// The maximum supported type alignment.
114+
const size_t MaximumAlignment = 16;
115+
113116
/// Flags stored in the value-witness table.
114117
template <typename int_type>
115118
class TargetValueWitnessFlags {
@@ -119,7 +122,7 @@ class TargetValueWitnessFlags {
119122
// flags for the struct. (The "non-inline" and "has-extra-inhabitants" bits
120123
// still require additional fixup.)
121124
enum : int_type {
122-
AlignmentMask = 0x0000FFFF,
125+
AlignmentMask = 0x000000FF,
123126
IsNonPOD = 0x00010000,
124127
IsNonInline = 0x00020000,
125128
HasExtraInhabitants = 0x00040000,

include/swift/AST/DiagnosticsIRGen.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ ERROR(alignment_dynamic_type_layout_unsupported,none,
6363
ERROR(alignment_less_than_natural,none,
6464
"@_alignment cannot decrease alignment below natural alignment of %0",
6565
(unsigned))
66+
ERROR(alignment_more_than_maximum,none,
67+
"@_alignment cannot increase alignment above maximum alignment of %0",
68+
(unsigned))
6669

6770
#ifndef DIAG_NO_UNDEF
6871
# if defined(DIAG)

lib/ClangImporter/ImportDecl.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2512,6 +2512,10 @@ namespace {
25122512
return nullptr;
25132513
}
25142514

2515+
// Don't import nominal types that are over-aligned.
2516+
if (Impl.isOverAligned(decl))
2517+
return nullptr;
2518+
25152519
Optional<ImportedName> correctSwiftName;
25162520
auto importedName = getClangDeclName(decl, correctSwiftName);
25172521
if (!importedName)
@@ -2997,6 +3001,10 @@ namespace {
29973001
return nullptr;
29983002
}
29993003

3004+
// Don't import nominal types that are over-aligned.
3005+
if (Impl.isOverAligned(decl))
3006+
return nullptr;
3007+
30003008
// FIXME: We should actually support strong ARC references and similar in
30013009
// C structs. That'll require some SIL and IRGen work, though.
30023010
if (decl->isNonTrivialToPrimitiveCopy() ||

lib/ClangImporter/ImportType.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "ImporterImpl.h"
1919
#include "ClangDiagnosticConsumer.h"
2020
#include "swift/Strings.h"
21+
#include "swift/ABI/MetadataValues.h"
2122
#include "swift/AST/ASTContext.h"
2223
#include "swift/AST/Decl.h"
2324
#include "swift/AST/DiagnosticEngine.h"
@@ -48,6 +49,16 @@ static bool isImportedCFPointer(clang::QualType clangType, Type type) {
4849
(type->is<ClassType>() || type->isClassExistentialType()));
4950
}
5051

52+
bool ClangImporter::Implementation::isOverAligned(const clang::TypeDecl *decl) {
53+
auto type = getClangASTContext().getTypeDeclType(decl);
54+
return isOverAligned(type);
55+
}
56+
57+
bool ClangImporter::Implementation::isOverAligned(clang::QualType type) {
58+
auto align = getClangASTContext().getTypeAlignInChars(type);
59+
return align.getQuantity() > MaximumAlignment;
60+
}
61+
5162
namespace {
5263
/// Various types that we want to do something interesting to after
5364
/// importing them.
@@ -377,9 +388,10 @@ namespace {
377388
pointeeQualType, ImportTypeKind::Pointee, AllowNSUIntegerAsInt,
378389
Bridgeability::None);
379390

380-
// If the pointed-to type is unrepresentable in Swift, import as
391+
// If the pointed-to type is unrepresentable in Swift, or its C
392+
// alignment is greater than the maximum Swift alignment, import as
381393
// OpaquePointer.
382-
if (!pointeeType) {
394+
if (!pointeeType || Impl.isOverAligned(pointeeQualType)) {
383395
auto opaquePointer = Impl.SwiftContext.getOpaquePointerDecl();
384396
if (!opaquePointer)
385397
return Type();

lib/ClangImporter/ImporterImpl.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -961,6 +961,11 @@ class LLVM_LIBRARY_VISIBILITY ClangImporter::Implementation
961961
/// bound of "Hashable", which is used to validate NSDictionary/NSSet.
962962
bool matchesHashableBound(Type type);
963963

964+
/// \brief Determines whether the type declared by the given declaration
965+
/// is over-aligned.
966+
bool isOverAligned(const clang::TypeDecl *typeDecl);
967+
bool isOverAligned(clang::QualType type);
968+
964969
/// \brief Look up and attempt to import a Clang declaration with
965970
/// the given name.
966971
Decl *importDeclByName(StringRef name);

lib/IRGen/GenStruct.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -829,7 +829,8 @@ class ClangRecordLowering {
829829
ClangDecl(clangDecl), ClangContext(clangDecl->getASTContext()),
830830
ClangLayout(ClangContext.getASTRecordLayout(clangDecl)),
831831
TotalStride(Size(ClangLayout.getSize().getQuantity())),
832-
TotalAlignment(Alignment(ClangLayout.getAlignment().getQuantity())) {
832+
TotalAlignment(IGM.getCappedAlignment(
833+
Alignment(ClangLayout.getAlignment()))) {
833834
SpareBits.reserve(TotalStride.getValue() * 8);
834835
}
835836

lib/IRGen/GenType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
//
1515
//===----------------------------------------------------------------------===//
1616

17+
#include "swift/ABI/MetadataValues.h"
1718
#include "swift/AST/CanTypeVisitor.h"
1819
#include "swift/AST/Decl.h"
1920
#include "swift/AST/GenericEnvironment.h"
@@ -50,6 +51,10 @@
5051
using namespace swift;
5152
using namespace irgen;
5253

54+
Alignment IRGenModule::getCappedAlignment(Alignment align) {
55+
return std::min(align, Alignment(MaximumAlignment));
56+
}
57+
5358
llvm::DenseMap<TypeBase*, TypeCacheEntry> &
5459
TypeConverter::Types_t::getCacheFor(bool isDependent, bool completelyFragile) {
5560
if (completelyFragile) {
@@ -1638,6 +1643,7 @@ TypeCacheEntry TypeConverter::convertType(CanType ty) {
16381643
Size size;
16391644
Alignment align;
16401645
std::tie(llvmTy, size, align) = convertPrimitiveBuiltin(IGM, ty);
1646+
align = IGM.getCappedAlignment(align);
16411647
return createPrimitive(llvmTy, size, align);
16421648
}
16431649

lib/IRGen/IRGen.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,7 @@ class Alignment {
239239

240240
constexpr Alignment() : Value(0) {}
241241
constexpr explicit Alignment(int_type Value) : Value(Value) {}
242+
explicit Alignment(clang::CharUnits value) : Value(value.getQuantity()) {}
242243

243244
constexpr int_type getValue() const { return Value; }
244245
constexpr int_type getMaskValue() const { return Value - 1; }

lib/IRGen/IRGenModule.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,7 @@ class IRGenModule {
747747
clang::CanQual<clang::Type> getClangType(CanType type);
748748
clang::CanQual<clang::Type> getClangType(SILType type);
749749
clang::CanQual<clang::Type> getClangType(SILParameterInfo param);
750-
750+
751751
const clang::ASTContext &getClangASTContext() {
752752
assert(ClangASTContext &&
753753
"requesting clang AST context without clang importer!");
@@ -761,6 +761,8 @@ class IRGenModule {
761761
ResilienceExpansion getResilienceExpansionForLayout(NominalTypeDecl *decl);
762762
ResilienceExpansion getResilienceExpansionForLayout(SILGlobalVariable *var);
763763

764+
Alignment getCappedAlignment(Alignment alignment);
765+
764766
SpareBitVector getSpareBitsForType(llvm::Type *scalarTy, Size size);
765767

766768
MetadataLayout &getMetadataLayout(NominalTypeDecl *decl);

lib/IRGen/StructLayout.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,8 +120,14 @@ void irgen::applyLayoutAttributes(IRGenModule &IGM,
120120
else if (value < MinimumAlign.getValue())
121121
Diags.diagnose(alignment->getLocation(),
122122
diag::alignment_less_than_natural, MinimumAlign.getValue());
123-
else
124-
MinimumAlign = Alignment(value);
123+
else {
124+
auto requestedAlignment = Alignment(value);
125+
MinimumAlign = IGM.getCappedAlignment(requestedAlignment);
126+
if (requestedAlignment > MinimumAlign)
127+
Diags.diagnose(alignment->getLocation(),
128+
diag::alignment_more_than_maximum,
129+
MinimumAlign.getValue());
130+
}
125131
}
126132
}
127133

stdlib/public/SDK/simd/simd.swift.gyb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ cardinal = { 2:'two', 3:'three', 4:'four'}
3030
% vectype = ctype[scalar] + str(count)
3131
% llvm_vectype = "Vec" + str(count) + "x" + llvm_type[scalar]
3232
% vecsize = (8 if scalar == 'Double' else 4) * (4 if count == 3 else count)
33+
% vecalign = (16 if vecsize > 16 else vecsize)
3334
% extractelement = "extractelement_" + llvm_vectype + "_Int32"
3435
% insertelement = "insertelement_" + llvm_vectype + "_" + llvm_type[scalar] + "_Int32"
3536
% is_floating = scalar in floating_types
@@ -40,7 +41,7 @@ cardinal = { 2:'two', 3:'three', 4:'four'}
4041
/// A vector of ${cardinal[count]} `${scalar}`. This corresponds to the C and
4142
/// Obj-C type `vector_${vectype}` and the C++ type `simd::${vectype}`.
4243
@_fixed_layout
43-
@_alignment(${vecsize})
44+
@_alignment(${vecalign})
4445
public struct ${vectype} {
4546
4647
public var _value: Builtin.${llvm_vectype}

test/DebugInfo/alignment.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
22

3-
@_alignment(32)
4-
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "S32"
5-
// CHECK-SAME: align: 256,
6-
struct S32 { var x, y, z, w: Float }
3+
@_alignment(8)
4+
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "S8"
5+
// CHECK-SAME: align: 64,
6+
struct S8 { var x, y, z, w: Float }
77

88
@_alignment(16)
99
// CHECK: !DICompositeType(tag: DW_TAG_structure_type, name: "E16"
@@ -13,5 +13,5 @@ enum E16 {
1313
case I(Int64)
1414
}
1515

16-
var s: S32
16+
var s: S8
1717
var e: E16

test/IRGen/builtins.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func generic_sizeof_alignof_test<T>(_: T) {
191191
// CHECK: [[T0:%.*]] = getelementptr inbounds i8*, i8** [[T:%.*]], i32 9
192192
// CHECK-NEXT: [[T1:%.*]] = load i8*, i8** [[T0]]
193193
// CHECK-NEXT: [[T2:%.*]] = ptrtoint i8* [[T1]] to i64
194-
// CHECK-NEXT: [[T3:%.*]] = and i64 [[T2]], 65535
194+
// CHECK-NEXT: [[T3:%.*]] = and i64 [[T2]], 255
195195
// CHECK-NEXT: [[ALIGN:%.*]] = add i64 [[T3]], 1
196196
// CHECK-NEXT: store i64 [[ALIGN]], i64* [[A:%.*]]
197197
var a = Builtin.alignof(T.self)

test/IRGen/existentials_opaque_boxed.sil

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s
1+
// RUN: %target-swift-frontend -assume-parsing-unqualified-ownership-sil %s -emit-ir | %FileCheck %s -check-prefix=CHECK -check-prefix=CHECK-%target-ptrsize
22

33
sil_stage canonical
44

@@ -135,7 +135,7 @@ entry:
135135
// CHECK: [[VW_ADDR2:%.*]] = getelementptr inbounds i8*, i8** [[VWT2]], i32 8
136136
// CHECK: [[VW2:%.*]] = load i8*, i8** [[VW_ADDR2]]
137137
// CHECK: [[SIZE:%.*]] = ptrtoint i8* [[VW2]] to {{(i64|i32)}}
138-
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 65535
138+
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 255
139139
// CHECK: [[HEADERSIZEPLUSALIGN:%.*]] = add {{(i64 16|i32 8)}}, [[ALIGNMASK]]
140140
// CHECK: [[NOTALIGNMASK:%.*]] = xor {{(i64|i32)}} [[ALIGNMASK]], -1
141141
// CHECK: [[ALIGNEDSTART:%.*]] = and {{(i64|i32)}} [[HEADERSIZEPLUSALIGN]], [[NOTALIGNMASK]]
@@ -178,7 +178,7 @@ bb0(%0 : $*Existential):
178178
// CHECK: boxed:
179179
// CHECK: [[REFADDR:%.*]] = bitcast [{{(24|12)}} x i8]* %0 to %swift.refcounted**
180180
// CHECK: [[REF:%.*]] = load %swift.refcounted*, %swift.refcounted** [[REFADDR]]
181-
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 65535
181+
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 255
182182
// CHECK: [[HEADERSIZEPLUSALIGN:%.*]] = add {{(i64 16|i32 8)}}, [[ALIGNMASK]]
183183
// CHECK: [[NOTALIGNMASK:%.*]] = xor {{(i64|i32)}} [[ALIGNMASK]], -1
184184
// CHECK: [[ALIGNEDSTART:%.*]] = and {{(i64|i32)}} [[HEADERSIZEPLUSALIGN]], [[NOTALIGNMASK]]
@@ -219,7 +219,7 @@ bb0(%0 : $*Existential):
219219
// CHECK: ret %swift.opaque* [[VALUEADDRINLINE]]
220220

221221
// CHECK: boxed:
222-
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 65535
222+
// CHECK: [[ALIGNMASK:%.*]] = and {{(i64|i32)}} [[FLAGS]], 255
223223
// CHECK: [[OPAQUE_ADDR:%.*]] = bitcast [{{(24|12)}} x i8]* %0 to %swift.opaque*
224224
// CHECK: [[REFANDADDR:%.*]] = call swiftcc { %swift.refcounted*, %swift.opaque* } @swift_makeBoxUnique(%swift.opaque* [[OPAQUE_ADDR]], %swift.type* %1, {{(i64|i32)}} [[ALIGNMASK]])
225225
// CHECK: [[REF:%.*]] = extractvalue { %swift.refcounted*, %swift.opaque* } [[REFANDADDR]], 0
@@ -493,7 +493,7 @@ bb0(%0 : $*Existential):
493493
return %t : $()
494494
}
495495

496-
@_alignment(32)
496+
@_alignment(16)
497497
struct FixedOveralign : Existential {
498498
var x : Int64
499499
}
@@ -504,10 +504,11 @@ struct FixedOveralign : Existential {
504504
// CHECK: [[CONTAINER:%.*]] = alloca %T25existentials_opaque_boxed11ExistentialP
505505
// CHECK: [[INLINEBUFFER:%.*]] = getelementptr inbounds %T25existentials_opaque_boxed11ExistentialP, %T25existentials_opaque_boxed11ExistentialP* [[CONTAINER]], i32 0, i32 0
506506
// CHECK: [[INLINEBUFFER:%.*]] = getelementptr inbounds %T25existentials_opaque_boxed11ExistentialP, %T25existentials_opaque_boxed11ExistentialP* [[CONTAINER]], i32 0, i32 0
507-
// CHECK: [[BOX:%.*]] = call noalias %swift.refcounted* @swift_allocObject(%swift.type* getelementptr inbounds (%swift.full_boxmetadata, %swift.full_boxmetadata* @metadata.3, i32 0, i32 2), {{(i64|i32)}} 64, {{(i64|i32)}} 31)
508-
// CHECK: [[BOX_ADDR:%.*]] = bitcast %swift.refcounted* [[BOX]] to <{ %swift.refcounted, [{{(16|24)}} x i8], [32 x i8] }>*
509-
// CHECK: [[VALUE_ADDR:%.*]] = getelementptr inbounds <{ %swift.refcounted, [{{(16|24)}} x i8], [32 x i8] }>, <{ %swift.refcounted, [{{(16|24)}} x i8], [32 x i8] }>* [[BOX_ADDR]], i32 0, i32 {{(1|2)}}
510-
// CHECK: [[INIT_EXIST_ADDR:%.*]] = bitcast [32 x i8]* [[VALUE_ADDR]] to %T25existentials_opaque_boxed14FixedOveralignV*
507+
// CHECK: [[BOX:%.*]] = call noalias %swift.refcounted* @swift_allocObject(%swift.type* getelementptr inbounds (%swift.full_boxmetadata, %swift.full_boxmetadata* @metadata.3, i32 0, i32 2), {{(i64|i32)}} 32, {{(i64|i32)}} 15)
508+
// CHECK-64: [[BOX_ADDR:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[BOX_TYPE:<{ %swift.refcounted, \[16 x i8\] }>]]*
509+
// CHECK-32: [[BOX_ADDR:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[BOX_TYPE:<{ %swift.refcounted, \[8 x i8\], \[16 x i8\] }>]]*
510+
// CHECK: [[VALUE_ADDR:%.*]] = getelementptr inbounds [[BOX_TYPE]], [[BOX_TYPE]]* [[BOX_ADDR]], i32 0, i32 {{(1|2)}}
511+
// CHECK: [[INIT_EXIST_ADDR:%.*]] = bitcast [16 x i8]* [[VALUE_ADDR]] to %T25existentials_opaque_boxed14FixedOveralignV*
511512
// CHECK: [[INLINEBUFFER_ADDR:%.*]] = bitcast [{{(24|12)}} x i8]* [[INLINEBUFFER]] to %swift.refcounted**
512513
// CHECK: store %swift.refcounted* [[BOX]], %swift.refcounted** [[INLINEBUFFER_ADDR]]
513514
// CHECK: ret void

test/IRGen/global_resilience.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ bb0:
142142
// CHECK: [[SIZE_ADDR:%.*]] = getelementptr inbounds i8*, i8** [[VWT]], i32 8
143143
// CHECK: [[SIZEWITNESS:%.*]] = load i8*, i8** [[SIZE_ADDR]]
144144
// CHECK: [[SIZE:%.*]] = ptrtoint i8* [[SIZEWITNESS]]
145-
// CHECK: [[ALIGN:%.*]] = and {{.*}} [[FLAGS]], 65535
145+
// CHECK: [[ALIGN:%.*]] = and {{.*}} [[FLAGS]], 255
146146
// CHECK: [[PTR:%.*]] = call noalias i8* @swift_slowAlloc({{.*}} [[SIZE]], {{.*}} [[ALIGN]])
147147
// CHECK: [[ADDR:%.*]] = bitcast %swift.opaque* %1 to i8**
148148
// CHECK: store i8* [[PTR]], i8** [[ADDR]]

test/IRGen/indirect_argument.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ struct Huge {
66
var x, y, z, w, v: Builtin.Word
77
}
88

9-
@_alignment(32)
9+
@_alignment(16)
1010
struct HugeAlignment {
1111
var x, y, z, w, v: Builtin.Word
1212
}

test/IRGen/int_to_fp.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sil_stage canonical
88
import Builtin
99

1010
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc float @test_large(i2048* noalias nocapture dereferenceable(256)
11-
// CHECK: %1 = load i2048, i2048* %0, align 256
11+
// CHECK: %1 = load i2048, i2048* %0, align 16
1212
// CHECK: %2 = trunc i2048 %1 to i64
1313
// CHECK: %3 = sitofp i64 %2 to float
1414
// CHECK: ret float %3

test/IRGen/partial_apply.sil

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ sil public_external @captured_fixed_and_dependent_params : $@convention(thin) <A
236236
// CHECK: [[T_FLAGS_ADDR:%.*]] = getelementptr {{.*}} [[T_VWTABLE]], i32 9
237237
// CHECK: [[T_FLAGS_PTR:%.*]] = load {{.*}} [[T_FLAGS_ADDR]]
238238
// CHECK: [[T_FLAGS:%.*]] = ptrtoint {{.*}} [[T_FLAGS_PTR]] to [[WORD]]
239-
// CHECK: [[T_ALIGN_MASK:%.*]] = and [[WORD]] [[T_FLAGS]], 65535
239+
// CHECK: [[T_ALIGN_MASK:%.*]] = and [[WORD]] [[T_FLAGS]], 255
240240
// CHECK: [[T_ALIGN_MASK_NOT:%.*]] = xor [[WORD]] [[T_ALIGN_MASK]], -1
241241
// -- 32 is 64-bit offset of 'T' field, 16 for obj header + 8 for T metadata + 8 for SwiftClass field
242242
// CHECK-64: [[T_UP_TO_ALIGN_1:%.*]] = add i64 32, [[T_ALIGN_MASK]]

test/IRGen/struct_with_resilient_type.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ struct ProtAndResilStruct {
2828
fooImp.foo(ptr: bar)
2929
}
3030
// CHECK-LABEL: define{{.*}} @"$S26struct_with_resilient_type18ProtAndResilStructV3baryyFTc"(%T26struct_with_resilient_type18ProtAndResilStructV* noalias nocapture)
31-
// CHECK: %flags.alignmentMask = and i64 %flags, 65535
31+
// CHECK: %flags.alignmentMask = and i64 %flags, 255
3232
// CHECK: [[XOR_ALIGN:%.*]] = xor i64 %flags.alignmentMask, -1
3333
// CHECK: [[INIT_OFFSET:%.*]] = add i64 16, %flags.alignmentMask
3434
// CHECK: [[T0:%.*]] = and i64 [[INIT_OFFSET]], [[XOR_ALIGN]]

test/IRGen/typed_boxes.sil

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,22 +32,23 @@ entry:
3232
return undef : $()
3333
}
3434

35-
@_alignment(32)
35+
@_alignment(16)
3636
struct OverAligned {
3737
var x, y, z, w: Builtin.Int64
3838
}
3939

40-
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @pod_box_32_32
41-
sil @pod_box_32_32 : $@convention(thin) () -> () {
40+
// CHECK-LABEL: define{{( dllexport)?}}{{( protected)?}} swiftcc void @pod_box_32_16
41+
sil @pod_box_32_16 : $@convention(thin) () -> () {
4242
entry:
43-
// CHECK: [[BOX:%.*]] = call noalias %swift.refcounted* @swift_allocObject(%swift.type* {{.*}} [[POD_32_32_METADATA:@metadata[0-9.]*]], {{.*}} [[WORD]] 64, [[WORD]] 31)
43+
// CHECK: [[BOX:%.*]] = call noalias %swift.refcounted* @swift_allocObject(%swift.type* {{.*}} [[POD_32_16_METADATA:@metadata[0-9.]*]], {{.*}} [[WORD]] 48, [[WORD]] 15)
4444
%a = alloc_box $<τ_0_0> { var τ_0_0 } <OverAligned>
45-
// CHECK-32: [[BOX_RAW:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[POD_32_32_LAYOUT:<\{ %swift.refcounted, \[24 x i8\], \[32 x i8\] \}>]]*
46-
// CHECK-64: [[BOX_RAW:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[POD_32_32_LAYOUT:<\{ %swift.refcounted, \[16 x i8\], \[32 x i8\] \}>]]*
47-
// CHECK: [[BOX_DATA:%.*]] = getelementptr inbounds [[POD_32_32_LAYOUT]], [[POD_32_32_LAYOUT]]* [[BOX_RAW]], i32 0, i32 2
45+
// CHECK-32: [[BOX_RAW:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[POD_32_16_LAYOUT:<\{ %swift.refcounted, \[8 x i8\], \[32 x i8\] \}>]]*
46+
// CHECK-32: [[BOX_DATA:%.*]] = getelementptr inbounds [[POD_32_16_LAYOUT]], [[POD_32_16_LAYOUT]]* [[BOX_RAW]], i32 0, i32 2
47+
// CHECK-64: [[BOX_RAW:%.*]] = bitcast %swift.refcounted* [[BOX]] to [[POD_32_16_LAYOUT:<\{ %swift.refcounted, \[32 x i8\] \}>]]*
48+
// CHECK-64: [[BOX_DATA:%.*]] = getelementptr inbounds [[POD_32_16_LAYOUT]], [[POD_32_16_LAYOUT]]* [[BOX_RAW]], i32 0, i32 1
4849
// CHECK: [[BOX_DATA_1:%.*]] = bitcast [32 x i8]* [[BOX_DATA]] to %T11typed_boxes11OverAlignedV*
4950
%b = project_box %a : $<τ_0_0> { var τ_0_0 } <OverAligned>, 0
50-
// CHECK: call void @swift_deallocUninitializedObject(%swift.refcounted* [[BOX]], [[WORD]] 64, [[WORD]] 31)
51+
// CHECK: call void @swift_deallocUninitializedObject(%swift.refcounted* [[BOX]], [[WORD]] 48, [[WORD]] 15)
5152
dealloc_box %a : $<τ_0_0> { var τ_0_0 } <OverAligned>
5253
return undef : $()
5354
}

0 commit comments

Comments
 (0)