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

Argyrios Kyrtzidis akyrtzi at gmail.com
Fri Sep 21 18:58:07 PDT 2012


Author: akirtzidis
Date: Fri Sep 21 20:58:06 2012
New Revision: 164450

URL: http://llvm.org/viewvc/llvm-project?rev=164450&view=rev
Log:
When importing a FunctionProtoType::ExtProtoInfo, its ExceptionSpecDecl can point to the
FunctionDecl that we are importing the FunctionProtoType for, in which case we'll have
infinite recursion when importing.

Initially create a FunctionProtoType with null ExceptionSpecDecl/ExceptionSpecTemplate and
update the type in ASTNodeImporter::VisitFunctionDecl after the FunctionDecl has been created.

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=164450&r1=164449&r2=164450&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Fri Sep 21 20:58:06 2012
@@ -1482,7 +1482,9 @@
                                                         T->getExtInfo());
 }
 
-QualType ASTNodeImporter::VisitFunctionProtoType(const FunctionProtoType *T) {
+static QualType importFunctionProtoType(ASTImporter &Importer,
+                                        const FunctionProtoType *T,
+                                        bool importExceptionSpecDecls) {
   QualType ToResultType = Importer.Import(T->getResultType());
   if (ToResultType.isNull())
     return QualType();
@@ -1509,16 +1511,38 @@
     ExceptionTypes.push_back(ExceptionType);
   }
 
-  FunctionProtoType::ExtProtoInfo EPI = T->getExtProtoInfo();
-  EPI.Exceptions = ExceptionTypes.data();
-  EPI.NoexceptExpr = Importer.Import(EPI.NoexceptExpr);
-  EPI.ExceptionSpecDecl
-    = cast_or_null<FunctionDecl>(Importer.Import(EPI.ExceptionSpecDecl));
-  EPI.ExceptionSpecTemplate
-    = cast_or_null<FunctionDecl>(Importer.Import(EPI.ExceptionSpecTemplate));
-       
+  FunctionProtoType::ExtProtoInfo FromEPI = T->getExtProtoInfo();
+  FunctionProtoType::ExtProtoInfo ToEPI;
+
+  ToEPI.ExtInfo = FromEPI.ExtInfo;
+  ToEPI.Variadic = FromEPI.Variadic;
+  ToEPI.HasTrailingReturn = FromEPI.HasTrailingReturn;
+  ToEPI.TypeQuals = FromEPI.TypeQuals;
+  ToEPI.RefQualifier = FromEPI.RefQualifier;
+  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>(
+                                Importer.Import(FromEPI.ExceptionSpecDecl));
+    ToEPI.ExceptionSpecTemplate = cast_or_null<FunctionDecl>(
+                                Importer.Import(FromEPI.ExceptionSpecTemplate));
+  }
+
   return Importer.getToContext().getFunctionType(ToResultType, ArgTypes.data(),
-                                                 ArgTypes.size(), EPI);
+                                                 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) {
@@ -2577,6 +2601,16 @@
   }
   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));
+    }
+  }
+
   // FIXME: Other bits to merge?
 
   // Add this function to the lexical context.





More information about the cfe-commits mailing list