[cfe-commits] r164625 - /cfe/trunk/lib/AST/ASTImporter.cpp

Argyrios Kyrtzidis akyrtzi at gmail.com
Tue Sep 25 12:26:39 PDT 2012


Author: akirtzidis
Date: Tue Sep 25 14:26:39 2012
New Revision: 164625

URL: http://llvm.org/viewvc/llvm-project?rev=164625&view=rev
Log:
Improve upon r164450 and localize the logic of updating the type of
a function decl inside the ASTNodeImporter::VisitFunctionDecl function.

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=164625&r1=164624&r2=164625&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Tue Sep 25 14:26:39 2012
@@ -1482,9 +1482,7 @@
                                                         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 @@
   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 @@
   // 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 @@
   }
   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?





More information about the cfe-commits mailing list