diff options
author | Richard Trieu <rtrieu@google.com> | 2017-12-23 00:41:01 +0000 |
---|---|---|
committer | Richard Trieu <rtrieu@google.com> | 2017-12-23 00:41:01 +0000 |
commit | e6caa26e5d1f277c620976923bf6fd58433b2c86 (patch) | |
tree | b240071434e238f24a4724c4abaa6fa2f8611171 /clang/lib/AST/ODRHash.cpp | |
parent | 50c342bf3f99c653716bd91201cc2a5189d596db (diff) | |
download | bcm5719-llvm-e6caa26e5d1f277c620976923bf6fd58433b2c86.tar.gz bcm5719-llvm-e6caa26e5d1f277c620976923bf6fd58433b2c86.zip |
[ODRHash] Support ODR violation detection in functions.
Extend the hashing to functions, which allows detection of function definition
mismatches across modules. This is a re-commit of r320230.
llvm-svn: 321395
Diffstat (limited to 'clang/lib/AST/ODRHash.cpp')
-rw-r--r-- | clang/lib/AST/ODRHash.cpp | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 0f07b6225d9..b6874e7ba42 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -466,6 +466,36 @@ void ODRHash::AddCXXRecordDecl(const CXXRecordDecl *Record) { } } +void ODRHash::AddFunctionDecl(const FunctionDecl *Function) { + assert(Function && "Expecting non-null pointer."); + + // Skip hashing these kinds of function. + if (Function->isImplicit()) return; + if (Function->isDefaulted()) return; + if (Function->isDeleted()) return; + if (!Function->hasBody()) return; + if (!Function->getBody()) return; + + // Skip functions that are specializations or in specialization context. + const DeclContext *DC = Function; + while (DC) { + if (isa<ClassTemplateSpecializationDecl>(DC)) return; + if (auto *F = dyn_cast<FunctionDecl>(DC)) + if (F->isFunctionTemplateSpecialization()) return; + DC = DC->getParent(); + } + + AddDecl(Function); + + AddQualType(Function->getReturnType()); + + ID.AddInteger(Function->param_size()); + for (auto Param : Function->parameters()) + AddSubDecl(Param); + + AddStmt(Function->getBody()); +} + void ODRHash::AddDecl(const Decl *D) { assert(D && "Expecting non-null pointer."); D = D->getCanonicalDecl(); |