diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-10-18 06:05:18 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2013-10-18 06:05:18 +0000 |
commit | 2b9e3e396a6f0b1ebd247cb204f20a319f6ae7f4 (patch) | |
tree | c93d61965532f68d891027c703eae93cb71366ed /clang/lib/Serialization/ASTReaderDecl.cpp | |
parent | 3dc4f44e71bc9d5650b2cd134ca4733438acfbfb (diff) | |
download | bcm5719-llvm-2b9e3e396a6f0b1ebd247cb204f20a319f6ae7f4.tar.gz bcm5719-llvm-2b9e3e396a6f0b1ebd247cb204f20a319f6ae7f4.zip |
Basic ODR checking for C++ modules:
If we have multiple definitions of the same entity from different modules, we
nominate the first definition which we see as being the canonical definition.
If we load a declaration from a different definition and we can't find a
corresponding declaration in the canonical definition, issue a diagnostic.
This is insufficient to prevent things from going horribly wrong in all cases
-- we might be in the middle of emitting IR for a function when we trigger some
deserialization and discover that it refers to an incoherent piece of the AST,
by which point it's probably too late to bail out -- but we'll at least produce
a diagnostic.
llvm-svn: 192950
Diffstat (limited to 'clang/lib/Serialization/ASTReaderDecl.cpp')
-rw-r--r-- | clang/lib/Serialization/ASTReaderDecl.cpp | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/clang/lib/Serialization/ASTReaderDecl.cpp b/clang/lib/Serialization/ASTReaderDecl.cpp index 14379f31167..e68c7fc6f9f 100644 --- a/clang/lib/Serialization/ASTReaderDecl.cpp +++ b/clang/lib/Serialization/ASTReaderDecl.cpp @@ -2193,6 +2193,9 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { return Result; } + // FIXME: Bail out for non-canonical declarations. We will have performed any + // necessary merging already. + DeclContext *DC = D->getDeclContext()->getRedeclContext(); if (DC->isTranslationUnit() && Reader.SemaObj) { IdentifierResolver &IdResolver = Reader.SemaObj->IdResolver; @@ -2226,17 +2229,23 @@ ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { if (isSameEntity(*I, D)) return FindExistingResult(Reader, D, *I); } - return FindExistingResult(Reader, D, /*Existing=*/0); } else if (DeclContext *MergeDC = getPrimaryContextForMerging(DC)) { DeclContext::lookup_result R = MergeDC->noload_lookup(Name); for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { if (isSameEntity(*I, D)) return FindExistingResult(Reader, D, *I); } - return FindExistingResult(Reader, D, /*Existing=*/0); + } else { + // Not in a mergeable context. + return FindExistingResult(Reader); } - return FindExistingResult(Reader); + // If this declaration is from a merged context, make a note that we need to + // check that the canonical definition of that context contains the decl. + if (Reader.MergedDeclContexts.count(D->getLexicalDeclContext())) + Reader.PendingOdrMergeChecks.push_back(D); + + return FindExistingResult(Reader, D, /*Existing=*/0); } void ASTDeclReader::attachPreviousDecl(Decl *D, Decl *previous) { |