From d498f384d154e154e939a9c764054cd4a8d76819 Mon Sep 17 00:00:00 2001 From: Argyrios Kyrtzidis Date: Tue, 25 Sep 2012 19:26:39 +0000 Subject: [PATCH] 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 --- lib/AST/ASTImporter.cpp | 62 ++++++++++++++++++++++------------------- 1 file 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( + ToEPI.ExceptionSpecType = FromEPI.ExceptionSpecType; + ToEPI.NoexceptExpr = Importer.Import(FromEPI.NoexceptExpr); + ToEPI.ExceptionSpecDecl = cast_or_null( Importer.Import(FromEPI.ExceptionSpecDecl)); - ToEPI.ExceptionSpecTemplate = cast_or_null( + ToEPI.ExceptionSpecTemplate = cast_or_null( 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::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::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? -- 2.40.0