@@ -4741,12 +4741,12 @@ static void AddLazyVectorDecls(ASTWriter &Writer, Vector &Vec) {
4741
4741
}
4742
4742
}
4743
4743
4744
- template <typename Vector>
4745
- static void AddLazyVectorDecls (ASTWriter &Writer, Vector &Vec,
4746
- ASTWriter::RecordData &Record) {
4744
+ template <typename Vector>
4745
+ static void AddLazyVectorEmiitedDecls (ASTWriter &Writer, Vector &Vec,
4746
+ ASTWriter::RecordData &Record) {
4747
4747
for (typename Vector::iterator I = Vec.begin (nullptr , true ), E = Vec.end ();
4748
4748
I != E; ++I) {
4749
- Writer.AddDeclRef (*I, Record);
4749
+ Writer.AddEmittedDeclRef (*I, Record);
4750
4750
}
4751
4751
}
4752
4752
@@ -4882,6 +4882,25 @@ void ASTWriter::PrepareWritingSpecialDecls(Sema &SemaRef) {
4882
4882
RegisterPredefDecl (Context.TypePackElementDecl ,
4883
4883
PREDEF_DECL_TYPE_PACK_ELEMENT_ID);
4884
4884
4885
+ const TranslationUnitDecl *TU = Context.getTranslationUnitDecl ();
4886
+
4887
+ // Force all top level declarations to be emitted.
4888
+ //
4889
+ // We start emitting top level declarations from the module purview to
4890
+ // implement the eliding unreachable declaration feature.
4891
+ for (const auto *D : TU->noload_decls ()) {
4892
+ if (D->isFromASTFile ())
4893
+ continue ;
4894
+
4895
+ if (GeneratingReducedBMI && D->isFromExplicitGlobalModule ())
4896
+ continue ;
4897
+
4898
+ GetDeclRef (D);
4899
+ }
4900
+
4901
+ if (GeneratingReducedBMI)
4902
+ return ;
4903
+
4885
4904
// Writing all of the tentative definitions in this file, in
4886
4905
// TentativeDefinitions order. Generally, this record will be empty for
4887
4906
// headers.
@@ -4943,22 +4962,6 @@ void ASTWriter::PrepareWritingSpecialDecls(Sema &SemaRef) {
4943
4962
SemaRef.getMismatchingDeleteExpressions ())
4944
4963
GetDeclRef (DeleteExprsInfo.first );
4945
4964
4946
- const TranslationUnitDecl *TU = Context.getTranslationUnitDecl ();
4947
-
4948
- // Force all top level declarations to be emitted.
4949
- //
4950
- // We start emitting top level declarations from the module purview to
4951
- // implement the eliding unreachable declaration feature.
4952
- for (const auto *D : TU->noload_decls ()) {
4953
- if (D->isFromASTFile ())
4954
- continue ;
4955
-
4956
- if (GeneratingReducedBMI && D->isFromExplicitGlobalModule ())
4957
- continue ;
4958
-
4959
- GetDeclRef (D);
4960
- }
4961
-
4962
4965
// Make sure visible decls, added to DeclContexts previously loaded from
4963
4966
// an AST file, are registered for serialization. Likewise for template
4964
4967
// specializations added to imported templates.
@@ -5001,46 +5004,54 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
5001
5004
5002
5005
// Write the record containing tentative definitions.
5003
5006
RecordData TentativeDefinitions;
5004
- AddLazyVectorDecls (*this , SemaRef.TentativeDefinitions , TentativeDefinitions);
5007
+ AddLazyVectorEmiitedDecls (*this , SemaRef.TentativeDefinitions ,
5008
+ TentativeDefinitions);
5005
5009
if (!TentativeDefinitions.empty ())
5006
5010
Stream.EmitRecord (TENTATIVE_DEFINITIONS, TentativeDefinitions);
5007
5011
5008
5012
// Write the record containing unused file scoped decls.
5009
5013
RecordData UnusedFileScopedDecls;
5010
5014
if (!isModule)
5011
- AddLazyVectorDecls (*this , SemaRef.UnusedFileScopedDecls ,
5012
- UnusedFileScopedDecls);
5015
+ AddLazyVectorEmiitedDecls (*this , SemaRef.UnusedFileScopedDecls ,
5016
+ UnusedFileScopedDecls);
5013
5017
if (!UnusedFileScopedDecls.empty ())
5014
5018
Stream.EmitRecord (UNUSED_FILESCOPED_DECLS, UnusedFileScopedDecls);
5015
5019
5016
5020
// Write the record containing ext_vector type names.
5017
5021
RecordData ExtVectorDecls;
5018
- AddLazyVectorDecls (*this , SemaRef.ExtVectorDecls , ExtVectorDecls);
5022
+ AddLazyVectorEmiitedDecls (*this , SemaRef.ExtVectorDecls , ExtVectorDecls);
5019
5023
if (!ExtVectorDecls.empty ())
5020
5024
Stream.EmitRecord (EXT_VECTOR_DECLS, ExtVectorDecls);
5021
5025
5022
5026
// Write the record containing VTable uses information.
5023
5027
RecordData VTableUses;
5024
5028
if (!SemaRef.VTableUses .empty ()) {
5025
5029
for (unsigned I = 0 , N = SemaRef.VTableUses .size (); I != N; ++I) {
5026
- AddDeclRef (SemaRef.VTableUses [I].first , VTableUses);
5030
+ CXXRecordDecl *D = SemaRef.VTableUses [I].first ;
5031
+ if (!wasDeclEmitted (D))
5032
+ continue ;
5033
+
5034
+ AddDeclRef (D, VTableUses);
5027
5035
AddSourceLocation (SemaRef.VTableUses [I].second , VTableUses);
5028
- VTableUses.push_back (SemaRef.VTablesUsed [SemaRef. VTableUses [I]. first ]);
5036
+ VTableUses.push_back (SemaRef.VTablesUsed [D ]);
5029
5037
}
5030
5038
Stream.EmitRecord (VTABLE_USES, VTableUses);
5031
5039
}
5032
5040
5033
5041
// Write the record containing potentially unused local typedefs.
5034
5042
RecordData UnusedLocalTypedefNameCandidates;
5035
5043
for (const TypedefNameDecl *TD : SemaRef.UnusedLocalTypedefNameCandidates )
5036
- AddDeclRef (TD, UnusedLocalTypedefNameCandidates);
5044
+ AddEmittedDeclRef (TD, UnusedLocalTypedefNameCandidates);
5037
5045
if (!UnusedLocalTypedefNameCandidates.empty ())
5038
5046
Stream.EmitRecord (UNUSED_LOCAL_TYPEDEF_NAME_CANDIDATES,
5039
5047
UnusedLocalTypedefNameCandidates);
5040
5048
5041
5049
// Write the record containing pending implicit instantiations.
5042
5050
RecordData PendingInstantiations;
5043
5051
for (const auto &I : SemaRef.PendingInstantiations ) {
5052
+ if (!wasDeclEmitted (I.first ))
5053
+ continue ;
5054
+
5044
5055
AddDeclRef (I.first , PendingInstantiations);
5045
5056
AddSourceLocation (I.second , PendingInstantiations);
5046
5057
}
@@ -5050,39 +5061,49 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
5050
5061
// Write the record containing declaration references of Sema.
5051
5062
RecordData SemaDeclRefs;
5052
5063
if (SemaRef.StdNamespace || SemaRef.StdBadAlloc || SemaRef.StdAlignValT ) {
5053
- AddDeclRef (SemaRef.getStdNamespace (), SemaDeclRefs);
5054
- AddDeclRef (SemaRef.getStdBadAlloc (), SemaDeclRefs);
5055
- AddDeclRef (SemaRef.getStdAlignValT (), SemaDeclRefs);
5064
+ auto AddEmittedDeclRefOrZero = [this , &SemaDeclRefs, &SemaRef](Decl *D) {
5065
+ if (!D || !wasDeclEmitted (D))
5066
+ SemaDeclRefs.push_back (0 );
5067
+ else
5068
+ SemaDeclRefs.push_back (getDeclID (D));
5069
+ };
5070
+
5071
+ AddEmittedDeclRefOrZero (SemaRef.getStdNamespace ());
5072
+ AddEmittedDeclRefOrZero (SemaRef.getStdBadAlloc ());
5073
+ AddEmittedDeclRefOrZero (SemaRef.getStdAlignValT ());
5056
5074
}
5057
5075
if (!SemaDeclRefs.empty ())
5058
5076
Stream.EmitRecord (SEMA_DECL_REFS, SemaDeclRefs);
5059
5077
5060
5078
// Write the record containing decls to be checked for deferred diags.
5061
5079
SmallVector<serialization::DeclID, 64 > DeclsToCheckForDeferredDiags;
5062
5080
for (auto *D : SemaRef.DeclsToCheckForDeferredDiags )
5063
- DeclsToCheckForDeferredDiags.push_back (GetDeclRef (D));
5081
+ if (wasDeclEmitted (D))
5082
+ DeclsToCheckForDeferredDiags.push_back (getDeclID (D));
5064
5083
if (!DeclsToCheckForDeferredDiags.empty ())
5065
5084
Stream.EmitRecord (DECLS_TO_CHECK_FOR_DEFERRED_DIAGS,
5066
5085
DeclsToCheckForDeferredDiags);
5067
5086
5068
5087
// Write the record containing CUDA-specific declaration references.
5069
5088
RecordData CUDASpecialDeclRefs;
5070
- if (Context.getcudaConfigureCallDecl ()) {
5071
- AddDeclRef (Context.getcudaConfigureCallDecl (), CUDASpecialDeclRefs);
5089
+ if (auto *CudaCallDecl = Context.getcudaConfigureCallDecl ();
5090
+ CudaCallDecl && wasDeclEmitted (CudaCallDecl)) {
5091
+ AddDeclRef (CudaCallDecl, CUDASpecialDeclRefs);
5072
5092
Stream.EmitRecord (CUDA_SPECIAL_DECL_REFS, CUDASpecialDeclRefs);
5073
5093
}
5074
5094
5075
5095
// Write the delegating constructors.
5076
5096
RecordData DelegatingCtorDecls;
5077
5097
if (!isModule)
5078
- AddLazyVectorDecls (*this , SemaRef.DelegatingCtorDecls , DelegatingCtorDecls);
5098
+ AddLazyVectorEmiitedDecls (*this , SemaRef.DelegatingCtorDecls ,
5099
+ DelegatingCtorDecls);
5079
5100
if (!DelegatingCtorDecls.empty ())
5080
5101
Stream.EmitRecord (DELEGATING_CTORS, DelegatingCtorDecls);
5081
5102
5082
5103
// Write the known namespaces.
5083
5104
RecordData KnownNamespaces;
5084
5105
for (const auto &I : SemaRef.KnownNamespaces ) {
5085
- if (!I.second )
5106
+ if (!I.second && wasDeclEmitted (I. first ) )
5086
5107
AddDeclRef (I.first , KnownNamespaces);
5087
5108
}
5088
5109
if (!KnownNamespaces.empty ())
@@ -5093,6 +5114,9 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
5093
5114
SmallVector<std::pair<NamedDecl *, SourceLocation>, 16 > Undefined;
5094
5115
SemaRef.getUndefinedButUsed (Undefined);
5095
5116
for (const auto &I : Undefined) {
5117
+ if (!wasDeclEmitted (I.first ))
5118
+ continue ;
5119
+
5096
5120
AddDeclRef (I.first , UndefinedButUsed);
5097
5121
AddSourceLocation (I.second , UndefinedButUsed);
5098
5122
}
@@ -5105,6 +5129,9 @@ void ASTWriter::WriteSpecialDeclRecords(Sema &SemaRef) {
5105
5129
if (!isModule) {
5106
5130
for (const auto &DeleteExprsInfo :
5107
5131
SemaRef.getMismatchingDeleteExpressions ()) {
5132
+ if (!wasDeclEmitted (DeleteExprsInfo.first ))
5133
+ continue ;
5134
+
5108
5135
AddDeclRef (DeleteExprsInfo.first , DeleteExprsToAnalyze);
5109
5136
DeleteExprsToAnalyze.push_back (DeleteExprsInfo.second .size ());
5110
5137
for (const auto &DeleteLoc : DeleteExprsInfo.second ) {
@@ -5919,6 +5946,13 @@ TypeID ASTWriter::getTypeID(QualType T) const {
5919
5946
});
5920
5947
}
5921
5948
5949
+ void ASTWriter::AddEmittedDeclRef (const Decl *D, RecordDataImpl &Record) {
5950
+ if (!wasDeclEmitted (D))
5951
+ return ;
5952
+
5953
+ Record.push_back (GetDeclRef (D));
5954
+ }
5955
+
5922
5956
void ASTWriter::AddDeclRef (const Decl *D, RecordDataImpl &Record) {
5923
5957
Record.push_back (GetDeclRef (D));
5924
5958
}
0 commit comments