r295654 - [ASTImporter] Support default argument initialization of ParmVarDecls

Aleksei Sidorin via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 20 03:57:12 PST 2017


Author: a.sidorin
Date: Mon Feb 20 05:57:12 2017
New Revision: 295654

URL: http://llvm.org/viewvc/llvm-project?rev=295654&view=rev
Log:
[ASTImporter] Support default argument initialization of ParmVarDecls

Patch by Peter Szecsi!

Differential Revision: https://reviews.llvm.org/D29612

Modified:
    cfe/trunk/lib/AST/ASTImporter.cpp
    cfe/trunk/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp
    cfe/trunk/test/ASTMerge/exprs-cpp/test.cpp

Modified: cfe/trunk/lib/AST/ASTImporter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTImporter.cpp?rev=295654&r1=295653&r2=295654&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTImporter.cpp (original)
+++ cfe/trunk/lib/AST/ASTImporter.cpp Mon Feb 20 05:57:12 2017
@@ -3859,8 +3859,27 @@ Decl *ASTNodeImporter::VisitParmVarDecl(
                                      Importer.Import(D->getInnerLocStart()),
                                             Loc, Name.getAsIdentifierInfo(),
                                             T, TInfo, D->getStorageClass(),
-                                            /*FIXME: Default argument*/nullptr);
+                                            /*DefaultArg*/ nullptr);
+
+  // Set the default argument.
   ToParm->setHasInheritedDefaultArg(D->hasInheritedDefaultArg());
+  ToParm->setKNRPromoted(D->isKNRPromoted());
+
+  Expr *ToDefArg = nullptr;
+  Expr *FromDefArg = nullptr;
+  if (D->hasUninstantiatedDefaultArg()) {
+    FromDefArg = D->getUninstantiatedDefaultArg();
+    ToDefArg = Importer.Import(FromDefArg);
+    ToParm->setUninstantiatedDefaultArg(ToDefArg);
+  } else if (D->hasUnparsedDefaultArg()) {
+    ToParm->setUnparsedDefaultArg();
+  } else if (D->hasDefaultArg()) {
+    FromDefArg = D->getDefaultArg();
+    ToDefArg = Importer.Import(FromDefArg);
+    ToParm->setDefaultArg(ToDefArg);
+  }
+  if (FromDefArg && !ToDefArg)
+    return nullptr;
 
   if (D->isUsed())
     ToParm->setIsUsed();

Modified: cfe/trunk/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp?rev=295654&r1=295653&r2=295654&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp (original)
+++ cfe/trunk/test/ASTMerge/exprs-cpp/Inputs/exprs3.cpp Mon Feb 20 05:57:12 2017
@@ -108,6 +108,10 @@ int testDefaultArg(int a = 2*2) {
   return a;
 }
 
+int testDefaultArgExpr() {
+  return testDefaultArg();
+}
+
 template <typename T> // T has TemplateTypeParmType
 void testTemplateTypeParmType(int i);
 

Modified: cfe/trunk/test/ASTMerge/exprs-cpp/test.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/ASTMerge/exprs-cpp/test.cpp?rev=295654&r1=295653&r2=295654&view=diff
==============================================================================
--- cfe/trunk/test/ASTMerge/exprs-cpp/test.cpp (original)
+++ cfe/trunk/test/ASTMerge/exprs-cpp/test.cpp Mon Feb 20 05:57:12 2017
@@ -41,5 +41,7 @@ void testImport(int *x, const S1 &cs1, S
   testScalarInit(42);
   testOffsetOf();
   testDefaultArg(12);
+  testDefaultArg();
+  testDefaultArgExpr();
   useTemplateType();
 }




More information about the cfe-commits mailing list