Read/write in PCH Sema's StdNamespace and StdBadAlloc and use a LazyDeclPtr for them that will deserialize them when needed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@110031 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index a9a4f52..a42c6e8 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -127,8 +127,7 @@
Diags(PP.getDiagnostics()), SourceMgr(PP.getSourceManager()),
ExternalSource(0), CodeCompleter(CodeCompleter), CurContext(0),
PackContext(0), TopFunctionScope(0), ParsingDeclDepth(0),
- IdResolver(pp.getLangOptions()), StdNamespace(0), StdBadAlloc(0),
- GlobalNewDeleteDeclared(false),
+ IdResolver(pp.getLangOptions()), GlobalNewDeleteDeclared(false),
CompleteTranslationUnit(CompleteTranslationUnit),
NumSFINAEErrors(0), SuppressAccessChecking(false),
NonInstantiationEntries(0), CurrentInstantiationScope(0), TyposCorrected(0),
diff --git a/lib/Sema/Sema.h b/lib/Sema/Sema.h
index 336dfa3..85627b0 100644
--- a/lib/Sema/Sema.h
+++ b/lib/Sema/Sema.h
@@ -523,11 +523,11 @@
Scope *TUScope;
/// \brief The C++ "std" namespace, where the standard library resides.
- NamespaceDecl *StdNamespace;
+ LazyDeclPtr StdNamespace;
/// \brief The C++ "std::bad_alloc" class, which is defined by the C++
/// standard library.
- CXXRecordDecl *StdBadAlloc;
+ LazyDeclPtr StdBadAlloc;
/// A flag to remember whether the implicit forms of operator new and delete
/// have been declared.
@@ -2167,7 +2167,17 @@
AttributeList *AttrList);
virtual void ActOnFinishNamespaceDef(DeclPtrTy Dcl, SourceLocation RBrace);
+ NamespaceDecl *getStdNamespace() const {
+ return cast_or_null<NamespaceDecl>(
+ StdNamespace.get(Context.getExternalSource()));
+ }
NamespaceDecl *getOrCreateStdNamespace();
+
+ CXXRecordDecl *getStdBadAlloc() const {
+ return cast_or_null<CXXRecordDecl>(
+ StdBadAlloc.get(Context.getExternalSource()));
+ }
+
virtual DeclPtrTy ActOnUsingDirective(Scope *CurScope,
SourceLocation UsingLoc,
SourceLocation NamespcLoc,
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index 71572d8..8a656bc 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -5182,7 +5182,7 @@
}
if (getLangOptions().CPlusPlus && Name && DC && StdNamespace &&
- DC->Equals(StdNamespace) && Name->isStr("bad_alloc")) {
+ DC->Equals(getStdNamespace()) && Name->isStr("bad_alloc")) {
// This is a declaration of or a reference to "std::bad_alloc".
isStdBadAlloc = true;
@@ -5190,7 +5190,7 @@
// std::bad_alloc has been implicitly declared (but made invisible to
// name lookup). Fill in this implicit declaration as the previous
// declaration, so that the declarations get chained appropriately.
- Previous.addDecl(StdBadAlloc);
+ Previous.addDecl(getStdBadAlloc());
}
}
@@ -5481,7 +5481,7 @@
New = CXXRecordDecl::Create(Context, Kind, SearchDC, Loc, Name, KWLoc,
cast_or_null<CXXRecordDecl>(PrevDecl));
- if (isStdBadAlloc && (!StdBadAlloc || StdBadAlloc->isImplicit()))
+ if (isStdBadAlloc && (!StdBadAlloc || getStdBadAlloc()->isImplicit()))
StdBadAlloc = cast<CXXRecordDecl>(New);
} else
New = RecordDecl::Create(Context, Kind, SearchDC, Loc, Name, KWLoc,
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index cf6e354..a0bc584 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -3213,12 +3213,12 @@
CurContext->getLookupContext()->isTranslationUnit()) {
// This is the first "real" definition of the namespace "std", so update
// our cache of the "std" namespace to point at this definition.
- if (StdNamespace) {
+ if (NamespaceDecl *StdNS = getStdNamespace()) {
// We had already defined a dummy namespace "std". Link this new
// namespace definition to the dummy namespace "std".
- StdNamespace->setNextNamespace(Namespc);
- StdNamespace->setLocation(IdentLoc);
- Namespc->setOriginalNamespace(StdNamespace->getOriginalNamespace());
+ StdNS->setNextNamespace(Namespc);
+ StdNS->setLocation(IdentLoc);
+ Namespc->setOriginalNamespace(StdNS->getOriginalNamespace());
}
// Make our StdNamespace cache point at the first real definition of the
@@ -3320,10 +3320,10 @@
Context.getTranslationUnitDecl(),
SourceLocation(),
&PP.getIdentifierTable().get("std"));
- StdNamespace->setImplicit(true);
+ getStdNamespace()->setImplicit(true);
}
- return StdNamespace;
+ return getStdNamespace();
}
Sema::DeclPtrTy Sema::ActOnUsingDirective(Scope *S,
diff --git a/lib/Sema/SemaExprCXX.cpp b/lib/Sema/SemaExprCXX.cpp
index d607afa..8b2fc7e 100644
--- a/lib/Sema/SemaExprCXX.cpp
+++ b/lib/Sema/SemaExprCXX.cpp
@@ -343,7 +343,7 @@
IdentifierInfo *TypeInfoII = &PP.getIdentifierTable().get("type_info");
LookupResult R(*this, TypeInfoII, SourceLocation(), LookupTagName);
- LookupQualifiedName(R, StdNamespace);
+ LookupQualifiedName(R, getStdNamespace());
RecordDecl *TypeInfoRecordDecl = R.getAsSingle<RecordDecl>();
if (!TypeInfoRecordDecl)
return ExprError(Diag(OpLoc, diag::err_need_header_before_typeid));
@@ -1203,7 +1203,7 @@
SourceLocation(),
&PP.getIdentifierTable().get("bad_alloc"),
SourceLocation(), 0);
- StdBadAlloc->setImplicit(true);
+ getStdBadAlloc()->setImplicit(true);
}
GlobalNewDeleteDeclared = true;
@@ -1257,7 +1257,7 @@
Name.getCXXOverloadedOperator() == OO_Array_New);
if (HasBadAllocExceptionSpec) {
assert(StdBadAlloc && "Must have std::bad_alloc declared");
- BadAllocType = Context.getTypeDeclType(StdBadAlloc);
+ BadAllocType = Context.getTypeDeclType(getStdBadAlloc());
}
QualType FnType = Context.getFunctionType(Return, &Argument, 1, false, 0,