@@ -7741,7 +7741,10 @@ SourceLocation ASTReader::getSourceLocationForDeclID(GlobalDeclID ID) {
7741
7741
return Loc;
7742
7742
}
7743
7743
7744
- static Decl *getPredefinedDecl (ASTContext &Context, PredefinedDeclIDs ID) {
7744
+ Decl *ASTReader::getPredefinedDecl (PredefinedDeclIDs ID) {
7745
+ assert (ContextObj && " reading predefined decl without AST context" );
7746
+ ASTContext &Context = *ContextObj;
7747
+ Decl *NewLoaded = nullptr ;
7745
7748
switch (ID) {
7746
7749
case PREDEF_DECL_NULL_ID:
7747
7750
return nullptr ;
@@ -7750,54 +7753,106 @@ static Decl *getPredefinedDecl(ASTContext &Context, PredefinedDeclIDs ID) {
7750
7753
return Context.getTranslationUnitDecl ();
7751
7754
7752
7755
case PREDEF_DECL_OBJC_ID_ID:
7753
- return Context.getObjCIdDecl ();
7756
+ if (Context.ObjCIdDecl )
7757
+ return Context.ObjCIdDecl ;
7758
+ NewLoaded = Context.getObjCIdDecl ();
7759
+ break ;
7754
7760
7755
7761
case PREDEF_DECL_OBJC_SEL_ID:
7756
- return Context.getObjCSelDecl ();
7762
+ if (Context.ObjCSelDecl )
7763
+ return Context.ObjCSelDecl ;
7764
+ NewLoaded = Context.getObjCSelDecl ();
7765
+ break ;
7757
7766
7758
7767
case PREDEF_DECL_OBJC_CLASS_ID:
7759
- return Context.getObjCClassDecl ();
7768
+ if (Context.ObjCClassDecl )
7769
+ return Context.ObjCClassDecl ;
7770
+ NewLoaded = Context.getObjCClassDecl ();
7771
+ break ;
7760
7772
7761
7773
case PREDEF_DECL_OBJC_PROTOCOL_ID:
7762
- return Context.getObjCProtocolDecl ();
7774
+ if (Context.ObjCProtocolClassDecl )
7775
+ return Context.ObjCProtocolClassDecl ;
7776
+ NewLoaded = Context.getObjCProtocolDecl ();
7777
+ break ;
7763
7778
7764
7779
case PREDEF_DECL_INT_128_ID:
7765
- return Context.getInt128Decl ();
7780
+ if (Context.Int128Decl )
7781
+ return Context.Int128Decl ;
7782
+ NewLoaded = Context.getInt128Decl ();
7783
+ break ;
7766
7784
7767
7785
case PREDEF_DECL_UNSIGNED_INT_128_ID:
7768
- return Context.getUInt128Decl ();
7786
+ if (Context.UInt128Decl )
7787
+ return Context.UInt128Decl ;
7788
+ NewLoaded = Context.getUInt128Decl ();
7789
+ break ;
7769
7790
7770
7791
case PREDEF_DECL_OBJC_INSTANCETYPE_ID:
7771
- return Context.getObjCInstanceTypeDecl ();
7792
+ if (Context.ObjCInstanceTypeDecl )
7793
+ return Context.ObjCInstanceTypeDecl ;
7794
+ NewLoaded = Context.getObjCInstanceTypeDecl ();
7795
+ break ;
7772
7796
7773
7797
case PREDEF_DECL_BUILTIN_VA_LIST_ID:
7774
- return Context.getBuiltinVaListDecl ();
7798
+ if (Context.BuiltinVaListDecl )
7799
+ return Context.BuiltinVaListDecl ;
7800
+ NewLoaded = Context.getBuiltinVaListDecl ();
7801
+ break ;
7775
7802
7776
7803
case PREDEF_DECL_VA_LIST_TAG:
7777
- return Context.getVaListTagDecl ();
7804
+ if (Context.VaListTagDecl )
7805
+ return Context.VaListTagDecl ;
7806
+ NewLoaded = Context.getVaListTagDecl ();
7807
+ break ;
7778
7808
7779
7809
case PREDEF_DECL_BUILTIN_MS_VA_LIST_ID:
7780
- return Context.getBuiltinMSVaListDecl ();
7810
+ if (Context.BuiltinMSVaListDecl )
7811
+ return Context.BuiltinMSVaListDecl ;
7812
+ NewLoaded = Context.getBuiltinMSVaListDecl ();
7813
+ break ;
7781
7814
7782
7815
case PREDEF_DECL_BUILTIN_MS_GUID_ID:
7816
+ // ASTContext::getMSGuidTagDecl won't create MSGuidTagDecl conditionally.
7783
7817
return Context.getMSGuidTagDecl ();
7784
7818
7785
7819
case PREDEF_DECL_EXTERN_C_CONTEXT_ID:
7786
- return Context.getExternCContextDecl ();
7820
+ if (Context.ExternCContext )
7821
+ return Context.ExternCContext ;
7822
+ NewLoaded = Context.getExternCContextDecl ();
7823
+ break ;
7787
7824
7788
7825
case PREDEF_DECL_MAKE_INTEGER_SEQ_ID:
7789
- return Context.getMakeIntegerSeqDecl ();
7826
+ if (Context.MakeIntegerSeqDecl )
7827
+ return Context.MakeIntegerSeqDecl ;
7828
+ NewLoaded = Context.getMakeIntegerSeqDecl ();
7829
+ break ;
7790
7830
7791
7831
case PREDEF_DECL_CF_CONSTANT_STRING_ID:
7792
- return Context.getCFConstantStringDecl ();
7832
+ if (Context.CFConstantStringTypeDecl )
7833
+ return Context.CFConstantStringTypeDecl ;
7834
+ NewLoaded = Context.getCFConstantStringDecl ();
7835
+ break ;
7793
7836
7794
7837
case PREDEF_DECL_CF_CONSTANT_STRING_TAG_ID:
7795
- return Context.getCFConstantStringTagDecl ();
7838
+ if (Context.CFConstantStringTagDecl )
7839
+ return Context.CFConstantStringTagDecl ;
7840
+ NewLoaded = Context.getCFConstantStringTagDecl ();
7841
+ break ;
7796
7842
7797
7843
case PREDEF_DECL_TYPE_PACK_ELEMENT_ID:
7798
- return Context.getTypePackElementDecl ();
7844
+ if (Context.TypePackElementDecl )
7845
+ return Context.TypePackElementDecl ;
7846
+ NewLoaded = Context.getTypePackElementDecl ();
7847
+ break ;
7799
7848
}
7800
- llvm_unreachable (" PredefinedDeclIDs unknown enum value" );
7849
+
7850
+ assert (NewLoaded && " Failed to load predefined decl?" );
7851
+
7852
+ if (DeserializationListener)
7853
+ DeserializationListener->PredefinedDeclBuilt (ID, NewLoaded);
7854
+
7855
+ return NewLoaded;
7801
7856
}
7802
7857
7803
7858
unsigned ASTReader::translateGlobalDeclIDToIndex (GlobalDeclID GlobalID) const {
@@ -7814,7 +7869,7 @@ Decl *ASTReader::GetExistingDecl(GlobalDeclID ID) {
7814
7869
assert (ContextObj && " reading decl with no AST context" );
7815
7870
7816
7871
if (ID < NUM_PREDEF_DECL_IDS) {
7817
- Decl *D = getPredefinedDecl (*ContextObj, (PredefinedDeclIDs)ID);
7872
+ Decl *D = getPredefinedDecl ((PredefinedDeclIDs)ID);
7818
7873
if (D) {
7819
7874
// Track that we have merged the declaration with ID \p ID into the
7820
7875
// pre-existing predefined declaration \p D.
0 commit comments