Skip to content

Commit

Permalink
Replace ASSUME(false) with Unreachable() for clearer intent.
Browse files Browse the repository at this point in the history
They have the same optimization effect.

PiperOrigin-RevId: 583455660
  • Loading branch information
protobuf-github-bot authored and Copybara-Service committed Nov 17, 2023
1 parent b41f04d commit 80056df
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/google/protobuf/extension_set.h
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ class PROTOBUF_EXPORT ExtensionSet {
// someone
// adds a new wire type.
}
PROTOBUF_ASSUME(false); // switch handles all possible enum values
Unreachable(); // switch handles all possible enum values
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/generated_message_tctable_decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ constexpr MapTypeCard MakeMapTypeCard(WireFormatLite::FieldType type) {

case WireFormatLite::TYPE_GROUP:
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/google/protobuf/generated_message_tctable_gen.cc
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ uint16_t MakeTypeCardForField(
}
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

Expand Down
23 changes: 12 additions & 11 deletions src/google/protobuf/generated_message_tctable_lite.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "google/protobuf/map.h"
#include "google/protobuf/message_lite.h"
#include "google/protobuf/parse_context.h"
#include "google/protobuf/port.h"
#include "google/protobuf/repeated_field.h"
#include "google/protobuf/repeated_ptr_field.h"
#include "google/protobuf/varint_shuffle.h"
Expand Down Expand Up @@ -2013,14 +2014,14 @@ PROTOBUF_NOINLINE const char* TcParser::MpRepeatedVarint(
is_split, uint32_t, (is_split ? 0 : field_layout::kTvRange)>(
PROTOBUF_TC_PARAM_PASS);
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
case field_layout::kRep8Bits >> field_layout::kRepShift:
PROTOBUF_MUSTTAIL return MpRepeatedVarintT<is_split, bool, 0>(
PROTOBUF_TC_PARAM_PASS);

default:
PROTOBUF_ASSUME(false);
Unreachable();
return nullptr; // To silence -Werror=return-type in some toolchains
}
}
Expand Down Expand Up @@ -2110,14 +2111,14 @@ PROTOBUF_NOINLINE const char* TcParser::MpPackedVarint(PROTOBUF_TC_PARAM_DECL) {
is_split, uint32_t, (is_split ? 0 : field_layout::kTvRange)>(
PROTOBUF_TC_PARAM_PASS);
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
case field_layout::kRep8Bits >> field_layout::kRepShift:
PROTOBUF_MUSTTAIL return MpPackedVarintT<is_split, bool, 0>(
PROTOBUF_TC_PARAM_PASS);

default:
PROTOBUF_ASSUME(false);
Unreachable();
return nullptr; // To silence -Werror=return-type in some toolchains
}
}
Expand Down Expand Up @@ -2216,7 +2217,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpString(PROTOBUF_TC_PARAM_DECL) {
}

default:
PROTOBUF_ASSUME(false);
Unreachable();
}

if (PROTOBUF_PREDICT_FALSE(ptr == nullptr || !is_valid)) {
Expand Down Expand Up @@ -2503,7 +2504,7 @@ static void SerializeMapKey(const NodeBase* node, MapTypeCard type_card,
}
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
break;
case WireFormatLite::WIRETYPE_FIXED32:
Expand All @@ -2522,7 +2523,7 @@ static void SerializeMapKey(const NodeBase* node, MapTypeCard type_card,
&coded_output);
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

Expand Down Expand Up @@ -2567,7 +2568,7 @@ PROTOBUF_ALWAYS_INLINE inline void TcParser::InitializeMapNodeEntry(
aux[1].create_in_arena(map.arena(), reinterpret_cast<MessageLite*>(obj));
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

Expand Down Expand Up @@ -2661,7 +2662,7 @@ const char* TcParser::ParseOneMapEntry(
memcpy(obj, &tmp, sizeof(tmp));
continue;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
case WFL::WIRETYPE_FIXED32:
ptr = ReadFixed<uint32_t>(obj, ptr);
Expand Down Expand Up @@ -2697,7 +2698,7 @@ const char* TcParser::ParseOneMapEntry(
continue;
}
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}
return ptr;
Expand Down Expand Up @@ -2772,7 +2773,7 @@ PROTOBUF_NOINLINE const char* TcParser::MpMap(PROTOBUF_TC_PARAM_DECL) {
static_cast<KeyMapBase<std::string>::KeyNode*>(node));
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/google/protobuf/map_field.cc
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ VariantKey RealKeyToVariantKey<MapKey>::operator()(const MapKey& value) const {
case FieldDescriptor::CPPTYPE_BOOL:
return VariantKey(static_cast<uint64_t>(value.GetBoolValue()));
default:
ABSL_ASSUME(false);
Unreachable();
return VariantKey(uint64_t{});
}
}
Expand Down Expand Up @@ -246,7 +246,7 @@ void MapFieldBase::SyncRepeatedFieldWithMapNoLock() {
reflection->SetBool(new_entry, key_des, map_key.GetBoolValue());
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}

const MapValueRef& map_val = it.GetValueRef();
Expand Down Expand Up @@ -342,7 +342,7 @@ void MapFieldBase::SyncMapWithRepeatedFieldNoLock() {
map_key.SetBoolValue(reflection->GetBool(elem, key_des));
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}

MapValueRef map_val;
Expand Down

0 comments on commit 80056df

Please sign in to comment.