[PATCH] D109237: [clang][AST] Add support for SubstTemplateTypeParmPackType to ASTImporter

2021-09-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added inline comments.



Comment at: clang/lib/AST/ASTImporter.cpp:1493
+const SubstTemplateTypeParmPackType *T) {
+  ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0));
+  if (!ReplacedOrErr)

martong wrote:
> steakhal wrote:
> > I know it's somewhat ugly, but it gets the job done.
> > There are other instances like this already.
> It is unfortunate that we can't we import the `Type` ptr directly and we must 
> create a qualified type with meaningless qualifiers. However, we use the very 
> same methods for `VisitSubstTemplateTypeParmType` so, this is okay for now. 
> Perhaps, in a later patch it would make sense to create an `import` overload 
> that returns and `Exptected` and takes `Type*` as a param. That could 
> simplify this line and the `cast` below.
D109269 aims to address this.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109237/new/

https://reviews.llvm.org/D109237

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109237: [clang][AST] Add support for SubstTemplateTypeParmPackType to ASTImporter

2021-09-04 Thread Balázs Benics via Phabricator via cfe-commits
steakhal added a comment.

In D109237#2982674 , @shafik wrote:

> LGTM, please run the `check-lldb` before landing this since lldb can be 
> sensitive to `ASTImporter` changes and it is nice to catch regressions there 
> before landing.

The patch did not introduce new failures.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109237/new/

https://reviews.llvm.org/D109237

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D109237: [clang][AST] Add support for SubstTemplateTypeParmPackType to ASTImporter

2021-09-04 Thread Balázs Benics via Phabricator via cfe-commits
This revision was automatically updated to reflect the committed changes.
Closed by commit rGd6ca91ea4245: [clang][AST] Add support for 
SubstTemplateTypeParmPackType to ASTImporter (authored by steakhal).
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D109237/new/

https://reviews.llvm.org/D109237

Files:
  clang/lib/AST/ASTImporter.cpp
  clang/unittests/AST/ASTImporterTest.cpp


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4693,6 +4693,57 @@
   ToD2->getDeclContext(), ToD2->getTemplateParameters()->getParam(0)));
 }
 
+const AstTypeMatcher
+substTemplateTypeParmPackType;
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmPackType) 
{
+  constexpr auto Code = R"(
+template struct D {
+  template using B = int(int (*...p)(T, U));
+  template D(B*);
+};
+int f(int(int, int), int(int, int));
+
+using asd = D::B;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cpp");
+  auto *FromClass = FirstDeclMatcher().match(
+  FromTU, classTemplateSpecializationDecl());
+
+  {
+ASTContext  = FromTU->getASTContext();
+const auto *FromSubstPack = selectFirst(
+"pack", match(substTemplateTypeParmPackType().bind("pack"), FromCtx));
+
+ASSERT_TRUE(FromSubstPack);
+ASSERT_EQ(FromSubstPack->getIdentifier()->getName(), "T");
+ArrayRef FromArgPack =
+FromSubstPack->getArgumentPack().pack_elements();
+ASSERT_EQ(FromArgPack.size(), 3u);
+ASSERT_EQ(FromArgPack[0].getAsType(), FromCtx.FloatTy);
+ASSERT_EQ(FromArgPack[1].getAsType(), FromCtx.DoubleTy);
+ASSERT_EQ(FromArgPack[2].getAsType(), FromCtx.FloatTy);
+  }
+  {
+// Let's do the import.
+ClassTemplateSpecializationDecl *ToClass = Import(FromClass, Lang_CXX11);
+ASTContext  = ToClass->getASTContext();
+
+const auto *ToSubstPack = selectFirst(
+"pack", match(substTemplateTypeParmPackType().bind("pack"), ToCtx));
+
+// Check if it meets the requirements.
+ASSERT_TRUE(ToSubstPack);
+ASSERT_EQ(ToSubstPack->getIdentifier()->getName(), "T");
+ArrayRef ToArgPack =
+ToSubstPack->getArgumentPack().pack_elements();
+ASSERT_EQ(ToArgPack.size(), 3u);
+ASSERT_EQ(ToArgPack[0].getAsType(), ToCtx.FloatTy);
+ASSERT_EQ(ToArgPack[1].getAsType(), ToCtx.DoubleTy);
+ASSERT_EQ(ToArgPack[2].getAsType(), ToCtx.FloatTy);
+  }
+}
+
 struct ASTImporterLookupTableTest : ASTImporterOptionSpecificTestBase {};
 
 TEST_P(ASTImporterLookupTableTest, OneDecl) {
Index: clang/lib/AST/ASTImporter.cpp
===
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -383,6 +383,8 @@
 ExpectedType VisitTemplateTypeParmType(const TemplateTypeParmType *T);
 ExpectedType VisitSubstTemplateTypeParmType(
 const SubstTemplateTypeParmType *T);
+ExpectedType
+VisitSubstTemplateTypeParmPackType(const SubstTemplateTypeParmPackType *T);
 ExpectedType VisitTemplateSpecializationType(
 const TemplateSpecializationType *T);
 ExpectedType VisitElaboratedType(const ElaboratedType *T);
@@ -1486,6 +1488,22 @@
 Replaced, (*ToReplacementTypeOrErr).getCanonicalType());
 }
 
+ExpectedType ASTNodeImporter::VisitSubstTemplateTypeParmPackType(
+const SubstTemplateTypeParmPackType *T) {
+  ExpectedType ReplacedOrErr = import(QualType(T->getReplacedParameter(), 0));
+  if (!ReplacedOrErr)
+return ReplacedOrErr.takeError();
+  const TemplateTypeParmType *Replaced =
+  cast(ReplacedOrErr->getTypePtr());
+
+  Expected ToArgumentPack = import(T->getArgumentPack());
+  if (!ToArgumentPack)
+return ToArgumentPack.takeError();
+
+  return Importer.getToContext().getSubstTemplateTypeParmPackType(
+  Replaced, *ToArgumentPack);
+}
+
 ExpectedType ASTNodeImporter::VisitTemplateSpecializationType(
const TemplateSpecializationType *T) {
   auto ToTemplateOrErr = import(T->getTemplateName());


Index: clang/unittests/AST/ASTImporterTest.cpp
===
--- clang/unittests/AST/ASTImporterTest.cpp
+++ clang/unittests/AST/ASTImporterTest.cpp
@@ -4693,6 +4693,57 @@
   ToD2->getDeclContext(), ToD2->getTemplateParameters()->getParam(0)));
 }
 
+const AstTypeMatcher
+substTemplateTypeParmPackType;
+
+TEST_P(ASTImporterOptionSpecificTestBase, ImportSubstTemplateTypeParmPackType) {
+  constexpr auto Code = R"(
+template struct D {
+  template using B = int(int (*...p)(T, U));
+  template D(B*);
+};
+int f(int(int, int), int(int, int));
+
+using asd = D::B;
+)";
+  Decl *FromTU = getTuDecl(Code, Lang_CXX11, "input.cpp");
+  auto *FromClass =