aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-09-25 19:26:39 +0000
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>2012-09-25 19:26:39 +0000
commitd498f384d154e154e939a9c764054cd4a8d76819 (patch)
tree83afdb168ff47715c58363f76f46027db98afed8
parent191046d0504cec221655e9821f264f492a70f0b1 (diff)
Improve upon r164450 and localize the logic of updating the type of
a function decl inside the ASTNodeImporter::VisitFunctionDecl function. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@164625 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/AST/ASTImporter.cpp62
1 files changed, 34 insertions, 28 deletions
diff --git a/lib/AST/ASTImporter.cpp b/lib/AST/ASTImporter.cpp
index 7639493cc5..34e699496b 100644
--- a/lib/AST/ASTImporter.cpp
+++ b/lib/AST/ASTImporter.cpp
@@ -1482,9 +1482,7 @@ ASTNodeImporter::VisitFunctionNoProtoType(const FunctionNoProtoType *T) {
T->getExtInfo());
}
-static QualType importFunctionProtoType(ASTImporter &Importer,
- const FunctionProtoType *T,
- bool importExceptionSpecDecls) {
+QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
QualType ToResultType = Importer.Import(T->getResultType());
if (ToResultType.isNull())
return QualType();
@@ -1522,29 +1520,17 @@ static QualType importFunctionProtoType(ASTImporter &Importer,
ToEPI.NumExceptions = ExceptionTypes.size();
ToEPI.Exceptions = ExceptionTypes.data();
ToEPI.ConsumedArguments = FromEPI.ConsumedArguments;
-
- if (importExceptionSpecDecls) {
- ToEPI.ExceptionSpecType = FromEPI.ExceptionSpecType;
- ToEPI.NoexceptExpr = Importer.Import(FromEPI.NoexceptExpr);
- ToEPI.ExceptionSpecDecl = cast_or_null<FunctionDecl>(
+ ToEPI.ExceptionSpecType = FromEPI.ExceptionSpecType;
+ ToEPI.NoexceptExpr = Importer.Import(FromEPI.NoexceptExpr);
+ ToEPI.ExceptionSpecDecl = cast_or_null<FunctionDecl>(
Importer.Import(FromEPI.ExceptionSpecDecl));
- ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
+ ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
Importer.Import(FromEPI.ExceptionSpecTemplate));
- }
return Importer.getToContext().getFunctionType(ToResultType, ArgTypes.data(),
ArgTypes.size(), ToEPI);
}
-QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
- // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
- // FunctionDecl that we are importing this FunctionProtoType for.
- // Update it in ASTNodeImporter::VisitFunctionDecl after the FunctionDecl has
- // been created.
- return importFunctionProtoType(Importer, T,
- /*importExceptionSpecDecls=*/false);
-}
-
QualType ASTNodeImporter::VisitParenType(const ParenType *T) {
QualType ToInnerType = Importer.Import(T->getInnerType());
if (ToInnerType.isNull())
@@ -2520,8 +2506,30 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
// Import additional name location/type info.
ImportDeclarationNameLoc(D->getNameInfo(), NameInfo);
+ QualType FromTy = D->getType();
+ bool usedDifferentExceptionSpec = false;
+
+ if (const FunctionProtoType *
+ FromFPT = D->getType()->getAs<FunctionProtoType>()) {
+ FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
+ // FunctionProtoType::ExtProtoInfo's ExceptionSpecDecl can point to the
+ // FunctionDecl that we are importing the FunctionProtoType for.
+ // To avoid an infinite recursion when importing, create the FunctionDecl
+ // with a simplified function type and update it afterwards.
+ if (FromEPI.ExceptionSpecDecl || FromEPI.ExceptionSpecTemplate ||
+ FromEPI.NoexceptExpr) {
+ FunctionProtoType::ExtProtoInfo DefaultEPI;
+ FromTy = Importer.getFromContext().getFunctionType(
+ FromFPT->getResultType(),
+ FromFPT->arg_type_begin(),
+ FromFPT->arg_type_end() - FromFPT->arg_type_begin(),
+ DefaultEPI);
+ usedDifferentExceptionSpec = true;
+ }
+ }
+
// Import the type.
- QualType T = Importer.Import(D->getType());
+ QualType T = Importer.Import(FromTy);
if (T.isNull())
return 0;
@@ -2601,14 +2609,12 @@ Decl *ASTNodeImporter::VisitFunctionDecl(FunctionDecl *D) {
}
ToFunction->setParams(Parameters);
- // Update FunctionProtoType::ExtProtoInfo.
- if (const FunctionProtoType *
- FromFPT = D->getType()->getAs<FunctionProtoType>()) {
- FunctionProtoType::ExtProtoInfo FromEPI = FromFPT->getExtProtoInfo();
- if (FromEPI.ExceptionSpecDecl || FromEPI.ExceptionSpecTemplate) {
- ToFunction->setType(importFunctionProtoType(Importer, FromFPT,
- /*importExceptionSpecDecls=*/true));
- }
+ if (usedDifferentExceptionSpec) {
+ // Update FunctionProtoType::ExtProtoInfo.
+ QualType T = Importer.Import(D->getType());
+ if (T.isNull())
+ return 0;
+ ToFunction->setType(T);
}
// FIXME: Other bits to merge?