forked from OSchip/llvm-project
[PCH] Avoid using Decl::setAttrs() and Decl::setLexicalDeclContext() from the ASTReaderDecl
directly; they internally call Decl::getASTContext() which may crash if a declaration context parent is still deserializing. llvm-svn: 150137
This commit is contained in:
parent
fbf19a0eb1
commit
6f40eb7e56
|
@ -389,7 +389,9 @@ public:
|
|||
}
|
||||
|
||||
bool hasAttrs() const { return HasAttrs; }
|
||||
void setAttrs(const AttrVec& Attrs);
|
||||
void setAttrs(const AttrVec& Attrs) {
|
||||
return setAttrsImpl(Attrs, getASTContext());
|
||||
}
|
||||
AttrVec &getAttrs() {
|
||||
return const_cast<AttrVec&>(const_cast<const Decl*>(this)->getAttrs());
|
||||
}
|
||||
|
@ -852,6 +854,9 @@ public:
|
|||
|
||||
private:
|
||||
const Attr *getAttrsImpl() const;
|
||||
void setAttrsImpl(const AttrVec& Attrs, ASTContext &Ctx);
|
||||
void setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
|
||||
ASTContext &Ctx);
|
||||
|
||||
protected:
|
||||
ASTMutationListener *getASTMutationListener() const;
|
||||
|
|
|
@ -203,15 +203,24 @@ void Decl::setLexicalDeclContext(DeclContext *DC) {
|
|||
return;
|
||||
|
||||
if (isInSemaDC()) {
|
||||
MultipleDC *MDC = new (getASTContext()) MultipleDC();
|
||||
MDC->SemanticDC = getDeclContext();
|
||||
MDC->LexicalDC = DC;
|
||||
DeclCtx = MDC;
|
||||
setDeclContextsImpl(getDeclContext(), DC, getASTContext());
|
||||
} else {
|
||||
getMultipleDC()->LexicalDC = DC;
|
||||
}
|
||||
}
|
||||
|
||||
void Decl::setDeclContextsImpl(DeclContext *SemaDC, DeclContext *LexicalDC,
|
||||
ASTContext &Ctx) {
|
||||
if (SemaDC == LexicalDC) {
|
||||
DeclCtx = SemaDC;
|
||||
} else {
|
||||
Decl::MultipleDC *MDC = new (Ctx) Decl::MultipleDC();
|
||||
MDC->SemanticDC = SemaDC;
|
||||
MDC->LexicalDC = LexicalDC;
|
||||
DeclCtx = MDC;
|
||||
}
|
||||
}
|
||||
|
||||
bool Decl::isInAnonymousNamespace() const {
|
||||
const DeclContext *DC = getDeclContext();
|
||||
do {
|
||||
|
@ -532,10 +541,10 @@ unsigned Decl::getIdentifierNamespaceForKind(Kind DeclKind) {
|
|||
llvm_unreachable("Invalid DeclKind!");
|
||||
}
|
||||
|
||||
void Decl::setAttrs(const AttrVec &attrs) {
|
||||
void Decl::setAttrsImpl(const AttrVec &attrs, ASTContext &Ctx) {
|
||||
assert(!HasAttrs && "Decl already contains attrs.");
|
||||
|
||||
AttrVec &AttrBlank = getASTContext().getDeclAttrs(this);
|
||||
AttrVec &AttrBlank = Ctx.getDeclAttrs(this);
|
||||
assert(AttrBlank.empty() && "HasAttrs was wrong?");
|
||||
|
||||
AttrBlank = attrs;
|
||||
|
|
|
@ -324,12 +324,11 @@ void ASTDeclReader::Visit(Decl *D) {
|
|||
} else if (D->isTemplateParameter()) {
|
||||
// If we have a fully initialized template parameter, we can now
|
||||
// set its DeclContext.
|
||||
D->setDeclContext(
|
||||
cast_or_null<DeclContext>(
|
||||
Reader.GetDecl(DeclContextIDForTemplateParmDecl)));
|
||||
D->setLexicalDeclContext(
|
||||
cast_or_null<DeclContext>(
|
||||
Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl)));
|
||||
DeclContext *SemaDC = cast<DeclContext>(
|
||||
Reader.GetDecl(DeclContextIDForTemplateParmDecl));
|
||||
DeclContext *LexicalDC = cast<DeclContext>(
|
||||
Reader.GetDecl(LexicalDeclContextIDForTemplateParmDecl));
|
||||
D->setDeclContextsImpl(SemaDC, LexicalDC, Reader.getContext());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,15 +342,16 @@ void ASTDeclReader::VisitDecl(Decl *D) {
|
|||
LexicalDeclContextIDForTemplateParmDecl = ReadDeclID(Record, Idx);
|
||||
D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
|
||||
} else {
|
||||
D->setDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
|
||||
D->setLexicalDeclContext(ReadDeclAs<DeclContext>(Record, Idx));
|
||||
DeclContext *SemaDC = ReadDeclAs<DeclContext>(Record, Idx);
|
||||
DeclContext *LexicalDC = ReadDeclAs<DeclContext>(Record, Idx);
|
||||
D->setDeclContextsImpl(SemaDC, LexicalDC, Reader.getContext());
|
||||
}
|
||||
D->setLocation(Reader.ReadSourceLocation(F, RawLocation));
|
||||
D->setInvalidDecl(Record[Idx++]);
|
||||
if (Record[Idx++]) { // hasAttrs
|
||||
AttrVec Attrs;
|
||||
Reader.ReadAttributes(F, Attrs, Record, Idx);
|
||||
D->setAttrs(Attrs);
|
||||
D->setAttrsImpl(Attrs, Reader.getContext());
|
||||
}
|
||||
D->setImplicit(Record[Idx++]);
|
||||
D->setUsed(Record[Idx++]);
|
||||
|
|
Loading…
Reference in New Issue