@@ -3030,7 +3030,7 @@ SWIFT_RUNTIME_EXPORT
30303030void swift::swift_initRawStructMetadata (StructMetadata *structType,
30313031 StructLayoutFlags structLayoutFlags,
30323032 const TypeLayout *likeTypeLayout,
3033- ssize_t count,
3033+ intptr_t count,
30343034 RawLayoutFlags rawLayoutFlags) {
30353035 auto vwtable = getMutableVWTableForInit (structType, structLayoutFlags);
30363036
@@ -3042,21 +3042,36 @@ void swift::swift_initRawStructMetadata(StructMetadata *structType,
30423042 auto extraInhabitantCount = likeTypeLayout->extraInhabitantCount ;
30433043
30443044 if (isRawLayoutArray (rawLayoutFlags)) {
3045- stride *= std::min (count, (ssize_t )0 );
3045+ // Our count value may be negative, so use 0 if that's the case.
3046+ stride *= std::max (count, (intptr_t )0 );
30463047 size = stride;
30473048 }
30483049
30493050 vwtable->size = size;
30503051 vwtable->stride = stride;
30513052 vwtable->flags = ValueWitnessFlags ()
30523053 .withAlignmentMask (alignMask)
3053- .withCopyable (false );
3054+ .withCopyable (false )
3055+ .withBitwiseTakable (true ); // All raw layouts are assumed
3056+ // to be bitwise takable unless
3057+ // movesAsLike is present.
30543058 vwtable->extraInhabitantCount = extraInhabitantCount;
30553059
30563060 if (shouldRawLayoutMoveAsLike (rawLayoutFlags)) {
30573061 vwtable->flags = vwtable->flags
3058- .withBitwiseTakable (likeTypeLayout->flags .isBitwiseTakable ())
3062+ .withBitwiseTakable (likeTypeLayout->flags .isBitwiseTakable ());
3063+ }
3064+
3065+ // If the calculated size of this raw layout type is available to be put in
3066+ // value buffers, then set the inline storage bit if our like type is also
3067+ // able to be put into inline storage.
3068+ if (size <= NumWords_ValueBuffer) {
3069+ vwtable->flags = vwtable->flags
30593070 .withInlineStorage (likeTypeLayout->flags .isInlineStorage ());
3071+ } else {
3072+ // Otherwise, we're too big to fit in inline storage regardless of the like
3073+ // type's ability to be put in inline storage.
3074+ vwtable->flags = vwtable->flags .withInlineStorage (false );
30603075 }
30613076}
30623077
0 commit comments