]> granicus.if.org Git - clang/commit
Add better ODR checking for modules.
authorRichard Trieu <rtrieu@google.com>
Tue, 31 Jan 2017 01:44:15 +0000 (01:44 +0000)
committerRichard Trieu <rtrieu@google.com>
Tue, 31 Jan 2017 01:44:15 +0000 (01:44 +0000)
commitbaa8d90405a1ef158229648304c09cce0fa5d8e7
tree98786014b55c90beebe72048372dc4f3914b692d
parent1db5d32248527100792078cad1026ec17d3426b4
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293585 91177308-0d34-0410-b5e6-96231b3b80d8
14 files changed:
include/clang/AST/DeclCXX.h
include/clang/AST/ODRHash.h [new file with mode: 0644]
include/clang/AST/Stmt.h
include/clang/Basic/DiagnosticSerializationKinds.td
lib/AST/CMakeLists.txt
lib/AST/DeclCXX.cpp
lib/AST/ODRHash.cpp [new file with mode: 0644]
lib/AST/StmtProfile.cpp
lib/Sema/SemaDecl.cpp
lib/Serialization/ASTReader.cpp
lib/Serialization/ASTReaderDecl.cpp
lib/Serialization/ASTWriter.cpp
test/Modules/merge-using-decls.cpp
test/Modules/odr_hash.cpp [new file with mode: 0644]