]> granicus.if.org Git - clang/commit
If a declaration is loaded, and then a module import adds a redeclaration, then
authorRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 16 May 2014 23:01:30 +0000 (23:01 +0000)
committerRichard Smith <richard-llvm@metafoo.co.uk>
Fri, 16 May 2014 23:01:30 +0000 (23:01 +0000)
commit3ad9bfabb64f758b5166353d978f18891c4e4a7f
treeb66f75ae8ff18581e9af97cc043fde52c53edbbc
parentdb597e2297f8e1b204959deca03e0466147cc0d1
If a declaration is loaded, and then a module import adds a redeclaration, then
ensure that querying the first declaration for its most recent declaration
checks for redeclarations from the imported module.

This works as follows:
 * The 'most recent' pointer on a canonical declaration grows a pointer to the
   external AST source and a generation number (space- and time-optimized for
   the case where there is no external source).
 * Each time the 'most recent' pointer is queried, if it has an external source,
   we check whether it's up to date, and update it if not.
 * The ancillary data stored on the canonical declaration is allocated lazily
   to avoid filling it in for declarations that end up being non-canonical.
   We'll still perform a redundant (ASTContext) allocation if someone asks for
   the most recent declaration from a decl before setPreviousDecl is called,
   but such cases are probably all bugs, and are now easy to find.

Some finessing is still in order here -- in particular, we use a very general
mechanism for handling the DefinitionData pointer on CXXRecordData, and a more
targeted approach would be more compact.

Also, the MayHaveOutOfDateDef mechanism should now be expunged, since it was
addressing only a corner of the full problem space here. That's not covered
by this patch.

Early performance benchmarks show that this makes no measurable difference to
Clang performance without modules enabled (and fixes a major correctness issue
with modules enabled). I'll revert if a full performance comparison shows any
problems.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@209046 91177308-0d34-0410-b5e6-96231b3b80d8
27 files changed:
include/clang/AST/ASTContext.h
include/clang/AST/Decl.h
include/clang/AST/DeclCXX.h
include/clang/AST/DeclObjC.h
include/clang/AST/DeclTemplate.h
include/clang/AST/ExternalASTSource.h
include/clang/AST/Redeclarable.h
include/clang/Sema/MultiplexExternalSemaSource.h
include/clang/Serialization/ASTReader.h
lib/AST/ASTContext.cpp
lib/AST/Decl.cpp
lib/AST/DeclCXX.cpp
lib/AST/DeclObjC.cpp
lib/AST/DeclTemplate.cpp
lib/AST/ExternalASTSource.cpp
lib/CodeGen/CGBlocks.cpp
lib/CodeGen/CGDeclCXX.cpp
lib/CodeGen/CGObjC.cpp
lib/Frontend/FrontendAction.cpp
lib/Sema/MultiplexExternalSemaSource.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriter.cpp
test/Modules/Inputs/module.map
test/Modules/Inputs/redecl-add-after-load.h [new file with mode: 0644]
test/Modules/decldef.mm
test/Modules/redecl-add-after-load.cpp [new file with mode: 0644]