@@ -116,20 +116,20 @@ TEST(GeneratedMessageTest, RecursiveMessageSize) {
116
116
ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 40 );
117
117
118
118
struct MockGeneratedLazy : public MockMessageBase { // 16 bytes
119
- int has_bits[1 ]; // 4 bytes
120
- int cached_size; // 4 bytes
121
- void * a[2 ]; // 16 bytes (lazy)
122
- int32_t i; // 4 bytes
123
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
119
+ int has_bits[1 ]; // 4 bytes
120
+ int cached_size; // 4 bytes
121
+ void * a[2 ]; // 16 bytes (lazy)
122
+ int32_t i; // 4 bytes
123
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
124
124
// + 0-4 bytes padding
125
125
};
126
126
ABSL_CHECK_MESSAGE_SIZE (MockGeneratedLazy, 48 );
127
127
128
128
struct MockGeneratedSplit : public MockMessageBase { // 16 bytes
129
129
int has_bits[1 ]; // 4 bytes
130
130
int cached_size; // 4 bytes
131
- void * split; // 8 bytes
132
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
131
+ void * split; // 8 bytes
132
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
133
133
// + 0-4 bytes padding
134
134
};
135
135
ABSL_CHECK_MESSAGE_SIZE (MockGeneratedSplit, 32 );
@@ -172,13 +172,26 @@ TEST(GeneratedMessageTest, OneStringSize) {
172
172
TEST (GeneratedMessageTest, MoreStringSize) {
173
173
// TODO: remove once synthetic_pdproto lands.
174
174
#ifndef PROTOBUF_FORCE_SPLIT
175
- struct MockGenerated : public MockMessageBase { // 16 bytes
176
- int cached_size; // 4 bytes
177
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
178
- // + 0-4 bytes padding
179
- MockRepeatedPtrField data; // 24 bytes
180
- };
181
- ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 48 );
175
+ if constexpr (internal::EnableExperimentalHintHasBitsForRepeatedFields ()) {
176
+ struct MockGenerated : public MockMessageBase { // 16 bytes
177
+ int has_bits[1 ]; // 4 bytes
178
+ int cached_size; // 4 bytes
179
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
180
+ // + 0-4 bytes padding
181
+ MockRepeatedPtrField data; // 24 bytes
182
+ };
183
+ ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 48 );
184
+ EXPECT_EQ (sizeof (proto2_unittest::MoreString), sizeof (MockGenerated));
185
+ } else {
186
+ struct MockGenerated : public MockMessageBase { // 16 bytes
187
+ int cached_size; // 4 bytes
188
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
189
+ // + 0-4 bytes padding
190
+ MockRepeatedPtrField data; // 24 bytes
191
+ };
192
+ ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 48 );
193
+ EXPECT_EQ (sizeof (proto2_unittest::MoreString), sizeof (MockGenerated));
194
+ }
182
195
#else // !PROTOBUF_FORCE_SPLIT
183
196
struct MockGenerated : public MockMessageBase { // 16 bytes
184
197
int cached_size; // 4 bytes
@@ -187,8 +200,8 @@ TEST(GeneratedMessageTest, MoreStringSize) {
187
200
// + 0-4 bytes padding
188
201
};
189
202
ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 32 );
190
- #endif // PROTOBUF_FORCE_SPLIT
191
203
EXPECT_EQ (sizeof (proto2_unittest::MoreString), sizeof (MockGenerated));
204
+ #endif // PROTOBUF_FORCE_SPLIT
192
205
}
193
206
194
207
TEST (GeneratedMessageTest, Int32MessageSize) {
@@ -288,26 +301,26 @@ TEST(GeneratedMessageTest, FieldOrderingsSize) {
288
301
ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 80 );
289
302
290
303
struct MockGeneratedExperiments : public MockMessageBase { // 16 bytes
291
- int has_bits[1 ]; // 4 bytes
292
- int donated[1 ]; // 4 bytes
293
- int cached_size; // 4 bytes
304
+ int has_bits[1 ]; // 4 bytes
305
+ int donated[1 ]; // 4 bytes
306
+ int cached_size; // 4 bytes
294
307
// + 0-4 bytes padding
295
- MockExtensionSet extensions; // 24 bytes
296
- std::string my_string; // sizeof(std::string)
308
+ MockExtensionSet extensions; // 24 bytes
309
+ std::string my_string; // sizeof(std::string)
297
310
void * optional_nested_message[2 ]; // 16 bytes (lazy)
298
311
int64_t my_int; // 8 bytes
299
312
float my_float; // 4 bytes
300
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
313
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
301
314
// + 0-4 bytes padding
302
315
};
303
316
ABSL_CHECK_MESSAGE_SIZE (MockGeneratedExperiments, 112 );
304
317
305
318
struct MockGeneratedSplit : public MockMessageBase { // 16 bytes
306
319
int has_bits[1 ]; // 4 bytes
307
320
int cached_size; // 4 bytes
308
- MockExtensionSet extensions; // 24 bytes
309
- void * split; // 8 bytes
310
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
321
+ MockExtensionSet extensions; // 24 bytes
322
+ void * split; // 8 bytes
323
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
311
324
// + 0-4 bytes padding
312
325
};
313
326
ABSL_CHECK_MESSAGE_SIZE (MockGeneratedSplit, 56 );
@@ -359,11 +372,11 @@ TEST(GeneratedMessageTest, TestMessageSize) {
359
372
ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 56 );
360
373
361
374
struct MockGeneratedSplit : public MockMessageBase { // 16 bytes
362
- int has_bits[1 ]; // 4 bytes
363
- int cached_size; // 4 bytes
364
- void * split; // 8 bytes
365
- PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
366
- // + 0-4 bytes padding
375
+ int has_bits[1 ]; // 4 bytes
376
+ int cached_size; // 4 bytes
377
+ void * split; // 8 bytes
378
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
379
+ // + 0-4 bytes padding
367
380
};
368
381
ABSL_CHECK_MESSAGE_SIZE (MockGeneratedSplit, 32 );
369
382
#ifndef PROTOBUF_FORCE_SPLIT
@@ -378,6 +391,33 @@ TEST(GeneratedMessageTest, TestMessageSize) {
378
391
TEST (GeneratedMessageTest, PackedTypesSize) {
379
392
// TODO: remove once synthetic_pdproto lands.
380
393
#ifndef PROTOBUF_FORCE_SPLIT
394
+ struct MockGeneratedWithHasBits : public MockMessageBase { // 16 bytes
395
+ int has_bits[1 ]; // 4 bytes
396
+ int cached_size; // 4 bytes
397
+ MockRepeatedField packed_int32; // 16 bytes
398
+ int packed_int32_cached_byte_size; // 4 bytes + 4 bytes padding
399
+ MockRepeatedField packed_int64; // 16 bytes
400
+ int packed_int64_cached_byte_size; // 4 bytes + 4 bytes padding
401
+ MockRepeatedField packed_uint32; // 16 bytes
402
+ int packed_uint32_cached_byte_size; // 4 bytes + 4 bytes padding
403
+ MockRepeatedField packed_uint64; // 16 bytes
404
+ int packed_uint64_cached_byte_size; // 4 bytes + 4 bytes padding
405
+ MockRepeatedField packed_sint32; // 16 bytes
406
+ int packed_sint32_cached_byte_size; // 4 bytes + 4 bytes padding
407
+ MockRepeatedField packed_sint64; // 16 bytes
408
+ int packed_sint64_cached_byte_size; // 4 bytes + 4 bytes padding
409
+ MockRepeatedField packed_fixed32; // 16 bytes
410
+ MockRepeatedField packed_fixed64; // 16 bytes
411
+ MockRepeatedField packed_sfixed32; // 16 bytes
412
+ MockRepeatedField packed_sfixed64; // 16 bytes
413
+ MockRepeatedField packed_float; // 16 bytes
414
+ MockRepeatedField packed_double; // 16 bytes
415
+ MockRepeatedField packed_bool; // 16 bytes
416
+ MockRepeatedField packed_enum; // 16 bytes
417
+ int packed_enum_cached_byte_size; // 4 bytes
418
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
419
+ // + 4-0 bytes padding
420
+ };
381
421
struct MockGenerated : public MockMessageBase { // 16 bytes
382
422
MockRepeatedField packed_int32; // 16 bytes
383
423
int packed_int32_cached_byte_size; // 4 bytes + 4 bytes padding
@@ -402,10 +442,21 @@ TEST(GeneratedMessageTest, PackedTypesSize) {
402
442
int packed_enum_cached_byte_size; // 4 bytes
403
443
int cached_size; // 4 bytes
404
444
PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
405
- // + 0-4 bytes padding
445
+ // + 4-0 bytes padding
406
446
};
407
- ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 16 * 15 + 8 * 6 + 8 );
447
+ if constexpr (internal::EnableExperimentalHintHasBitsForRepeatedFields ()) {
448
+ ABSL_CHECK_MESSAGE_SIZE (MockGeneratedWithHasBits, 8 + 16 * 15 + 8 * 6 + 8 );
449
+ } else {
450
+ ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 16 * 15 + 8 * 6 + 8 );
451
+ }
408
452
#else // !PROTOBUF_FORCE_SPLIT
453
+ struct MockGeneratedWithHasBits : public MockMessageBase { // 16 bytes
454
+ int has_bits[1 ]; // 4 bytes
455
+ int cached_size; // 4 bytes + 4 bytes padding
456
+ void * split; // 8 bytes
457
+ PROTOBUF_TSAN_DECLARE_MEMBER; // 0-4 bytes
458
+ // + 0-4 bytes padding
459
+ };
409
460
struct MockGenerated : public MockMessageBase { // 16 bytes
410
461
int cached_size; // 4 bytes + 4 bytes padding
411
462
void * split; // 8 bytes
@@ -414,7 +465,12 @@ TEST(GeneratedMessageTest, PackedTypesSize) {
414
465
};
415
466
ABSL_CHECK_MESSAGE_SIZE (MockGenerated, 32 );
416
467
#endif // PROTOBUF_FORCE_SPLIT
417
- EXPECT_EQ (sizeof (proto2_unittest::TestPackedTypes), sizeof (MockGenerated));
468
+ if constexpr (internal::EnableExperimentalHintHasBitsForRepeatedFields ()) {
469
+ EXPECT_EQ (sizeof (proto2_unittest::TestPackedTypes),
470
+ sizeof (MockGeneratedWithHasBits));
471
+ } else {
472
+ EXPECT_EQ (sizeof (proto2_unittest::TestPackedTypes), sizeof (MockGenerated));
473
+ }
418
474
}
419
475
420
476
} // namespace cpp_unittest
0 commit comments