Skip to content

Commit 0778473

Browse files
Add tests for older gcc versions we still support (#20463)
PiperOrigin-RevId: 723691910 Co-authored-by: Mike Kruskal <mkruskal@google.com>
1 parent 503abcc commit 0778473

File tree

7 files changed

+59
-43
lines changed

7 files changed

+59
-43
lines changed

.github/workflows/test_cpp.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ jobs:
7474
strategy:
7575
fail-fast: false # Don't cancel all jobs if one fails.
7676
matrix:
77-
version: ['9.5', '13.1']
77+
version: ['7.5', '9.1', '9.5', '13.1']
7878
name: Linux GCC ${{ matrix.version }}
7979
runs-on: ubuntu-latest
8080
steps:
@@ -85,7 +85,7 @@ jobs:
8585
- name: Run tests
8686
uses: protocolbuffers/protobuf-ci/bazel-docker@v4
8787
with:
88-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-${{ matrix.version }}-d9624f2aa83cba3eaf906f751d75b36aacb9aa82
88+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-${{ matrix.version }}-e78301df86b3e4c46ec9ac4d98be00e19305d8f3
8989
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
9090
bazel-cache: cpp_linux/gcc-${{ matrix.version }}
9191
bazel: test //pkg/... //src/... //third_party/utf8_range/... //conformance:conformance_framework_tests
@@ -352,7 +352,7 @@ jobs:
352352
if: ${{ !matrix.continuous-only || inputs.continuous-run }}
353353
uses: protocolbuffers/protobuf-ci/docker@v4
354354
with:
355-
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-12.2-d9624f2aa83cba3eaf906f751d75b36aacb9aa82
355+
image: us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-12.2-e78301df86b3e4c46ec9ac4d98be00e19305d8f3
356356
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
357357
entrypoint: bash
358358
command: >-

.github/workflows/test_upb.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ jobs:
6969
- name: Run tests
7070
uses: protocolbuffers/protobuf-ci/bazel-docker@v4
7171
with:
72-
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-12.2-d9624f2aa83cba3eaf906f751d75b36aacb9aa82"
72+
image: "us-docker.pkg.dev/protobuf-build/containers/test/linux/gcc:7.1.2-12.2-e78301df86b3e4c46ec9ac4d98be00e19305d8f3"
7373
credentials: ${{ secrets.GAR_SERVICE_ACCOUNT }}
7474
bazel-cache: "upb-bazel-gcc"
7575
bazel: >-

src/google/protobuf/generated_message_tctable_lite.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2717,11 +2717,11 @@ const char* TcParser::ParseOneMapEntry(
27172717
void* obj;
27182718
if (inner_tag == key_tag) {
27192719
type_card = map_info.key_type_card;
2720-
type_kind = map.type_info().key_type;
2720+
type_kind = map.type_info().key_type_kind();
27212721
obj = node->GetVoidKey();
27222722
} else {
27232723
type_card = map_info.value_type_card;
2724-
type_kind = map.type_info().value_type;
2724+
type_kind = map.type_info().value_type_kind();
27252725
obj = map.GetVoidValue(node);
27262726
}
27272727

@@ -2870,7 +2870,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) {
28702870
WriteMapEntryAsUnknown(msg, table, map, saved_tag, node, map_info);
28712871
} else {
28722872
// Done parsing the node, insert it.
2873-
switch (map.type_info().key_type) {
2873+
switch (map.type_info().key_type_kind()) {
28742874
case UntypedMapBase::TypeKind::kBool:
28752875
static_cast<KeyMapBase<bool>&>(map).InsertOrReplaceNode(
28762876
static_cast<KeyMapBase<bool>::KeyNode*>(node));

src/google/protobuf/map.cc

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ void UntypedMapBase::ClearTableImpl(bool reset) {
133133
};
134134

135135
const auto dispatch_key = [&](auto value_handler) {
136-
if (type_info_.key_type < TypeKind::kString) {
136+
if (type_info_.key_type_kind() < TypeKind::kString) {
137137
loop(value_handler);
138-
} else if (type_info_.key_type == TypeKind::kString) {
138+
} else if (type_info_.key_type_kind() == TypeKind::kString) {
139139
loop([=](NodeBase* node) {
140140
static_cast<std::string*>(node->GetVoidKey())->~basic_string();
141141
value_handler(node);
@@ -145,13 +145,13 @@ void UntypedMapBase::ClearTableImpl(bool reset) {
145145
}
146146
};
147147

148-
if (type_info_.value_type < TypeKind::kString) {
148+
if (type_info_.value_type_kind() < TypeKind::kString) {
149149
dispatch_key([](NodeBase*) {});
150-
} else if (type_info_.value_type == TypeKind::kString) {
150+
} else if (type_info_.value_type_kind() == TypeKind::kString) {
151151
dispatch_key([&](NodeBase* node) {
152152
GetValue<std::string>(node)->~basic_string();
153153
});
154-
} else if (type_info_.value_type == TypeKind::kMessage) {
154+
} else if (type_info_.value_type_kind() == TypeKind::kMessage) {
155155
dispatch_key([&](NodeBase* node) {
156156
GetValue<MessageLite>(node)->DestroyInstance();
157157
});
@@ -251,7 +251,8 @@ UntypedMapBase::TypeInfo UntypedMapBase::GetTypeInfoDynamic(
251251
key_offsets.end, value_type, value_prototype_if_message, max_align);
252252
return TypeInfo{
253253
Narrow<uint16_t>(AlignTo(value_offsets.end, max_align, max_align)),
254-
Narrow<uint8_t>(value_offsets.start), key_type, value_type};
254+
Narrow<uint8_t>(value_offsets.start), static_cast<uint8_t>(key_type),
255+
static_cast<uint8_t>(value_type)};
255256
}
256257

257258
} // namespace internal

src/google/protobuf/map.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,13 @@ class PROTOBUF_EXPORT UntypedMapBase {
294294
uint16_t node_size;
295295
// Equivalent to `offsetof(Node, kv.second)` in the derived type.
296296
uint8_t value_offset;
297-
TypeKind key_type : 4;
298-
TypeKind value_type : 4;
297+
uint8_t key_type : 4;
298+
uint8_t value_type : 4;
299+
300+
TypeKind key_type_kind() const { return static_cast<TypeKind>(key_type); }
301+
TypeKind value_type_kind() const {
302+
return static_cast<TypeKind>(value_type);
303+
}
299304
};
300305
static_assert(sizeof(TypeInfo) == 4);
301306

@@ -474,7 +479,7 @@ class PROTOBUF_EXPORT UntypedMapBase {
474479

475480
template <typename F>
476481
auto UntypedMapBase::VisitKeyType(F f) const {
477-
switch (type_info_.key_type) {
482+
switch (type_info_.key_type_kind()) {
478483
case TypeKind::kBool:
479484
return f(std::enable_if<true, bool>{});
480485
case TypeKind::kU32:
@@ -494,7 +499,7 @@ auto UntypedMapBase::VisitKeyType(F f) const {
494499

495500
template <typename F>
496501
auto UntypedMapBase::VisitValueType(F f) const {
497-
switch (type_info_.value_type) {
502+
switch (type_info_.value_type_kind()) {
498503
case TypeKind::kBool:
499504
return f(std::enable_if<true, bool>{});
500505
case TypeKind::kU32:
@@ -1446,8 +1451,8 @@ class Map : private internal::KeyMapBase<internal::KeyForBase<Key>> {
14461451
return internal::UntypedMapBase::TypeInfo{
14471452
sizeof(Node),
14481453
PROTOBUF_FIELD_OFFSET(Node, kv.second),
1449-
internal::UntypedMapBase::StaticTypeKind<Key>(),
1450-
internal::UntypedMapBase::StaticTypeKind<T>(),
1454+
static_cast<uint8_t>(internal::UntypedMapBase::StaticTypeKind<Key>()),
1455+
static_cast<uint8_t>(internal::UntypedMapBase::StaticTypeKind<T>()),
14511456
};
14521457
}
14531458

src/google/protobuf/map_test.cc

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,32 @@ TEST(MapTest, SizeTypeIsSizeT) {
309309
(void)x;
310310
}
311311

312+
using KeyTypes = void (*)(bool, int32_t, uint32_t, int64_t, uint64_t,
313+
std::string);
314+
// Some arbitrary proto enum.
315+
using SomeEnum = proto2_unittest::TestAllTypes::NestedEnum;
316+
using ValueTypes = void (*)(bool, int32_t, uint32_t, int64_t, uint64_t, float,
317+
double, std::string, SomeEnum,
318+
proto2_unittest::TestEmptyMessage,
319+
proto2_unittest::TestAllTypes);
320+
321+
TEST(MapTest, StaticTypeKindWorks) {
322+
using UMB = UntypedMapBase;
323+
EXPECT_EQ(UMB::TypeKind::kBool, UMB::StaticTypeKind<bool>());
324+
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<int32_t>());
325+
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<uint32_t>());
326+
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<SomeEnum>());
327+
EXPECT_EQ(UMB::TypeKind::kU64, UMB::StaticTypeKind<int64_t>());
328+
EXPECT_EQ(UMB::TypeKind::kU64, UMB::StaticTypeKind<uint64_t>());
329+
EXPECT_EQ(UMB::TypeKind::kString, UMB::StaticTypeKind<std::string>());
330+
EXPECT_EQ(UMB::TypeKind::kMessage,
331+
UMB::StaticTypeKind<proto2_unittest::TestAllTypes>());
332+
}
333+
334+
#if !defined(__GNUC__) || defined(__clang__) || PROTOBUF_GNUC_MIN(9, 4)
335+
// Parameter pack expansion bug before GCC 8.2:
336+
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85305
337+
312338
template <typename F, typename... Key, typename... Value>
313339
void TestAllKeyValueTypes(void (*)(Key...), void (*)(Value...), F f) {
314340
(
@@ -319,15 +345,6 @@ void TestAllKeyValueTypes(void (*)(Key...), void (*)(Value...), F f) {
319345
...);
320346
}
321347

322-
using KeyTypes = void (*)(bool, int32_t, uint32_t, int64_t, uint64_t,
323-
std::string);
324-
// Some arbitrary proto enum.
325-
using SomeEnum = proto2_unittest::TestAllTypes::NestedEnum;
326-
using ValueTypes = void (*)(bool, int32_t, uint32_t, int64_t, uint64_t, float,
327-
double, std::string, SomeEnum,
328-
proto2_unittest::TestEmptyMessage,
329-
proto2_unittest::TestAllTypes);
330-
331348
TEST(MapTest, StaticTypeInfoMatchesDynamicOne) {
332349
TestAllKeyValueTypes(KeyTypes(), ValueTypes(), [](auto key, auto value) {
333350
using Key = decltype(key);
@@ -338,27 +355,15 @@ TEST(MapTest, StaticTypeInfoMatchesDynamicOne) {
338355
}
339356
const auto type_info = MapTestPeer::GetTypeInfo<Map<Key, Value>>();
340357
const auto dyn_type_info = internal::UntypedMapBase::GetTypeInfoDynamic(
341-
type_info.key_type, type_info.value_type, value_prototype);
358+
type_info.key_type_kind(), type_info.value_type_kind(),
359+
value_prototype);
342360
EXPECT_EQ(dyn_type_info.node_size, type_info.node_size);
343361
EXPECT_EQ(dyn_type_info.value_offset, type_info.value_offset);
344362
EXPECT_EQ(dyn_type_info.key_type, type_info.key_type);
345363
EXPECT_EQ(dyn_type_info.value_type, type_info.value_type);
346364
});
347365
}
348366

349-
TEST(MapTest, StaticTypeKindWorks) {
350-
using UMB = UntypedMapBase;
351-
EXPECT_EQ(UMB::TypeKind::kBool, UMB::StaticTypeKind<bool>());
352-
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<int32_t>());
353-
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<uint32_t>());
354-
EXPECT_EQ(UMB::TypeKind::kU32, UMB::StaticTypeKind<SomeEnum>());
355-
EXPECT_EQ(UMB::TypeKind::kU64, UMB::StaticTypeKind<int64_t>());
356-
EXPECT_EQ(UMB::TypeKind::kU64, UMB::StaticTypeKind<uint64_t>());
357-
EXPECT_EQ(UMB::TypeKind::kString, UMB::StaticTypeKind<std::string>());
358-
EXPECT_EQ(UMB::TypeKind::kMessage,
359-
UMB::StaticTypeKind<proto2_unittest::TestAllTypes>());
360-
}
361-
362367
template <typename LHS, typename RHS>
363368
void TestEqPtr(LHS* lhs, RHS* rhs) {
364369
// To silence some false positive compiler errors in gcc 9.5
@@ -428,6 +433,8 @@ TEST(MapTest, VisitAllNodesUsesTheRightTypesOnAllNodes) {
428433
});
429434
}
430435

436+
#endif
437+
431438
TEST(MapTest, IteratorNodeFieldIsNullPtrAtEnd) {
432439
Map<int, int> map;
433440
EXPECT_EQ(internal::UntypedMapIterator::FromTyped(map.cbegin()).node_,

src/google/protobuf/map_test.inc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2389,7 +2389,10 @@ class MyMapEntry
23892389
constexpr MyMapEntry()
23902390
: MyMapEntry::MapEntry(static_cast<ClassData*>(nullptr)) {}
23912391
MyMapEntry(Arena* arena) : MyMapEntry::MapEntry(arena, nullptr) {}
2392-
const ClassData* GetClassData() const { ABSL_CHECK(false); }
2392+
const ClassData* GetClassData() const {
2393+
ABSL_CHECK(false);
2394+
return nullptr;
2395+
}
23932396
static bool ValidateKey(void*) { return true; }
23942397
static bool ValidateValue(void*) { return true; }
23952398
};

0 commit comments

Comments
 (0)