diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-02-09 02:44:08 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-02-09 02:44:08 +0000 |
commit | 4bbb8501d9db2ae72b1e39afaafa5795d67ffe03 (patch) | |
tree | 5ca821bcb0736ec33085ab5f2d6d58530ae26e94 /lib/AST/DeclBase.cpp | |
parent | 5e058eb02875530f1aed10c3417a1011744239b1 (diff) |
[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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@150137 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclBase.cpp')
-rw-r--r-- | lib/AST/DeclBase.cpp | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp index da54a44784..a507215aa8 100644 --- a/lib/AST/DeclBase.cpp +++ b/lib/AST/DeclBase.cpp @@ -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; |