Replace ASSUME(false) with Unreachable() for clearer intent.

They have the same optimization effect.

PiperOrigin-RevId: 583455660
pull/14796/head
Protobuf Team Bot 1 year ago committed by Copybara-Service
parent b41f04d42a
commit 80056dfb30
  1. 2
      src/google/protobuf/extension_set.h
  2. 2
      src/google/protobuf/generated_message_tctable_decl.h
  3. 2
      src/google/protobuf/generated_message_tctable_gen.cc
  4. 23
      src/google/protobuf/generated_message_tctable_lite.cc
  5. 6
      src/google/protobuf/map_field.cc

@ -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;
}

@ -238,7 +238,7 @@ constexpr MapTypeCard MakeMapTypeCard(WireFormatLite::FieldType type) {
case WireFormatLite::TYPE_GROUP:
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

@ -713,7 +713,7 @@ uint16_t MakeTypeCardForField(
}
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}

@ -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"
@ -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
}
}
@ -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
}
}
@ -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)) {
@ -2503,7 +2504,7 @@ static void SerializeMapKey(const NodeBase* node, MapTypeCard type_card,
}
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
break;
case WireFormatLite::WIRETYPE_FIXED32:
@ -2522,7 +2523,7 @@ static void SerializeMapKey(const NodeBase* node, MapTypeCard type_card,
&coded_output);
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}
@ -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();
}
}
@ -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);
@ -2697,7 +2698,7 @@ const char* TcParser::ParseOneMapEntry(
continue;
}
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
}
return ptr;
@ -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();
}
}
}

@ -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{});
}
}
@ -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();
@ -342,7 +342,7 @@ void MapFieldBase::SyncMapWithRepeatedFieldNoLock() {
map_key.SetBoolValue(reflection->GetBool(elem, key_des));
break;
default:
PROTOBUF_ASSUME(false);
Unreachable();
}
MapValueRef map_val;

Loading…
Cancel
Save