Omit the `_raw_default_instance_` declaration when using DLL linkage.

In that mode we might not be able to make a `constexpr` pointer to the default
instance. Omitting the declaration will only turn off an optimization, but the
code will still be correct.

Fixes https://github.com/protocolbuffers/protobuf/issues/17303

PiperOrigin-RevId: 649160060
pull/17331/head
Protobuf Team Bot 8 months ago committed by Sandy Zhang
parent 7592817d04
commit 22d9a03056
  1. 15
      src/google/protobuf/compiler/cpp/message.cc
  2. 2
      src/google/protobuf/compiler/java/java_features.pb.h
  3. 8
      src/google/protobuf/compiler/plugin.pb.h
  4. 2
      src/google/protobuf/cpp_features.pb.h
  5. 66
      src/google/protobuf/descriptor.pb.h

@ -1904,6 +1904,18 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$pbi$::ParseContext* ctx);
)cc");
}},
{"raw_default_instance",
[&] {
// We can't make a constexpr pointer to the global if we have DLL
// linkage so skip this. The fallback in
// `MessageLite::GetStrongPointerForType` will do the right thing in
// those platforms.
if (!options_.dllexport_decl.empty()) return;
p->Emit(R"cc(
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
)cc");
}},
{"decl_impl", [&] { GenerateImplDefinition(p); }},
{"split_friend",
[&] {
@ -2043,8 +2055,7 @@ void MessageGenerator::GenerateClassDefinition(io::Printer* p) {
$decl_data$;
$post_loop_handler$;
static constexpr const void* _raw_default_instance_ =
&_$classname$_default_instance_;
$raw_default_instance$;
friend class ::$proto_ns$::MessageLite;
friend class ::$proto_ns$::Arena;

@ -276,8 +276,6 @@ class PROTOC_EXPORT JavaFeatures final : public ::google::protobuf::Message
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_JavaFeatures_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;

@ -303,8 +303,6 @@ class PROTOC_EXPORT Version final : public ::google::protobuf::Message
47, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_Version_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -537,8 +535,6 @@ class PROTOC_EXPORT CodeGeneratorResponse_File final : public ::google::protobuf
86, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorResponse_File_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -794,8 +790,6 @@ class PROTOC_EXPORT CodeGeneratorResponse final : public ::google::protobuf::Mes
60, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorResponse_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -1063,8 +1057,6 @@ class PROTOC_EXPORT CodeGeneratorRequest final : public ::google::protobuf::Mess
79, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CodeGeneratorRequest_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;

@ -278,8 +278,6 @@ class PROTOBUF_EXPORT CppFeatures final : public ::google::protobuf::Message
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_CppFeatures_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;

@ -870,8 +870,6 @@ class PROTOBUF_EXPORT UninterpretedOption_NamePart final : public ::google::prot
62, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_UninterpretedOption_NamePart_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -1135,8 +1133,6 @@ class PROTOBUF_EXPORT SourceCodeInfo_Location final : public ::google::protobuf:
106, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_SourceCodeInfo_Location_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -1395,8 +1391,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo_Annotation final : public ::google::prot
64, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_GeneratedCodeInfo_Annotation_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -1615,8 +1609,6 @@ class PROTOBUF_EXPORT FieldOptions_FeatureSupport final : public ::google::proto
71, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldOptions_FeatureSupport_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -1809,8 +1801,6 @@ class PROTOBUF_EXPORT FieldOptions_EditionDefault final : public ::google::proto
57, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldOptions_EditionDefault_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -2348,8 +2338,6 @@ class PROTOBUF_EXPORT FeatureSet final : public ::google::protobuf::Message
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSet_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -2587,8 +2575,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions_Declaration final : public ::google:
71, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ExtensionRangeOptions_Declaration_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -2776,8 +2762,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto_EnumReservedRange final : public ::goo
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumDescriptorProto_EnumReservedRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -2962,8 +2946,6 @@ class PROTOBUF_EXPORT DescriptorProto_ReservedRange final : public ::google::pro
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_ReservedRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -3238,8 +3220,6 @@ class PROTOBUF_EXPORT UninterpretedOption final : public ::google::protobuf::Mes
75, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_UninterpretedOption_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -3424,8 +3404,6 @@ class PROTOBUF_EXPORT SourceCodeInfo final : public ::google::protobuf::Message
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_SourceCodeInfo_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -3603,8 +3581,6 @@ class PROTOBUF_EXPORT GeneratedCodeInfo final : public ::google::protobuf::Messa
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_GeneratedCodeInfo_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -3812,8 +3788,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults_FeatureSetEditionDefault final : public
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSetDefaults_FeatureSetEditionDefault_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -4205,8 +4179,6 @@ class PROTOBUF_EXPORT ServiceOptions final : public ::google::protobuf::Message
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ServiceOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -4587,8 +4559,6 @@ class PROTOBUF_EXPORT OneofOptions final : public ::google::protobuf::Message
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_OneofOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -5012,8 +4982,6 @@ class PROTOBUF_EXPORT MethodOptions final : public ::google::protobuf::Message
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MethodOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -5455,8 +5423,6 @@ class PROTOBUF_EXPORT MessageOptions final : public ::google::protobuf::Message
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MessageOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -6149,8 +6115,6 @@ class PROTOBUF_EXPORT FileOptions final : public ::google::protobuf::Message
202, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -6800,8 +6764,6 @@ class PROTOBUF_EXPORT FieldOptions final : public ::google::protobuf::Message
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -7023,8 +6985,6 @@ class PROTOBUF_EXPORT FeatureSetDefaults final : public ::google::protobuf::Mess
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FeatureSetDefaults_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -7454,8 +7414,6 @@ class PROTOBUF_EXPORT ExtensionRangeOptions final : public ::google::protobuf::M
0, 12>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ExtensionRangeOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -7877,8 +7835,6 @@ class PROTOBUF_EXPORT EnumValueOptions final : public ::google::protobuf::Messag
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumValueOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -8297,8 +8253,6 @@ class PROTOBUF_EXPORT EnumOptions final : public ::google::protobuf::Message
0, 7>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumOptions_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -8502,8 +8456,6 @@ class PROTOBUF_EXPORT OneofDescriptorProto final : public ::google::protobuf::Me
49, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_OneofDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -8763,8 +8715,6 @@ class PROTOBUF_EXPORT MethodDescriptorProto final : public ::google::protobuf::M
71, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_MethodDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -9155,8 +9105,6 @@ class PROTOBUF_EXPORT FieldDescriptorProto final : public ::google::protobuf::Me
96, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FieldDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -9377,8 +9325,6 @@ class PROTOBUF_EXPORT EnumValueDescriptorProto final : public ::google::protobuf
53, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumValueDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -9585,8 +9531,6 @@ class PROTOBUF_EXPORT DescriptorProto_ExtensionRange final : public ::google::pr
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_ExtensionRange_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -9805,8 +9749,6 @@ class PROTOBUF_EXPORT ServiceDescriptorProto final : public ::google::protobuf::
51, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_ServiceDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -10073,8 +10015,6 @@ class PROTOBUF_EXPORT EnumDescriptorProto final : public ::google::protobuf::Mes
61, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_EnumDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -10434,8 +10374,6 @@ class PROTOBUF_EXPORT DescriptorProto final : public ::google::protobuf::Message
65, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_DescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -10846,8 +10784,6 @@ class PROTOBUF_EXPORT FileDescriptorProto final : public ::google::protobuf::Mes
79, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileDescriptorProto_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;
@ -11042,8 +10978,6 @@ class PROTOBUF_EXPORT FileDescriptorSet final : public ::google::protobuf::Messa
0, 2>
_table_;
static constexpr const void* _raw_default_instance_ =
&_FileDescriptorSet_default_instance_;
friend class ::google::protobuf::MessageLite;
friend class ::google::protobuf::Arena;

Loading…
Cancel
Save