From 22349bcfb9b492c5f0aa795dca26d26e0b878839 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Fri, 9 Aug 2024 11:17:03 -0700 Subject: [PATCH] Use intptr_t instead of ssize_t and more test fixes --- include/swift/Runtime/Metadata.h | 2 +- include/swift/Runtime/RuntimeFunctions.def | 2 +- lib/AST/Decl.cpp | 2 +- stdlib/public/runtime/Metadata.cpp | 23 ++++++++++++++++++---- test/IRGen/raw_layout.swift | 6 +++--- 5 files changed, 25 insertions(+), 10 deletions(-) diff --git a/include/swift/Runtime/Metadata.h b/include/swift/Runtime/Metadata.h index e4ebd31a431..80f8ca8cf76 100644 --- a/include/swift/Runtime/Metadata.h +++ b/include/swift/Runtime/Metadata.h @@ -1059,7 +1059,7 @@ SWIFT_RUNTIME_EXPORT void swift_initRawStructMetadata(StructMetadata *self, StructLayoutFlags structLayoutFlags, const TypeLayout *likeType, - ssize_t count, + intptr_t count, RawLayoutFlags rawLayoutFlags); /// Check if the given generic arguments are valid inputs for the generic type diff --git a/include/swift/Runtime/RuntimeFunctions.def b/include/swift/Runtime/RuntimeFunctions.def index 89de9e97391..6e04138d00f 100644 --- a/include/swift/Runtime/RuntimeFunctions.def +++ b/include/swift/Runtime/RuntimeFunctions.def @@ -2825,7 +2825,7 @@ FUNCTION(GenericInstantiateLayoutString, // void swift_initRawStructMetadata(Metadata *structType, // StructLayoutFlags structLayoutFlags, // const TypeLayout *likeType, -// ssize_t count, +// intptr_t count, // RawLayoutFlags rawLayoutFlags); FUNCTION(InitRawStructMetadata, swift_initRawStructMetadata, diff --git a/lib/AST/Decl.cpp b/lib/AST/Decl.cpp index 1aac987359e..df14df464b2 100644 --- a/lib/AST/Decl.cpp +++ b/lib/AST/Decl.cpp @@ -5682,7 +5682,7 @@ GenericTypeParamDecl *GenericTypeParamDecl::create( auto numTypeReprs = 0; - if (opaqueTypeRepr) + if (isOpaqueType) numTypeReprs = 1; auto numSourceLocs = 0; diff --git a/stdlib/public/runtime/Metadata.cpp b/stdlib/public/runtime/Metadata.cpp index 1eb81feac39..dab4b8441b3 100644 --- a/stdlib/public/runtime/Metadata.cpp +++ b/stdlib/public/runtime/Metadata.cpp @@ -3030,7 +3030,7 @@ SWIFT_RUNTIME_EXPORT void swift::swift_initRawStructMetadata(StructMetadata *structType, StructLayoutFlags structLayoutFlags, const TypeLayout *likeTypeLayout, - ssize_t count, + intptr_t count, RawLayoutFlags rawLayoutFlags) { auto vwtable = getMutableVWTableForInit(structType, structLayoutFlags); @@ -3042,7 +3042,8 @@ void swift::swift_initRawStructMetadata(StructMetadata *structType, auto extraInhabitantCount = likeTypeLayout->extraInhabitantCount; if (isRawLayoutArray(rawLayoutFlags)) { - stride *= std::min(count, (ssize_t)0); + // Our count value may be negative, so use 0 if that's the case. + stride *= std::max(count, (intptr_t)0); size = stride; } @@ -3050,13 +3051,27 @@ void swift::swift_initRawStructMetadata(StructMetadata *structType, vwtable->stride = stride; vwtable->flags = ValueWitnessFlags() .withAlignmentMask(alignMask) - .withCopyable(false); + .withCopyable(false) + .withBitwiseTakable(true); // All raw layouts are assumed + // to be bitwise takable unless + // movesAsLike is present. vwtable->extraInhabitantCount = extraInhabitantCount; if (shouldRawLayoutMoveAsLike(rawLayoutFlags)) { vwtable->flags = vwtable->flags - .withBitwiseTakable(likeTypeLayout->flags.isBitwiseTakable()) + .withBitwiseTakable(likeTypeLayout->flags.isBitwiseTakable()); + } + + // If the calculated size of this raw layout type is available to be put in + // value buffers, then set the inline storage bit if our like type is also + // able to be put into inline storage. + if (size <= NumWords_ValueBuffer) { + vwtable->flags = vwtable->flags .withInlineStorage(likeTypeLayout->flags.isInlineStorage()); + } else { + // Otherwise, we're too big to fit in inline storage regardless of the like + // type's ability to be put in inline storage. + vwtable->flags = vwtable->flags.withInlineStorage(false); } } diff --git a/test/IRGen/raw_layout.swift b/test/IRGen/raw_layout.swift index a24ad9cd1e3..fe606fe0b52 100644 --- a/test/IRGen/raw_layout.swift +++ b/test/IRGen/raw_layout.swift @@ -428,7 +428,7 @@ entry(%0 : $*Cell): // CHECK-LABEL: define {{.*}} void @"$s10raw_layout18ConcreteMoveAsLikeVwxx"(ptr {{.*}} %object, ptr %ConcreteMoveAsLike) // CHECK: [[OBJ_CELL:%.*]] = getelementptr inbounds %T10raw_layout18ConcreteMoveAsLikeV, ptr %object, i32 0, i32 0 -// CHECK: {{invoke void|invoke ptr|call ptr}} @{{.*}}(ptr [[OBJ_CELL]]) +// CHECK: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJ_CELL]]) //===----------------------------------------------------------------------===// // ConcreteMoveAsLike initializeWithTake @@ -555,7 +555,7 @@ entry(%0 : $*Cell): // CHECK: [[NEW_I:%.*]] = add {{i64|i32}} [[I]], 1 // CHECK: store {{i64|i32}} [[NEW_I]], ptr [[I_ALLOCA]] // CHECK: [[OBJECT:%.*]] = getelementptr inbounds %TSo24NonBitwiseTakableCXXTypeV, ptr [[OBJ_VECTOR]], {{i64|i32}} [[I]] -// CHECK-NEXT: {{invoke void|invoke ptr|call ptr}} @{{.*}}(ptr [[OBJECT]]) +// CHECK-NEXT: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJECT]]) // This may or may not be in the loop_br // CHECK: [[EQ_CMP:%.*]] = icmp eq {{i64|i32}} [[NEW_I]], 2 @@ -747,7 +747,7 @@ entry(%0 : $*Cell): // CHECK: [[NEW_I:%.*]] = add {{i64|i32}} [[I]], 1 // CHECK: store {{i64|i32}} [[NEW_I]], ptr [[I_ALLOCA]] // CHECK: [[OBJECT:%.*]] = getelementptr inbounds %TSo24NonBitwiseTakableCXXTypeV, ptr [[OBJ_VECTOR]], {{i64|i32}} [[I]] -// CHECK-NEXT: {{invoke void|invoke ptr|call ptr}} @{{.*}}(ptr [[OBJECT]]) +// CHECK-NEXT: {{invoke void|invoke ptr|call void}} @{{.*}}(ptr [[OBJECT]]) // This may or may not be in the loop_br // CHECK: [[EQ_CMP:%.*]] = icmp eq {{i64|i32}} [[NEW_I]], 4