summaryrefslogtreecommitdiffstats
path: root/clang/lib/AST/ASTImporter.cpp
diff options
context:
space:
mode:
authorGabor Marton <martongabesz@gmail.com>2018-08-06 14:38:37 +0000
committerGabor Marton <martongabesz@gmail.com>2018-08-06 14:38:37 +0000
commitfe68e29f854d9ae7a2f90d04b02d2dbc507d2146 (patch)
tree3ffaac37b78de62a3cdb97ea001eadd14199d97e /clang/lib/AST/ASTImporter.cpp
parent8d53476614157bba06b14e672621cef7e7ee7497 (diff)
downloadbcm5719-llvm-fe68e29f854d9ae7a2f90d04b02d2dbc507d2146.tar.gz
bcm5719-llvm-fe68e29f854d9ae7a2f90d04b02d2dbc507d2146.zip
[ASTmporter] SourceRange-free function parameter checking for declarations
Summary: The previous code which avoided infinite recursion (because of reparsing declarations in function parameter lists) contained SourceRange dependent code which had some problems when parameter types were coming from macros. The new solution is not using macros and therefore much safer. A couple of importer problems are fixed in redis and tmux by this fix. Various unittests are included. Reviewers: a.sidorin, r.stahl, a_sidorin Reviewed By: a_sidorin Subscribers: cfe-commits, dkrupp, balazske, martong Differential Revision: https://reviews.llvm.org/D49792 Patch by Zoltan Gera! llvm-svn: 339018
Diffstat (limited to 'clang/lib/AST/ASTImporter.cpp')
-rw-r--r--clang/lib/AST/ASTImporter.cpp24
1 files changed, 15 insertions, 9 deletions
diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index b360b391063..38ad4e28931 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -1147,15 +1147,21 @@ bool ASTNodeImporter::ImportDeclParts(NamedDecl *D, DeclContext *&DC,
FunctionDecl *FunDecl;
if (isa<RecordDecl>(D) && (FunDecl = dyn_cast<FunctionDecl>(OrigDC)) &&
FunDecl->hasBody()) {
- SourceRange RecR = D->getSourceRange();
- SourceRange BodyR = FunDecl->getBody()->getSourceRange();
- // If RecordDecl is not in Body (it is a param), we bail out.
- if (RecR.isValid() && BodyR.isValid() &&
- (RecR.getBegin() < BodyR.getBegin() ||
- BodyR.getEnd() < RecR.getEnd())) {
- Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
- << D->getDeclKindName();
- return true;
+ auto getLeafPointeeType = [](const Type *T) {
+ while (T->isPointerType() || T->isArrayType()) {
+ T = T->getPointeeOrArrayElementType();
+ }
+ return T;
+ };
+ for (const ParmVarDecl *P : FunDecl->parameters()) {
+ const Type *LeafT =
+ getLeafPointeeType(P->getType().getCanonicalType().getTypePtr());
+ auto *RT = dyn_cast<RecordType>(LeafT);
+ if (RT && RT->getDecl() == D) {
+ Importer.FromDiag(D->getLocation(), diag::err_unsupported_ast_node)
+ << D->getDeclKindName();
+ return true;
+ }
}
}
OpenPOWER on IntegriCloud