summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorRichard Trieu <rtrieu@google.com>2017-01-31 01:44:15 +0000
committerRichard Trieu <rtrieu@google.com>2017-01-31 01:44:15 +0000
commitfa3d93a148d47a60022900815c4dd4f49f9ac08c (patch)
tree9fbc7c3ce6d03d38ebb97e11566d7bd76725b3cd /clang/lib/Sema/SemaDecl.cpp
parent6c907a9bb3d16208d765fb409a30e82af5b81c11 (diff)
downloadbcm5719-llvm-fa3d93a148d47a60022900815c4dd4f49f9ac08c.tar.gz
bcm5719-llvm-fa3d93a148d47a60022900815c4dd4f49f9ac08c.zip
Add better ODR checking for modules.
When objects are imported for modules, there is a chance that a name collision will cause an ODR violation. Previously, only a small number of such violations were detected. This patch provides a stronger check based on AST nodes. The information needed to uniquely identify an object is taked from the AST and put into a one-dimensional byte stream. This stream is then hashed to give a value to represent the object, which is stored with the other object data in the module. When modules are loaded, and Decl's are merged, the hash values of the two Decl's are compared. Only Decl's with matched hash values will be merged. Mismatch hashes will generate a module error, and if possible, point to the first difference between the two objects. The transform from AST to byte stream is a modified depth first algorithm. Due to references between some AST nodes, a pure depth first algorithm could generate loops. For Stmt nodes, a straight depth first processing occurs. For Type and Decl nodes, they are replaced with an index number and only on first visit will these nodes be processed. As an optimization, boolean values are saved and stored together in reverse order at the end of the byte stream to lower the ammount of data that needs to be hashed. Compile time impact was measured at 1.5-2.0% during module building, and negligible during builds without module building. Differential Revision: https://reviews.llvm.org/D21675 llvm-svn: 293585
Diffstat (limited to 'clang/lib/Sema/SemaDecl.cpp')
-rw-r--r--clang/lib/Sema/SemaDecl.cpp5
1 files changed, 4 insertions, 1 deletions
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 60daae056b3..f65a83f4b6a 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -13705,8 +13705,11 @@ void Sema::ActOnTagFinishDefinition(Scope *S, Decl *TagD,
RD->completeDefinition();
}
- if (isa<CXXRecordDecl>(Tag))
+ if (auto *RD = dyn_cast<CXXRecordDecl>(Tag)) {
FieldCollector->FinishClass();
+ if (Context.getLangOpts().Modules)
+ RD->computeODRHash();
+ }
// Exit this scope of this tag's definition.
PopDeclContext();
OpenPOWER on IntegriCloud