From 7e861cc593ae3ca3ef1190be966011ecd7ae4542 Mon Sep 17 00:00:00 2001 From: Mike Kruskal Date: Wed, 7 Dec 2022 15:45:59 -0800 Subject: [PATCH] Internal changes PiperOrigin-RevId: 493729702 --- .../compiler/cpp/bootstrap_unittest.cc | 9 ++- src/google/protobuf/compiler/cpp/enum_field.h | 3 +- src/google/protobuf/compiler/cpp/field.cc | 12 +-- src/google/protobuf/compiler/cpp/field.h | 3 +- src/google/protobuf/compiler/cpp/file.cc | 6 +- src/google/protobuf/compiler/cpp/file.h | 3 +- src/google/protobuf/compiler/cpp/generator.cc | 4 +- src/google/protobuf/compiler/cpp/helpers.cc | 34 ++++---- src/google/protobuf/compiler/cpp/helpers.h | 5 +- src/google/protobuf/compiler/cpp/map_field.cc | 3 +- src/google/protobuf/compiler/cpp/message.cc | 69 +++++++++-------- .../protobuf/compiler/cpp/message_field.cc | 35 +++++---- .../compiler/cpp/message_size_unittest.cc | 52 +++++++------ .../protobuf/compiler/cpp/metadata_test.cc | 9 ++- .../compiler/cpp/padding_optimizer.cc | 6 +- .../compiler/cpp/parse_function_generator.cc | 33 ++++---- .../protobuf/compiler/cpp/plugin_unittest.cc | 77 ++++++++++--------- .../protobuf/compiler/cpp/primitive_field.cc | 3 +- .../protobuf/compiler/cpp/primitive_field.h | 3 +- .../protobuf/compiler/cpp/string_field.cc | 9 ++- .../protobuf/compiler/cpp/string_field.h | 3 +- src/google/protobuf/compiler/cpp/unittest.inc | 1 - 22 files changed, 202 insertions(+), 180 deletions(-) diff --git a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc index 036a434ce1..3a876666f6 100644 --- a/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc +++ b/src/google/protobuf/compiler/cpp/bootstrap_unittest.cc @@ -53,6 +53,7 @@ #include "google/protobuf/testing/googletest.h" #include #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/substitute.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/io/zero_copy_stream_impl.h" @@ -96,15 +97,15 @@ class MockGeneratorContext : public GeneratorContext { std::string expected_contents = *it->second; std::string actual_contents; - GOOGLE_CHECK_OK( + GOOGLE_ABSL_CHECK_OK( File::GetContents(TestUtil::TestSourceDir() + "/" + physical_filename, &actual_contents, true)) << physical_filename; #ifdef WRITE_FILES // Define to debug mismatched files. - GOOGLE_CHECK_OK(File::SetContents("/tmp/expected.cc", expected_contents, - true)); - GOOGLE_CHECK_OK( + GOOGLE_ABSL_CHECK_OK(File::SetContents("/tmp/expected.cc", expected_contents, + true)); + GOOGLE_ABSL_CHECK_OK( File::SetContents("/tmp/actual.cc", actual_contents, true)); #endif diff --git a/src/google/protobuf/compiler/cpp/enum_field.h b/src/google/protobuf/compiler/cpp/enum_field.h index 496f146d70..0dc62921ae 100644 --- a/src/google/protobuf/compiler/cpp/enum_field.h +++ b/src/google/protobuf/compiler/cpp/enum_field.h @@ -37,6 +37,7 @@ #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/field.h" namespace google { @@ -102,7 +103,7 @@ class RepeatedEnumFieldGenerator : public FieldGenerator { void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override; void GenerateCopyConstructorCode(io::Printer* /*printer*/) const override { - GOOGLE_CHECK(!ShouldSplit(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!ShouldSplit(descriptor_, options_)); } void GenerateDestructorCode(io::Printer* printer) const override; void GenerateSerializeWithCachedSizesToArray( diff --git a/src/google/protobuf/compiler/cpp/field.cc b/src/google/protobuf/compiler/cpp/field.cc index a6dff9ae02..04d0183b0f 100644 --- a/src/google/protobuf/compiler/cpp/field.cc +++ b/src/google/protobuf/compiler/cpp/field.cc @@ -316,7 +316,7 @@ void SetCommonOneofFieldVariables( void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { if (!internal::cpp::HasHasbit(descriptor_) || has_bit_index < 0) { - GOOGLE_CHECK_EQ(has_bit_index, -1); + GOOGLE_ABSL_CHECK_EQ(has_bit_index, -1); return; } int32_t index = has_bit_index / 32; @@ -334,11 +334,11 @@ void FieldGenerator::SetHasBitIndex(int32_t has_bit_index) { void FieldGenerator::SetInlinedStringIndex(int32_t inlined_string_index) { if (!IsStringInlined(descriptor_, options_)) { - GOOGLE_CHECK_EQ(inlined_string_index, -1); + GOOGLE_ABSL_CHECK_EQ(inlined_string_index, -1); return; } // The first bit is the tracking bit for on demand registering ArenaDtor. - GOOGLE_CHECK_GT(inlined_string_index, 0) + GOOGLE_ABSL_CHECK_GT(inlined_string_index, 0) << "_inlined_string_donated_'s bit 0 is reserved for arena dtor tracking"; variables_["inlined_string_donated"] = absl::StrCat( "(", variables_["inlined_string_donated_array"], "[", @@ -384,8 +384,8 @@ void FieldGenerator::GenerateCopyConstructorCode(io::Printer* printer) const { } void FieldGenerator::GenerateIfHasField(io::Printer* printer) const { - GOOGLE_CHECK(internal::cpp::HasHasbit(descriptor_)); - GOOGLE_CHECK(variables_.find("has_hasbit") != variables_.end()); + GOOGLE_ABSL_CHECK(internal::cpp::HasHasbit(descriptor_)); + GOOGLE_ABSL_CHECK(variables_.find("has_hasbit") != variables_.end()); Formatter format(printer, variables_); format("if (($has_hasbit$) != 0) {\n"); @@ -465,7 +465,7 @@ FieldGeneratorMap::~FieldGeneratorMap() {} const FieldGenerator& FieldGeneratorMap::get( const FieldDescriptor* field) const { - GOOGLE_CHECK_EQ(field->containing_type(), descriptor_); + GOOGLE_ABSL_CHECK_EQ(field->containing_type(), descriptor_); return *field_generators_[field->index()]; } diff --git a/src/google/protobuf/compiler/cpp/field.h b/src/google/protobuf/compiler/cpp/field.h index a196918d12..2b97272273 100644 --- a/src/google/protobuf/compiler/cpp/field.h +++ b/src/google/protobuf/compiler/cpp/field.h @@ -41,6 +41,7 @@ #include "google/protobuf/descriptor.h" #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/compiler/cpp/options.h" @@ -169,7 +170,7 @@ class FieldGenerator { // shared-for-the-whole-message-class method registered with // OwnDestructor(). virtual void GenerateArenaDestructorCode(io::Printer* printer) const { - GOOGLE_CHECK(NeedsArenaDestructor() == ArenaDtorNeeds::kNone) + GOOGLE_ABSL_CHECK(NeedsArenaDestructor() == ArenaDtorNeeds::kNone) << descriptor_->cpp_type_name(); } diff --git a/src/google/protobuf/compiler/cpp/file.cc b/src/google/protobuf/compiler/cpp/file.cc index 9d40484be1..d566f78f56 100644 --- a/src/google/protobuf/compiler/cpp/file.cc +++ b/src/google/protobuf/compiler/cpp/file.cc @@ -373,7 +373,7 @@ void FileGenerator::GeneratePBHeader(io::Printer* p, void FileGenerator::DoIncludeFile(absl::string_view google3_name, bool do_export, io::Printer* p) { constexpr absl::string_view prefix = "third_party/protobuf/"; - GOOGLE_CHECK(absl::StartsWith(google3_name, prefix)) << google3_name; + GOOGLE_ABSL_CHECK(absl::StartsWith(google3_name, prefix)) << google3_name; auto v = p->WithVars( {{"export_suffix", do_export ? "// IWYU pragma: export" : ""}}); @@ -1240,11 +1240,11 @@ void FileGenerator::GenerateLibraryIncludes(io::Printer* p) { IncludeFile("third_party/protobuf/implicit_weak_message.h", p); } if (HasWeakFields(file_, options_)) { - GOOGLE_CHECK(!options_.opensource_runtime); + GOOGLE_ABSL_CHECK(!options_.opensource_runtime); IncludeFile("third_party/protobuf/weak_field_map.h", p); } if (HasLazyFields(file_, options_, &scc_analyzer_)) { - GOOGLE_CHECK(!options_.opensource_runtime); + GOOGLE_ABSL_CHECK(!options_.opensource_runtime); IncludeFile("third_party/protobuf/lazy_field.h", p); } if (ShouldVerify(file_, options_, &scc_analyzer_)) { diff --git a/src/google/protobuf/compiler/cpp/file.h b/src/google/protobuf/compiler/cpp/file.h index 5f8ffcfc3e..3a746c09aa 100644 --- a/src/google/protobuf/compiler/cpp/file.h +++ b/src/google/protobuf/compiler/cpp/file.h @@ -45,6 +45,7 @@ #include "google/protobuf/compiler/scc.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/enum.h" #include "google/protobuf/compiler/cpp/extension.h" #include "google/protobuf/compiler/cpp/field.h" @@ -179,7 +180,7 @@ class FileGenerator { bool IsDepWeak(const FileDescriptor* dep) const { if (weak_deps_.count(dep) != 0) { - GOOGLE_CHECK(!options_.opensource_runtime); + GOOGLE_ABSL_CHECK(!options_.opensource_runtime); return true; } return false; diff --git a/src/google/protobuf/compiler/cpp/generator.cc b/src/google/protobuf/compiler/cpp/generator.cc index 14082f52af..44a0913f6a 100644 --- a/src/google/protobuf/compiler/cpp/generator.cc +++ b/src/google/protobuf/compiler/cpp/generator.cc @@ -75,7 +75,7 @@ absl::flat_hash_map CommonVars( // Warning: there is some clever naming/splitting here to avoid extract // script rewrites. The names of these variables must not be things that // the extract script will rewrite. That's why we use "CHK" (for example) - // instead of "GOOGLE_CHECK". + // instead of "GOOGLE_ABSL_CHECK". // // These values are things the extract script would rewrite if we did not // split them. It might not strictly matter since we don't generate @@ -297,7 +297,7 @@ bool CppGenerator::Generate(const FileDescriptor* file, // pb.cc file. If we have more files than messages, then some files will // be generated as empty placeholders. if (file_options.num_cc_files > 0) { - GOOGLE_CHECK_LE(num_cc_files, file_options.num_cc_files) + GOOGLE_ABSL_CHECK_LE(num_cc_files, file_options.num_cc_files) << "There must be at least as many numbered .cc files as messages " "and extensions."; num_cc_files = file_options.num_cc_files; diff --git a/src/google/protobuf/compiler/cpp/helpers.cc b/src/google/protobuf/compiler/cpp/helpers.cc index 242022c467..21118bbf06 100644 --- a/src/google/protobuf/compiler/cpp/helpers.cc +++ b/src/google/protobuf/compiler/cpp/helpers.cc @@ -45,12 +45,13 @@ #include #include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/scc.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/dynamic_message.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" @@ -443,7 +444,7 @@ std::string ExtensionName(const FieldDescriptor* d) { std::string QualifiedExtensionName(const FieldDescriptor* d, const Options& options) { - GOOGLE_DCHECK(d->is_extension()); + GOOGLE_ABSL_DCHECK(d->is_extension()); return QualifiedFileLevelSymbol(d->file(), ExtensionName(d), options); } @@ -561,19 +562,19 @@ std::string FieldMemberName(const FieldDescriptor* field, bool split) { return absl::StrCat(prefix, split_prefix, FieldName(field), "_"); } // Oneof fields are never split. - GOOGLE_CHECK(!split); + GOOGLE_ABSL_CHECK(!split); return absl::StrCat(prefix, field->containing_oneof()->name(), "_.", FieldName(field), "_"); } std::string OneofCaseConstantName(const FieldDescriptor* field) { - GOOGLE_DCHECK(field->containing_oneof()); + GOOGLE_ABSL_DCHECK(field->containing_oneof()); std::string field_name = UnderscoresToCamelCase(field->name(), true); return "k" + field_name; } std::string QualifiedOneofCaseConstantName(const FieldDescriptor* field) { - GOOGLE_DCHECK(field->containing_oneof()); + GOOGLE_ABSL_DCHECK(field->containing_oneof()); const std::string qualification = QualifiedClassName(field->containing_type()); return absl::StrCat(qualification, "::", OneofCaseConstantName(field)); @@ -607,7 +608,7 @@ int EstimateAlignmentSize(const FieldDescriptor* field) { case FieldDescriptor::CPPTYPE_MESSAGE: return 8; } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return -1; // Make compiler happy. } @@ -669,7 +670,7 @@ const char* PrimitiveTypeName(FieldDescriptor::CppType type) { // CppTypes are added. } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return nullptr; } @@ -701,7 +702,7 @@ std::string PrimitiveTypeName(const Options& options, // CppTypes are added. } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return ""; } @@ -749,7 +750,7 @@ const char* DeclaredTypeMethodName(FieldDescriptor::Type type) { // No default because we want the compiler to complain if any new // types are added. } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return ""; } @@ -840,7 +841,7 @@ std::string DefaultValue(const Options& options, const FieldDescriptor* field) { // Can't actually get here; make compiler happy. (We could add a default // case above but then we wouldn't get the nice compiler warning when a // new type is added.) - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return ""; } @@ -1119,13 +1120,13 @@ bool IsStringOrMessage(const FieldDescriptor* field) { return true; } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return false; } FieldOptions::CType EffectiveStringCType(const FieldDescriptor* field, const Options& options) { - GOOGLE_DCHECK(field->cpp_type() == FieldDescriptor::CPPTYPE_STRING); + GOOGLE_ABSL_DCHECK(field->cpp_type() == FieldDescriptor::CPPTYPE_STRING); if (options.opensource_runtime) { // Open-source protobuf release only supports STRING ctype. return FieldOptions::STRING; @@ -1636,16 +1637,17 @@ FileOptions_OptimizeMode GetOptimizeFor(const FileDescriptor* file, case EnforceOptimizeMode::kNoEnforcement: if (file->options().optimize_for() == FileOptions::CODE_SIZE) { if (HasBootstrapProblem(file, options, has_opt_codesize_extension)) { - GOOGLE_LOG(WARNING) << "Proto states optimize_for = CODE_SIZE, but we " - "cannot honor that because it contains custom option " - "extensions defined in the same proto."; + GOOGLE_ABSL_LOG(WARNING) + << "Proto states optimize_for = CODE_SIZE, but we " + "cannot honor that because it contains custom option " + "extensions defined in the same proto."; return FileOptions::SPEED; } } return file->options().optimize_for(); } - GOOGLE_LOG(FATAL) << "Unknown optimization enforcement requested."; + GOOGLE_ABSL_LOG(FATAL) << "Unknown optimization enforcement requested."; // The phony return below serves to silence a warning from GCC 8. return FileOptions::SPEED; } diff --git a/src/google/protobuf/compiler/cpp/helpers.h b/src/google/protobuf/compiler/cpp/helpers.h index 7ac55af880..c2fb1cdbf6 100644 --- a/src/google/protobuf/compiler/cpp/helpers.h +++ b/src/google/protobuf/compiler/cpp/helpers.h @@ -44,6 +44,7 @@ #include "google/protobuf/compiler/scc.h" #include "google/protobuf/compiler/code_generator.h" #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/match.h" #include "absl/strings/str_split.h" #include "absl/strings/string_view.h" @@ -341,7 +342,7 @@ inline bool UseUnknownFieldSet(const FileDescriptor* file, inline bool IsWeak(const FieldDescriptor* field, const Options& options) { if (field->options().weak()) { - GOOGLE_CHECK(!options.opensource_runtime); + GOOGLE_ABSL_CHECK(!options.opensource_runtime); return true; } return false; @@ -991,7 +992,7 @@ struct OneOfRangeImpl { value_type operator*() { return descriptor->oneof_decl(idx); } friend bool operator==(const Iterator& a, const Iterator& b) { - GOOGLE_DCHECK(a.descriptor == b.descriptor); + GOOGLE_ABSL_DCHECK(a.descriptor == b.descriptor); return a.idx == b.idx; } friend bool operator!=(const Iterator& a, const Iterator& b) { diff --git a/src/google/protobuf/compiler/cpp/map_field.cc b/src/google/protobuf/compiler/cpp/map_field.cc index dd9f0a6c47..21b86a5d23 100644 --- a/src/google/protobuf/compiler/cpp/map_field.cc +++ b/src/google/protobuf/compiler/cpp/map_field.cc @@ -33,6 +33,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/ascii.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -300,7 +301,7 @@ void MapFieldGenerator::GenerateAggregateInitializer( } void MapFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (ShouldSplit(descriptor_, options_)) { diff --git a/src/google/protobuf/compiler/cpp/message.cc b/src/google/protobuf/compiler/cpp/message.cc index 93ceb44f3a..cd0d7ee007 100644 --- a/src/google/protobuf/compiler/cpp/message.cc +++ b/src/google/protobuf/compiler/cpp/message.cc @@ -51,6 +51,8 @@ #include "google/protobuf/map_entry_lite.h" #include "absl/container/flat_hash_map.h" #include "absl/container/flat_hash_set.h" +#include "google/protobuf/stubs/logging.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/ascii.h" #include "absl/strings/escaping.h" #include "absl/strings/str_cat.h" @@ -102,7 +104,7 @@ std::string ConditionalToCheckBitmasks( parts.push_back( absl::StrCat("((", has_bits_var, "[", i, "] & ", m, ") ^ ", m, ")")); } - GOOGLE_CHECK(!parts.empty()); + GOOGLE_ABSL_CHECK(!parts.empty()); // If we have multiple parts, each expected to be 0, then bitwise-or them. std::string result = parts.size() == 1 @@ -206,7 +208,7 @@ RunMap FindRuns(const std::vector& fields, // !HasHasbit(field). bool EmitFieldNonDefaultCondition(io::Printer* p, const std::string& prefix, const FieldDescriptor* field) { - GOOGLE_CHECK(!HasHasbit(field)); + GOOGLE_ABSL_CHECK(!HasHasbit(field)); Formatter format(p); auto v = p->WithVars({{ {"prefix", prefix}, @@ -271,7 +273,7 @@ bool HasInternalHasMethod(const FieldDescriptor* field) { void CollectMapInfo( const Options& options, const Descriptor* descriptor, absl::flat_hash_map* variables) { - GOOGLE_CHECK(IsMapEntryMessage(descriptor)); + GOOGLE_ABSL_CHECK(IsMapEntryMessage(descriptor)); absl::flat_hash_map& vars = *variables; const FieldDescriptor* key = descriptor->map_key(); const FieldDescriptor* val = descriptor->map_value(); @@ -357,16 +359,16 @@ std::vector> CollectFields( // masked to tell if any thing in "fields" is present. uint32_t GenChunkMask(const std::vector& fields, const std::vector& has_bit_indices) { - GOOGLE_CHECK(!fields.empty()); + GOOGLE_ABSL_CHECK(!fields.empty()); int first_index_offset = has_bit_indices[fields.front()->index()] / 32; uint32_t chunk_mask = 0; for (auto field : fields) { // "index" defines where in the _has_bits_ the field appears. int index = has_bit_indices[field->index()]; - GOOGLE_CHECK_EQ(first_index_offset, index / 32); + GOOGLE_ABSL_CHECK_EQ(first_index_offset, index / 32); chunk_mask |= static_cast(1) << (index % 32); } - GOOGLE_CHECK_NE(0, chunk_mask); + GOOGLE_ABSL_CHECK_NE(0, chunk_mask); return chunk_mask; } @@ -463,7 +465,7 @@ void ColdChunkSkipper::OnStartChunk(int chunk, int cached_has_word_index, for (auto field : chunks_[chunk]) { int hasbit_index = has_bit_indices_[field->index()]; // Fields on a chunk must be in the same word. - GOOGLE_CHECK_EQ(this_word, hasbit_index / 32); + GOOGLE_ABSL_CHECK_EQ(this_word, hasbit_index / 32); mask |= 1 << (hasbit_index % 32); } } @@ -1059,7 +1061,7 @@ void MessageGenerator::GenerateSingularFieldHasBits( } if (HasHasbit(field)) { int has_bit_index = HasBitIndex(field); - GOOGLE_CHECK_NE(has_bit_index, kNoHasbit); + GOOGLE_ABSL_CHECK_NE(has_bit_index, kNoHasbit); auto v = p->WithVars(HasbitVars(has_bit_index)); format( @@ -1298,7 +1300,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { " }\n", descriptor_->field(0)->full_name()); } else { - GOOGLE_CHECK(utf8_check == Utf8CheckMode::kVerify); + GOOGLE_ABSL_CHECK(utf8_check == Utf8CheckMode::kVerify); format( " static bool ValidateKey(std::string* s) {\n" "#ifndef NDEBUG\n" @@ -1327,7 +1329,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { " }\n", descriptor_->field(1)->full_name()); } else { - GOOGLE_CHECK(utf8_check == Utf8CheckMode::kVerify); + GOOGLE_ABSL_CHECK(utf8_check == Utf8CheckMode::kVerify); format( " static bool ValidateValue(std::string* s) {\n" "#ifndef NDEBUG\n" @@ -1960,7 +1962,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) { format.Outdent(); format("};"); - GOOGLE_DCHECK(!need_to_emit_cached_size); + GOOGLE_ABSL_DCHECK(!need_to_emit_cached_size); } // NOLINT(readability/fn_size) void MessageGenerator::GenerateInlineMethods(io::Printer* p) { @@ -1997,8 +1999,8 @@ void MessageGenerator::GenerateSchema(io::Printer* p, int offset, if (inlined_string_indices_.empty()) { inlined_string_indices_offset = -1; } else { - GOOGLE_DCHECK_NE(has_offset, -1); - GOOGLE_DCHECK(!IsMapEntryMessage(descriptor_)); + GOOGLE_ABSL_DCHECK_NE(has_offset, -1); + GOOGLE_ABSL_DCHECK(!IsMapEntryMessage(descriptor_)); inlined_string_indices_offset = has_offset + has_bit_indices_.size(); } format("{ $1$, $2$, $3$, sizeof($classtype$)},\n", offset, has_offset, @@ -2082,7 +2084,7 @@ void MessageGenerator::GenerateClassMethods(io::Printer* p) { } if (HasHasbit(field)) { int has_bit_index = HasBitIndex(field); - GOOGLE_CHECK_NE(has_bit_index, kNoHasbit) << field->full_name(); + GOOGLE_ABSL_CHECK_NE(has_bit_index, kNoHasbit) << field->full_name(); format( "static void set_has_$1$(HasBits* has_bits) {\n" " (*has_bits)[$2$] |= $3$u;\n" @@ -2302,7 +2304,7 @@ std::pair MessageGenerator::GenerateOffsets(io::Printer* p) { format("PROTOBUF_FIELD_OFFSET($classtype$, _impl_.$1$_),\n", oneof->name()); count++; } - GOOGLE_CHECK_EQ(count, descriptor_->real_oneof_decl_count()); + GOOGLE_ABSL_CHECK_EQ(count, descriptor_->real_oneof_decl_count()); if (IsMapEntryMessage(descriptor_)) { entries += 2; @@ -2374,7 +2376,7 @@ void MessageGenerator::GenerateSharedConstructorCode(io::Printer* p) { // Initialize member variables with arena constructor. for (auto field : optimized_order_) { - GOOGLE_DCHECK(!IsFieldStripped(field, options_)); + GOOGLE_ABSL_DCHECK(!IsFieldStripped(field, options_)); if (ShouldSplit(field, options_)) { continue; } @@ -2554,7 +2556,7 @@ ArenaDtorNeeds MessageGenerator::NeedsArenaDestructor() const { } void MessageGenerator::GenerateArenaDestructorCode(io::Printer* p) { - GOOGLE_CHECK(NeedsArenaDestructor() > ArenaDtorNeeds::kNone); + GOOGLE_ABSL_CHECK(NeedsArenaDestructor() > ArenaDtorNeeds::kNone); Formatter format(p); @@ -3067,7 +3069,7 @@ void MessageGenerator::GenerateClear(io::Printer* p) { bool chunk_is_split = !chunk.empty() && ShouldSplit(chunk.front(), options_); // All chunks after the first split chunk should also be split. - GOOGLE_CHECK(!first_split_chunk_processed || chunk_is_split); + GOOGLE_ABSL_CHECK(!first_split_chunk_processed || chunk_is_split); if (chunk_is_split && !first_split_chunk_processed) { // Some fields are cleared without checking has_bit. So we add the // condition here to avoid writing to the default split instance. @@ -3078,7 +3080,7 @@ void MessageGenerator::GenerateClear(io::Printer* p) { for (const auto& field : chunk) { if (CanClearByZeroing(field)) { - GOOGLE_CHECK(!saw_non_zero_init); + GOOGLE_ABSL_CHECK(!saw_non_zero_init); if (!memset_start) memset_start = field; memset_end = field; } else { @@ -3104,8 +3106,8 @@ void MessageGenerator::GenerateClear(io::Printer* p) { // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check // _has_bits_[last_chunk * 8 / 32] multiple times. - GOOGLE_DCHECK_LE(2, popcnt(chunk_mask)); - GOOGLE_DCHECK_GE(8, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_LE(2, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_GE(8, popcnt(chunk_mask)); if (cached_has_word_index != HasWordIndex(chunk.front())) { cached_has_word_index = HasWordIndex(chunk.front()); @@ -3120,8 +3122,8 @@ void MessageGenerator::GenerateClear(io::Printer* p) { // For clarity, do not memset a single field. field_generators_.get(memset_start).GenerateMessageClearingCode(p); } else { - GOOGLE_CHECK_EQ(chunk_is_split, ShouldSplit(memset_start, options_)); - GOOGLE_CHECK_EQ(chunk_is_split, ShouldSplit(memset_end, options_)); + GOOGLE_ABSL_CHECK_EQ(chunk_is_split, ShouldSplit(memset_start, options_)); + GOOGLE_ABSL_CHECK_EQ(chunk_is_split, ShouldSplit(memset_end, options_)); format( "::memset(&$1$, 0, static_cast<::size_t>(\n" " reinterpret_cast(&$2$) -\n" @@ -3394,7 +3396,8 @@ void MessageGenerator::GenerateMergeFrom(io::Printer* p) { void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { if (HasSimpleBaseClass(descriptor_, options_)) return; - // Generate the class-specific MergeFrom, which avoids the GOOGLE_CHECK and cast. + // Generate the class-specific MergeFrom, which avoids the GOOGLE_ABSL_CHECK and + // cast. Formatter format(p); if (!HasDescriptorMethods(descriptor_->file(), options_)) { // For messages that don't inherit from Message, just implement MergeFrom @@ -3457,8 +3460,8 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check // _has_bits_[last_chunk * 8 / 32] multiple times. - GOOGLE_DCHECK_LE(2, popcnt(chunk_mask)); - GOOGLE_DCHECK_GE(8, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_LE(2, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_GE(8, popcnt(chunk_mask)); if (cached_has_word_index != HasWordIndex(chunk.front())) { cached_has_word_index = HasWordIndex(chunk.front()); @@ -3490,7 +3493,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { } else if (field->options().weak() || cached_has_word_index != HasWordIndex(field)) { // Check hasbit, not using cached bits. - GOOGLE_CHECK(HasHasbit(field)); + GOOGLE_ABSL_CHECK(HasHasbit(field)); auto v = p->WithVars(HasbitVars(HasBitIndex(field))); format( "if ((from.$has_bits$[$has_array_index$] & $has_mask$) != 0) {\n"); @@ -3500,7 +3503,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { format("}\n"); } else { // Check hasbit, using cached bits. - GOOGLE_CHECK(HasHasbit(field)); + GOOGLE_ABSL_CHECK(HasHasbit(field)); int has_bit_index = has_bit_indices_[field->index()]; const std::string mask = absl::StrCat( absl::Hex(1u << (has_bit_index % 32), absl::kZeroPad8)); @@ -3524,7 +3527,7 @@ void MessageGenerator::GenerateClassSpecificMergeImpl(io::Printer* p) { if (have_outer_if) { if (deferred_has_bit_changes) { // Flush the has bits for the primitives we deferred. - GOOGLE_CHECK_LE(0, cached_has_word_index); + GOOGLE_ABSL_CHECK_LE(0, cached_has_word_index); format("_this->$has_bits$[$1$] |= cached_has_bits;\n", cached_has_word_index); } @@ -3651,7 +3654,7 @@ void MessageGenerator::GenerateVerify(io::Printer* p) { void MessageGenerator::GenerateSerializeOneofFields( io::Printer* p, const std::vector& fields) { Formatter format(p); - GOOGLE_CHECK(!fields.empty()); + GOOGLE_ABSL_CHECK(!fields.empty()); if (fields.size() == 1) { GenerateSerializeOneField(p, fields[0], -1); return; @@ -4014,7 +4017,7 @@ void MessageGenerator::GenerateSerializeWithCachedSizesBodyShuffled( int num_fields = ordered_fields.size() + sorted_extensions.size(); constexpr int kLargePrime = 1000003; - GOOGLE_CHECK_LT(num_fields, kLargePrime) + GOOGLE_ABSL_CHECK_LT(num_fields, kLargePrime) << "Prime offset must be greater than the number of fields to ensure " "those are coprime."; @@ -4233,8 +4236,8 @@ void MessageGenerator::GenerateByteSize(io::Printer* p) { // Check (up to) 8 has_bits at a time if we have more than one field in // this chunk. Due to field layout ordering, we may check // _has_bits_[last_chunk * 8 / 32] multiple times. - GOOGLE_DCHECK_LE(2, popcnt(chunk_mask)); - GOOGLE_DCHECK_GE(8, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_LE(2, popcnt(chunk_mask)); + GOOGLE_ABSL_DCHECK_GE(8, popcnt(chunk_mask)); if (cached_has_word_index != HasWordIndex(chunk.front())) { cached_has_word_index = HasWordIndex(chunk.front()); diff --git a/src/google/protobuf/compiler/cpp/message_field.cc b/src/google/protobuf/compiler/cpp/message_field.cc index 175313c3aa..20d0eabb90 100644 --- a/src/google/protobuf/compiler/cpp/message_field.cc +++ b/src/google/protobuf/compiler/cpp/message_field.cc @@ -35,6 +35,7 @@ #include "google/protobuf/compiler/cpp/message_field.h" #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/field.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -386,7 +387,7 @@ void MessageFieldGenerator::GenerateInternalAccessorDefinitions( } void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (!internal::cpp::HasHasbit(descriptor_)) { @@ -404,7 +405,7 @@ void MessageFieldGenerator::GenerateClearingCode(io::Printer* printer) const { void MessageFieldGenerator::GenerateMessageClearingCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (!internal::cpp::HasHasbit(descriptor_)) { @@ -423,7 +424,7 @@ void MessageFieldGenerator::GenerateMessageClearingCode( } void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (implicit_weak_field_) { @@ -438,14 +439,14 @@ void MessageFieldGenerator::GenerateMergingCode(io::Printer* printer) const { } void MessageFieldGenerator::GenerateSwappingCode(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format("swap($field$, other->$field$);\n"); } void MessageFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (options_.opensource_runtime) { @@ -467,7 +468,7 @@ using internal::cpp::HasHasbit; void MessageFieldGenerator::GenerateCopyConstructorCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (HasHasbit(descriptor_)) { @@ -485,7 +486,7 @@ void MessageFieldGenerator::GenerateCopyConstructorCode( void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (descriptor_->type() == FieldDescriptor::TYPE_MESSAGE) { @@ -503,7 +504,7 @@ void MessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( } void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format( @@ -513,7 +514,7 @@ void MessageFieldGenerator::GenerateByteSize(io::Printer* printer) const { } void MessageFieldGenerator::GenerateIsInitialized(io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); if (!has_required_fields_) return; @@ -695,7 +696,7 @@ void MessageOneofFieldGenerator::GenerateInlineAccessorDefinitions( void MessageOneofFieldGenerator::GenerateClearingCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format( @@ -866,7 +867,7 @@ void RepeatedMessageFieldGenerator::GenerateInlineAccessorDefinitions( void RepeatedMessageFieldGenerator::GenerateClearingCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format("$field$.Clear();\n"); @@ -874,7 +875,7 @@ void RepeatedMessageFieldGenerator::GenerateClearingCode( void RepeatedMessageFieldGenerator::GenerateMergingCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format("_this->$field$.MergeFrom(from.$field$);\n"); @@ -882,7 +883,7 @@ void RepeatedMessageFieldGenerator::GenerateMergingCode( void RepeatedMessageFieldGenerator::GenerateSwappingCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format("$field$.InternalSwap(&other->$field$);\n"); @@ -895,7 +896,7 @@ void RepeatedMessageFieldGenerator::GenerateConstructorCode( void RepeatedMessageFieldGenerator::GenerateDestructorCode( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (implicit_weak_field_) { @@ -907,7 +908,7 @@ void RepeatedMessageFieldGenerator::GenerateDestructorCode( void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); if (implicit_weak_field_) { @@ -952,7 +953,7 @@ void RepeatedMessageFieldGenerator::GenerateSerializeWithCachedSizesToArray( void RepeatedMessageFieldGenerator::GenerateByteSize( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); Formatter format(printer, variables_); format( @@ -965,7 +966,7 @@ void RepeatedMessageFieldGenerator::GenerateByteSize( void RepeatedMessageFieldGenerator::GenerateIsInitialized( io::Printer* printer) const { - GOOGLE_CHECK(!IsFieldStripped(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!IsFieldStripped(descriptor_, options_)); if (!has_required_fields_) return; diff --git a/src/google/protobuf/compiler/cpp/message_size_unittest.cc b/src/google/protobuf/compiler/cpp/message_size_unittest.cc index 36eeb92271..6d6bf6e5c6 100644 --- a/src/google/protobuf/compiler/cpp/message_size_unittest.cc +++ b/src/google/protobuf/compiler/cpp/message_size_unittest.cc @@ -30,6 +30,7 @@ #include #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/descriptor.h" #include "google/protobuf/unittest.pb.h" @@ -42,8 +43,8 @@ namespace cpp { namespace cpp_unittest { -#if !defined(GOOGLE_CHECK_MESSAGE_SIZE) -#define GOOGLE_CHECK_MESSAGE_SIZE(t, expected) +#if !defined(GOOGLE_ABSL_CHECK_MESSAGE_SIZE) +#define GOOGLE_ABSL_CHECK_MESSAGE_SIZE(t, expected) #endif // Mock structures to lock down the size of messages in a platform-independent @@ -52,13 +53,13 @@ struct MockMessageBase { virtual ~MockMessageBase() = default; // 8 bytes vtable void* internal_metadata; // 8 bytes }; -GOOGLE_CHECK_MESSAGE_SIZE(MockMessageBase, 16); +GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockMessageBase, 16); struct MockZeroFieldsBase : public MockMessageBase { int cached_size; // 4 bytes // + 4 bytes padding }; -GOOGLE_CHECK_MESSAGE_SIZE(MockZeroFieldsBase, 24); +GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockZeroFieldsBase, 24); struct MockExtensionSet { void* arena; // 8 bytes @@ -66,7 +67,7 @@ struct MockExtensionSet { int16_t size; // 4 bytes void* data; // 8 bytes }; -GOOGLE_CHECK_MESSAGE_SIZE(MockExtensionSet, 24); +GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockExtensionSet, 24); struct MockRepeatedPtrField { void* arena; // 8 bytes @@ -74,23 +75,24 @@ struct MockRepeatedPtrField { int total_size; // 4 bytes void* data; // 8 bytes }; -GOOGLE_CHECK_MESSAGE_SIZE(MockRepeatedPtrField, 24); +GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockRepeatedPtrField, 24); struct MockRepeatedField { int current_size; // 4 bytes int total_size; // 4 bytes void* data; // 8 bytes }; -GOOGLE_CHECK_MESSAGE_SIZE(MockRepeatedField, 16); +GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockRepeatedField, 16); TEST(GeneratedMessageTest, MockSizes) { // Consistency checks -- if these fail, the tests below will definitely fail. - GOOGLE_CHECK_EQ(sizeof(MessageLite), sizeof(MockMessageBase)); - GOOGLE_CHECK_EQ(sizeof(Message), sizeof(MockMessageBase)); - GOOGLE_CHECK_EQ(sizeof(internal::ZeroFieldsBase), sizeof(MockZeroFieldsBase)); - GOOGLE_CHECK_EQ(sizeof(internal::ExtensionSet), sizeof(MockExtensionSet)); - GOOGLE_CHECK_EQ(sizeof(RepeatedPtrField), sizeof(MockRepeatedPtrField)); - GOOGLE_CHECK_EQ(sizeof(RepeatedField), sizeof(MockRepeatedField)); + GOOGLE_ABSL_CHECK_EQ(sizeof(MessageLite), sizeof(MockMessageBase)); + GOOGLE_ABSL_CHECK_EQ(sizeof(Message), sizeof(MockMessageBase)); + GOOGLE_ABSL_CHECK_EQ(sizeof(internal::ZeroFieldsBase), sizeof(MockZeroFieldsBase)); + GOOGLE_ABSL_CHECK_EQ(sizeof(internal::ExtensionSet), sizeof(MockExtensionSet)); + GOOGLE_ABSL_CHECK_EQ(sizeof(RepeatedPtrField), + sizeof(MockRepeatedPtrField)); + GOOGLE_ABSL_CHECK_EQ(sizeof(RepeatedField), sizeof(MockRepeatedField)); } TEST(GeneratedMessageTest, EmptyMessageSize) { @@ -109,7 +111,7 @@ TEST(GeneratedMessageTest, EmptyMessageWithExtensionsSize) { int cached_size; // 4 bytes // + 4 bytes of padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48); EXPECT_EQ(sizeof(protobuf_unittest::TestEmptyMessageWithExtensions), sizeof(MockGenerated)); } @@ -122,7 +124,7 @@ TEST(GeneratedMessageTest, RecursiveMessageSize) { int32_t i; // 4 bytes // + 4 bytes padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 40); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 40); EXPECT_EQ(sizeof(protobuf_unittest::TestRecursiveMessage), sizeof(MockGenerated)); } @@ -133,7 +135,7 @@ TEST(GeneratedMessageTest, OneStringSize) { int cached_size; // 4 bytes void* data; // 8 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::OneString), sizeof(MockGenerated)); } @@ -143,7 +145,7 @@ TEST(GeneratedMessageTest, MoreStringSize) { MockRepeatedPtrField data; // 24 bytes // + 4 bytes padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 48); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 48); EXPECT_EQ(sizeof(protobuf_unittest::MoreString), sizeof(MockGenerated)); } @@ -154,7 +156,7 @@ TEST(GeneratedMessageTest, Int32MessageSize) { int32_t data; // 4 bytes // + 4 bytes padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::Int32Message), sizeof(MockGenerated)); } @@ -164,7 +166,7 @@ TEST(GeneratedMessageTest, Int64MessageSize) { int cached_size; // 4 bytes int64_t data; // 8 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::Int64Message), sizeof(MockGenerated)); } @@ -175,7 +177,7 @@ TEST(GeneratedMessageTest, BoolMessageSize) { bool data; // 1 byte // + 3 bytes padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::BoolMessage), sizeof(MockGenerated)); } @@ -185,7 +187,7 @@ TEST(GeneratedMessageTest, OneofSize) { int cached_size; // 4 bytes uint32_t oneof_case[1]; // 4 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 32); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 32); EXPECT_EQ(sizeof(protobuf_unittest::TestOneof), sizeof(MockGenerated)); } @@ -200,7 +202,7 @@ TEST(GeneratedMessageTest, Oneof2Size) { void* bar; // 8 bytes uint32_t oneof_case[2]; // 8 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 64); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 64); EXPECT_EQ(sizeof(protobuf_unittest::TestOneof2), sizeof(MockGenerated)); } @@ -215,7 +217,7 @@ TEST(GeneratedMessageTest, FieldOrderingsSize) { float my_float; // 4 bytes // + 4 bytes of padding }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 80); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 80); EXPECT_EQ(sizeof(protobuf_unittest::TestFieldOrderings), sizeof(MockGenerated)); } @@ -232,7 +234,7 @@ TEST(GeneratedMessageTest, TestMessageSize) { int m5; // 4 bytes int64_t m6; // 8 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 56); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 56); EXPECT_EQ(sizeof(protobuf_unittest::TestMessageSize), sizeof(MockGenerated)); } @@ -261,7 +263,7 @@ TEST(GeneratedMessageTest, PackedTypesSize) { int packed_enum_cached_byte_size; // 4 bytes int cached_size; // 4 bytes }; - GOOGLE_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8); + GOOGLE_ABSL_CHECK_MESSAGE_SIZE(MockGenerated, 16 * 15 + 8 * 6 + 8); EXPECT_EQ(sizeof(protobuf_unittest::TestPackedTypes), sizeof(MockGenerated)); } diff --git a/src/google/protobuf/compiler/cpp/metadata_test.cc b/src/google/protobuf/compiler/cpp/metadata_test.cc index 2a516553e6..a4e4888c3a 100644 --- a/src/google/protobuf/compiler/cpp/metadata_test.cc +++ b/src/google/protobuf/compiler/cpp/metadata_test.cc @@ -37,6 +37,7 @@ #include "google/protobuf/descriptor.pb.h" #include "google/protobuf/testing/googletest.h" #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/annotation_test_util.h" #include "google/protobuf/compiler/cpp/helpers.h" @@ -77,12 +78,12 @@ class CppMetadataTest : public ::testing::Test { std::string output_base = TestTempDir() + "/" + StripProto(filename); if (pb_cc != nullptr) { - GOOGLE_CHECK_OK( + GOOGLE_ABSL_CHECK_OK( File::GetContents(output_base + ".pb.cc", pb_cc, true)); } if (pb_h != nullptr && pb_h_info != nullptr) { - GOOGLE_CHECK_OK( + GOOGLE_ABSL_CHECK_OK( File::GetContents(output_base + ".pb.h", pb_h, true)); if (!atu::DecodeMetadata(output_base + ".pb.h.meta", pb_h_info)) { return false; @@ -90,8 +91,8 @@ class CppMetadataTest : public ::testing::Test { } if (proto_h != nullptr && proto_h_info != nullptr) { - GOOGLE_CHECK_OK(File::GetContents(output_base + ".proto.h", proto_h, - true)); + GOOGLE_ABSL_CHECK_OK(File::GetContents(output_base + ".proto.h", proto_h, + true)); if (!atu::DecodeMetadata(output_base + ".proto.h.meta", proto_h_info)) { return false; } diff --git a/src/google/protobuf/compiler/cpp/padding_optimizer.cc b/src/google/protobuf/compiler/cpp/padding_optimizer.cc index d611c34f00..4ababbf088 100644 --- a/src/google/protobuf/compiler/cpp/padding_optimizer.cc +++ b/src/google/protobuf/compiler/cpp/padding_optimizer.cc @@ -30,6 +30,7 @@ #include "google/protobuf/compiler/cpp/padding_optimizer.h" +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/helpers.h" namespace google { @@ -137,8 +138,9 @@ static void OptimizeLayoutHelper(std::vector* fields, aligned_to_8[f].push_back(FieldGroup(j, field)); break; default: - GOOGLE_LOG(FATAL) << "Unknown alignment size " << EstimateAlignmentSize(field) - << "for a field " << field->full_name() << "."; + GOOGLE_ABSL_LOG(FATAL) << "Unknown alignment size " + << EstimateAlignmentSize(field) << "for a field " + << field->full_name() << "."; } } diff --git a/src/google/protobuf/compiler/cpp/parse_function_generator.cc b/src/google/protobuf/compiler/cpp/parse_function_generator.cc index e4f8edf4ab..ce8a34b723 100644 --- a/src/google/protobuf/compiler/cpp/parse_function_generator.cc +++ b/src/google/protobuf/compiler/cpp/parse_function_generator.cc @@ -37,6 +37,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/generated_message_tctable_gen.h" @@ -210,7 +211,7 @@ bool ParseFunctionGenerator::should_generate_tctable() const { } void ParseFunctionGenerator::GenerateTailcallParseFunction(Formatter& format) { - GOOGLE_CHECK(should_generate_tctable()); + GOOGLE_ABSL_CHECK(should_generate_tctable()); // Generate an `_InternalParse` that starts the tail-calling loop. format( @@ -237,7 +238,7 @@ static bool NeedsUnknownEnumSupport(const Descriptor* descriptor) { void ParseFunctionGenerator::GenerateTailcallFallbackFunction( Formatter& format) { - GOOGLE_CHECK(should_generate_tctable()); + GOOGLE_ABSL_CHECK(should_generate_tctable()); format( "const char* $classname$::Tct_ParseFallback(PROTOBUF_TC_PARAM_DECL) {\n" "#define CHK_(x) if (PROTOBUF_PREDICT_FALSE(!(x))) return nullptr\n"); @@ -429,7 +430,7 @@ static NumToEntryTable MakeNumToEntryTable( for (; field_entry_index != N; ++field_entry_index) { auto* field_descriptor = field_descriptors[field_entry_index]; uint32_t fnum = field_descriptor->number(); - GOOGLE_CHECK_GT(fnum, last_skip_entry_start); + GOOGLE_ABSL_CHECK_GT(fnum, last_skip_entry_start); if (start_new_block == false) { // If the next field number is within 15 of the last_skip_entry_start, we // continue writing just to that entry. If it's between 16 and 31 more, @@ -462,7 +463,7 @@ static NumToEntryTable MakeNumToEntryTable( } void ParseFunctionGenerator::GenerateTailCallTable(Formatter& format) { - GOOGLE_CHECK(should_generate_tctable()); + GOOGLE_ABSL_CHECK(should_generate_tctable()); // All entries without a fast-path parsing function need a fallback. std::string fallback; if (tc_table_info_->use_generated_fallback) { @@ -573,7 +574,7 @@ void ParseFunctionGenerator::GenerateTailCallTable(Formatter& format) { format("65535, 65535\n"); } if (ordered_fields_.empty()) { - GOOGLE_LOG_IF(DFATAL, !tc_table_info_->aux_entries.empty()) + GOOGLE_ABSL_LOG_IF(DFATAL, !tc_table_info_->aux_entries.empty()) << "Invalid message: " << descriptor_->full_name() << " has " << tc_table_info_->aux_entries.size() << " auxiliary field entries, but no fields"; @@ -679,7 +680,7 @@ void ParseFunctionGenerator::GenerateFastFieldEntries(Formatter& format) { format("{$1$, {$2$, $3$}},\n", info.func_name, info.coded_tag, info.nonfield_info); } else { - GOOGLE_CHECK(!ShouldSplit(info.field, options_)); + GOOGLE_ABSL_CHECK(!ShouldSplit(info.field, options_)); std::string func_name = info.func_name; if (GetOptimizeFor(info.field->file(), options_) == FileOptions::SPEED) { @@ -746,7 +747,7 @@ static void FormatFieldKind(Formatter& format, PROTOBUF_INTERNAL_TYPE_CARD_CASE(RawString); PROTOBUF_INTERNAL_TYPE_CARD_CASE(Utf8String); default: - GOOGLE_LOG(FATAL) << "Unknown type_card: 0x" << type_card; + GOOGLE_ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; } static constexpr const char* kRepNames[] = {"AString", "IString", "Cord", @@ -831,7 +832,7 @@ static void FormatFieldKind(Formatter& format, PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedSInt64); PROTOBUF_INTERNAL_TYPE_CARD_CASE(PackedDouble); default: - GOOGLE_LOG(FATAL) << "Unknown type_card: 0x" << type_card; + GOOGLE_ABSL_LOG(FATAL) << "Unknown type_card: 0x" << type_card; } } } @@ -924,13 +925,13 @@ void ParseFunctionGenerator::GenerateArenaString(Formatter& format, "if (arena != nullptr) {\n" " ptr = ctx->ReadArenaString(ptr, &$msg$$field$, arena"); if (IsStringInlined(field, options_)) { - GOOGLE_DCHECK(!inlined_string_indices_.empty()); + GOOGLE_ABSL_DCHECK(!inlined_string_indices_.empty()); int inlined_string_index = inlined_string_indices_[field->index()]; - GOOGLE_DCHECK_GT(inlined_string_index, 0); + GOOGLE_ABSL_DCHECK_GT(inlined_string_index, 0); format(", &$msg$$inlined_string_donated_array$[0], $1$, $this$", inlined_string_index); } else { - GOOGLE_DCHECK(field->default_value_string().empty()); + GOOGLE_ABSL_DCHECK(field->default_value_string().empty()); } format( ");\n" @@ -1043,7 +1044,7 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, case FieldDescriptor::TYPE_MESSAGE: { if (field->is_map()) { const FieldDescriptor* val = field->message_type()->map_value(); - GOOGLE_CHECK(val); + GOOGLE_ABSL_CHECK(val); if (val->type() == FieldDescriptor::TYPE_ENUM && !internal::cpp::HasPreservingUnknownEnumSemantics(field)) { format( @@ -1131,8 +1132,8 @@ void ParseFunctionGenerator::GenerateLengthDelim(Formatter& format, break; } default: - GOOGLE_LOG(FATAL) << "Illegal combination for length delimited wiretype " - << " filed type is " << field->type(); + GOOGLE_ABSL_LOG(FATAL) << "Illegal combination for length delimited wiretype " + << " filed type is " << field->type(); } } } @@ -1246,7 +1247,7 @@ void ParseFunctionGenerator::GenerateFieldBody( break; } case WireFormatLite::WIRETYPE_END_GROUP: { - GOOGLE_LOG(FATAL) << "Can't have end group field\n"; + GOOGLE_ABSL_LOG(FATAL) << "Can't have end group field\n"; break; } } // switch (wire_type) @@ -1260,7 +1261,7 @@ static uint32_t ExpectedTag(const FieldDescriptor* field, if (field->is_packable()) { auto expected_wiretype = WireFormat::WireTypeForFieldType(field->type()); expected_tag = WireFormatLite::MakeTag(field->number(), expected_wiretype); - GOOGLE_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); + GOOGLE_ABSL_CHECK(expected_wiretype != WireFormatLite::WIRETYPE_LENGTH_DELIMITED); auto fallback_wiretype = WireFormatLite::WIRETYPE_LENGTH_DELIMITED; uint32_t fallback_tag = WireFormatLite::MakeTag(field->number(), fallback_wiretype); diff --git a/src/google/protobuf/compiler/cpp/plugin_unittest.cc b/src/google/protobuf/compiler/cpp/plugin_unittest.cc index b303bd0bbb..ee3dfb77fb 100644 --- a/src/google/protobuf/compiler/cpp/plugin_unittest.cc +++ b/src/google/protobuf/compiler/cpp/plugin_unittest.cc @@ -42,6 +42,7 @@ #include "google/protobuf/compiler/command_line_interface.h" #include "google/protobuf/testing/googletest.h" #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/io/printer.h" #include "google/protobuf/io/zero_copy_stream.h" @@ -171,44 +172,44 @@ class TestGenerator : public CodeGenerator { // not verify that they are correctly-placed; that would require actually // compiling the output which is a bit more than I care to do for this test. TEST(CppPluginTest, PluginTest) { - GOOGLE_CHECK_OK(File::SetContents(TestTempDir() + "/test.proto", - "syntax = \"proto2\";\n" - "package foo;\n" - "\n" - "enum Thud { VALUE = 0; }\n" - "\n" - "message Bar {\n" - " message Baz {}\n" - " optional int32 optInt = 1;\n" - " repeated int32 repeatedInt = 2;\n" - "\n" - " required string requiredString = 3;\n" - " repeated string repeatedString = 4;\n" - "\n" - " optional Baz optMessage = 6;\n" - " repeated Baz repeatedMessage = 7;\n" - "\n" - " optional Thud optEnum = 8;\n" - " repeated Thud repeatedEnum = 9;\n" - "\n" - " required string requiredCord = 10 [\n" - " ctype = CORD\n" - " ];\n" - " repeated string repeatedCord = 11 [\n" - " ctype = CORD\n" - " ];\n" - "\n" - " oneof Moo {\n" - " int64 oneOfInt = 20;\n" - " string oneOfString = 21;\n" - " Baz oneOfMessage = 22;\n" - " Thud oneOfEnum = 23;" - " string oneOfCord = 24 [\n" - " ctype = CORD\n" - " ];\n" - " }\n" - "}\n", - true)); + GOOGLE_ABSL_CHECK_OK(File::SetContents(TestTempDir() + "/test.proto", + "syntax = \"proto2\";\n" + "package foo;\n" + "\n" + "enum Thud { VALUE = 0; }\n" + "\n" + "message Bar {\n" + " message Baz {}\n" + " optional int32 optInt = 1;\n" + " repeated int32 repeatedInt = 2;\n" + "\n" + " required string requiredString = 3;\n" + " repeated string repeatedString = 4;\n" + "\n" + " optional Baz optMessage = 6;\n" + " repeated Baz repeatedMessage = 7;\n" + "\n" + " optional Thud optEnum = 8;\n" + " repeated Thud repeatedEnum = 9;\n" + "\n" + " required string requiredCord = 10 [\n" + " ctype = CORD\n" + " ];\n" + " repeated string repeatedCord = 11 [\n" + " ctype = CORD\n" + " ];\n" + "\n" + " oneof Moo {\n" + " int64 oneOfInt = 20;\n" + " string oneOfString = 21;\n" + " Baz oneOfMessage = 22;\n" + " Thud oneOfEnum = 23;" + " string oneOfCord = 24 [\n" + " ctype = CORD\n" + " ];\n" + " }\n" + "}\n", + true)); CommandLineInterface cli; cli.SetInputsAreProtoPathRelative(true); diff --git a/src/google/protobuf/compiler/cpp/primitive_field.cc b/src/google/protobuf/compiler/cpp/primitive_field.cc index e672d0917a..fa0a4d306b 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.cc +++ b/src/google/protobuf/compiler/cpp/primitive_field.cc @@ -38,6 +38,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/descriptor.pb.h" @@ -99,7 +100,7 @@ int FixedSize(FieldDescriptor::Type type) { // No default because we want the compiler to complain if any new // types are added. } - GOOGLE_LOG(FATAL) << "Can't get here."; + GOOGLE_ABSL_LOG(FATAL) << "Can't get here."; return -1; } diff --git a/src/google/protobuf/compiler/cpp/primitive_field.h b/src/google/protobuf/compiler/cpp/primitive_field.h index 78e717b417..43ada6ff5d 100644 --- a/src/google/protobuf/compiler/cpp/primitive_field.h +++ b/src/google/protobuf/compiler/cpp/primitive_field.h @@ -37,6 +37,7 @@ #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/field.h" namespace google { @@ -105,7 +106,7 @@ class RepeatedPrimitiveFieldGenerator : public FieldGenerator { void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override {} void GenerateCopyConstructorCode(io::Printer* /*printer*/) const override { - GOOGLE_CHECK(!ShouldSplit(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!ShouldSplit(descriptor_, options_)); } void GenerateDestructorCode(io::Printer* printer) const override; void GenerateSerializeWithCachedSizesToArray( diff --git a/src/google/protobuf/compiler/cpp/string_field.cc b/src/google/protobuf/compiler/cpp/string_field.cc index 7c53fa9dff..3446285ad8 100644 --- a/src/google/protobuf/compiler/cpp/string_field.cc +++ b/src/google/protobuf/compiler/cpp/string_field.cc @@ -37,6 +37,7 @@ #include #include "absl/container/flat_hash_map.h" +#include "google/protobuf/stubs/logging.h" #include "absl/strings/str_cat.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/descriptor.pb.h" @@ -369,7 +370,7 @@ void StringFieldGenerator::GenerateClearingCode(io::Printer* printer) const { if (descriptor_->default_value_string().empty()) { format("$field$.ClearToEmpty();\n"); } else { - GOOGLE_DCHECK(!inlined_); + GOOGLE_ABSL_DCHECK(!inlined_); format( "$field$.ClearToDefault($lazy_variable$, GetArenaForAllocation());\n"); } @@ -443,7 +444,7 @@ void StringFieldGenerator::GenerateConstructorCode(io::Printer* printer) const { if (inlined_ && descriptor_->default_value_string().empty()) { return; } - GOOGLE_DCHECK(!inlined_); + GOOGLE_ABSL_DCHECK(!inlined_); format("$field$.InitDefault();\n"); if (IsString(descriptor_, options_) && descriptor_->default_value_string().empty()) { @@ -499,7 +500,7 @@ void StringFieldGenerator::GenerateDestructorCode(io::Printer* printer) const { // Destructor has been implicitly skipped as a union, and even the // message-owned arena is enabled, arena could still be missing for // Arena::CreateMessage(nullptr). - GOOGLE_DCHECK(!ShouldSplit(descriptor_, options_)); + GOOGLE_ABSL_DCHECK(!ShouldSplit(descriptor_, options_)); format("$field$.~InlinedStringField();\n"); } @@ -557,7 +558,7 @@ void StringFieldGenerator::GenerateAggregateInitializer( io::Printer* printer) const { Formatter format(printer, variables_); if (ShouldSplit(descriptor_, options_)) { - GOOGLE_CHECK(!inlined_); + GOOGLE_ABSL_CHECK(!inlined_); format("decltype(Impl_::Split::$name$_){}"); return; } diff --git a/src/google/protobuf/compiler/cpp/string_field.h b/src/google/protobuf/compiler/cpp/string_field.h index 67cfa34c8c..1280fa08be 100644 --- a/src/google/protobuf/compiler/cpp/string_field.h +++ b/src/google/protobuf/compiler/cpp/string_field.h @@ -37,6 +37,7 @@ #include +#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/field.h" namespace google { @@ -119,7 +120,7 @@ class RepeatedStringFieldGenerator : public FieldGenerator { void GenerateSwappingCode(io::Printer* printer) const override; void GenerateConstructorCode(io::Printer* printer) const override {} void GenerateCopyConstructorCode(io::Printer* /*printer*/) const override { - GOOGLE_CHECK(!ShouldSplit(descriptor_, options_)); + GOOGLE_ABSL_CHECK(!ShouldSplit(descriptor_, options_)); } void GenerateDestructorCode(io::Printer* printer) const override; void GenerateSerializeWithCachedSizesToArray( diff --git a/src/google/protobuf/compiler/cpp/unittest.inc b/src/google/protobuf/compiler/cpp/unittest.inc index 3499fb5b85..292f70002e 100644 --- a/src/google/protobuf/compiler/cpp/unittest.inc +++ b/src/google/protobuf/compiler/cpp/unittest.inc @@ -59,7 +59,6 @@ #endif #include "google/protobuf/stubs/callback.h" #include "google/protobuf/stubs/common.h" -#include "google/protobuf/stubs/logging.h" #include "google/protobuf/compiler/cpp/helpers.h" #include "google/protobuf/unittest_no_generic_services.pb.h" #include "google/protobuf/descriptor.pb.h"