Skip to content

Commit cdbde21

Browse files
tonyliaosscopybara-github
authored andcommitted
Add ifdef guards to prevent tests from consistently failing ASAN and UBSAN.
In the GenCodeMapMissingKeyDeathTest we deliberately trigger an invalid map access to try to understand its behaviour. This test case was added in 27ee74e. This undefined behaviour was gated by an ABSL_DCHECK and will consistently crash in debug mode. In optimized mode, this is invoking undefined behaviour and having a test case for it is meaningless. (We have seen it crash or run without errors depending on sanitizer and other compiler flags). I've removed this test case altogether in NDEBUG mode. PiperOrigin-RevId: 734293191
1 parent 1c0a923 commit cdbde21

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/google/protobuf/no_field_presence_map_test.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,17 +119,23 @@ TEST(NoFieldPresenceTest, GenCodeMapMissingKeyDeathTest) {
119119
EXPECT_DEATH(message.map_int32_bytes().at(9), "key not found");
120120
}
121121

122+
#ifndef NDEBUG
123+
// This test case tests a DCHECK assertion. If this scenario happens in
124+
// optimized builds, it's technically UB, so having a test case for it in opt
125+
// builds is meaningless.
122126
TEST(NoFieldPresenceTest, GenCodeMapReflectionMissingKeyDeathTest) {
123127
TestAllMapTypes message;
124128
const Reflection* r = message.GetReflection();
125129
const Descriptor* desc = message.GetDescriptor();
126130

127131
const FieldDescriptor* field_map_int32_bytes =
128132
desc->FindFieldByName("map_int32_bytes");
129-
// Trying to get an unset map entry would crash in debug mode.
130-
EXPECT_DEBUG_DEATH(r->GetRepeatedMessage(message, field_map_int32_bytes, 0),
131-
"index < current_size_");
133+
134+
// Trying to get an unset map entry would crash with a DCHECK in debug mode.
135+
EXPECT_DEATH(r->GetRepeatedMessage(message, field_map_int32_bytes, 0),
136+
"index < current_size_");
132137
}
138+
#endif
133139

134140
TEST(NoFieldPresenceTest, ReflectionEmptyMapTest) {
135141
TestAllMapTypes message;

0 commit comments

Comments
 (0)