[llvm-branch-commits] [clang] 726de41 - [clang][AST] Add get functions for CXXFoldExpr paren locations.

2021-01-21 Thread Balázs Kéri via llvm-branch-commits

Author: Balázs Kéri
Date: 2021-01-21T14:35:42+01:00
New Revision: 726de41e2bfb1d0d65e08f103dcb12810fe99d60

URL: 
https://github.com/llvm/llvm-project/commit/726de41e2bfb1d0d65e08f103dcb12810fe99d60
DIFF: 
https://github.com/llvm/llvm-project/commit/726de41e2bfb1d0d65e08f103dcb12810fe99d60.diff

LOG: [clang][AST] Add get functions for CXXFoldExpr paren locations.

Reviewed By: hokein

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

Added: 


Modified: 
clang/include/clang/AST/ExprCXX.h

Removed: 




diff  --git a/clang/include/clang/AST/ExprCXX.h 
b/clang/include/clang/AST/ExprCXX.h
index 2656952377b3..fbeeb4004f7d 100644
--- a/clang/include/clang/AST/ExprCXX.h
+++ b/clang/include/clang/AST/ExprCXX.h
@@ -4624,6 +4624,8 @@ class CXXFoldExpr : public Expr {
   /// Get the operand that doesn't contain a pack, for a binary fold.
   Expr *getInit() const { return isLeftFold() ? getLHS() : getRHS(); }
 
+  SourceLocation getLParenLoc() const { return LParenLoc; }
+  SourceLocation getRParenLoc() const { return RParenLoc; }
   SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
   BinaryOperatorKind getOperator() const { return Opcode; }
 



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


[llvm-branch-commits] [clang] 98a8344 - [clang][ASTImporter] Add support for importing CXXFoldExpr.

2021-01-22 Thread Balázs Kéri via llvm-branch-commits

Author: Balázs Kéri
Date: 2021-01-22T15:20:55+01:00
New Revision: 98a8344895a8e1f2cfa98b664b50fb7b864afa52

URL: 
https://github.com/llvm/llvm-project/commit/98a8344895a8e1f2cfa98b664b50fb7b864afa52
DIFF: 
https://github.com/llvm/llvm-project/commit/98a8344895a8e1f2cfa98b664b50fb7b864afa52.diff

LOG: [clang][ASTImporter] Add support for importing CXXFoldExpr.

Reviewed By: shafik, martong

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 5c6aa5d3c015..085c50c0667b 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -644,6 +644,7 @@ namespace clang {
 ExpectedStmt 
VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
 ExpectedStmt VisitTypeTraitExpr(TypeTraitExpr *E);
 ExpectedStmt VisitCXXTypeidExpr(CXXTypeidExpr *E);
+ExpectedStmt VisitCXXFoldExpr(CXXFoldExpr *E);
 
 template
 Error ImportArrayChecked(IIter Ibegin, IIter Iend, OIter Obegin) {
@@ -8011,6 +8012,25 @@ ExpectedStmt 
ASTNodeImporter::VisitCXXTypeidExpr(CXXTypeidExpr *E) {
   *ToTypeOrErr, *ToExprOperandOrErr, *ToSourceRangeOrErr);
 }
 
+ExpectedStmt ASTNodeImporter::VisitCXXFoldExpr(CXXFoldExpr *E) {
+  Error Err = Error::success();
+
+  QualType ToType = importChecked(Err, E->getType());
+  UnresolvedLookupExpr *ToCallee = importChecked(Err, E->getCallee());
+  SourceLocation ToLParenLoc = importChecked(Err, E->getLParenLoc());
+  Expr *ToLHS = importChecked(Err, E->getLHS());
+  SourceLocation ToEllipsisLoc = importChecked(Err, E->getEllipsisLoc());
+  Expr *ToRHS = importChecked(Err, E->getRHS());
+  SourceLocation ToRParenLoc = importChecked(Err, E->getRParenLoc());
+
+  if (Err)
+return std::move(Err);
+
+  return new (Importer.getToContext())
+  CXXFoldExpr(ToType, ToCallee, ToLParenLoc, ToLHS, E->getOperator(),
+  ToEllipsisLoc, ToRHS, ToRParenLoc, E->getNumExpansions());
+}
+
 Error ASTNodeImporter::ImportOverriddenMethods(CXXMethodDecl *ToMethod,
CXXMethodDecl *FromMethod) {
   Error ImportErrors = Error::success();

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 8a07a5b8e0df..193523f2fc51 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -639,6 +639,38 @@ TEST_P(ImportExpr, ImportSizeOfPackExpr) {
   hasUnqualifiedDesugaredType(constantArrayType(hasSize(7));
 }
 
+const internal::VariadicDynCastAllOfMatcher cxxFoldExpr;
+
+AST_MATCHER_P(CXXFoldExpr, hasOperator, BinaryOperatorKind, Op) {
+  return Node.getOperator() == Op;
+}
+AST_MATCHER(CXXFoldExpr, hasInit) { return Node.getInit(); }
+AST_MATCHER(CXXFoldExpr, isRightFold) { return Node.isRightFold(); }
+AST_MATCHER(CXXFoldExpr, isLeftFold) { return Node.isLeftFold(); }
+
+TEST_P(ImportExpr, ImportCXXFoldExpr) {
+  auto Match1 =
+  cxxFoldExpr(hasOperator(BO_Add), isLeftFold(), unless(hasInit()));
+  auto Match2 = cxxFoldExpr(hasOperator(BO_Sub), isLeftFold(), hasInit());
+  auto Match3 =
+  cxxFoldExpr(hasOperator(BO_Mul), isRightFold(), unless(hasInit()));
+  auto Match4 = cxxFoldExpr(hasOperator(BO_Div), isRightFold(), hasInit());
+
+  MatchVerifier Verifier;
+  testImport("template "
+ "void declToImport(Ts... args) {"
+ "  const int i1 = (... + args);"
+ "  const int i2 = (1 - ... - args);"
+ "  const int i3 = (args * ...);"
+ "  const int i4 = (args / ... / 1);"
+ "};"
+ "void g() { declToImport(1, 2, 3, 4, 5); }",
+ Lang_CXX17, "", Lang_CXX17, Verifier,
+ functionTemplateDecl(hasDescendant(Match1), hasDescendant(Match2),
+  hasDescendant(Match3),
+  hasDescendant(Match4)));
+}
+
 /// \brief Matches __builtin_types_compatible_p:
 /// GNU extension to check equivalent types
 /// Given



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


[llvm-branch-commits] [clang] 0877b96 - [clang][ASTImporter] Fix a possible assertion failure `NeedsInjectedClassNameType(Decl)'.

2021-01-07 Thread Balázs Kéri via llvm-branch-commits

Author: Balázs Kéri
Date: 2021-01-07T11:28:11+01:00
New Revision: 0877b963ef2d3c384b47f7a6161c9d9ab106a7f2

URL: 
https://github.com/llvm/llvm-project/commit/0877b963ef2d3c384b47f7a6161c9d9ab106a7f2
DIFF: 
https://github.com/llvm/llvm-project/commit/0877b963ef2d3c384b47f7a6161c9d9ab106a7f2.diff

LOG: [clang][ASTImporter] Fix a possible assertion failure 
`NeedsInjectedClassNameType(Decl)'.

The assertion can happen if ASTImporter imports a CXXRecordDecl in a template
and then imports another redeclaration of this declaration, while the first 
import is in progress.
The process of first import did not set the "described template" yet
and the second import finds the first declaration at setting the injected types.
Setting the injected type requires in the assertion that the described template 
is set.
The exact assertion was:
clang/lib/AST/ASTContext.cpp:4411:
clang::QualType 
clang::ASTContext::getInjectedClassNameType(clang::CXXRecordDecl*, 
clang::QualType) const:
Assertion `NeedsInjectedClassNameType(Decl)' failed.

Reviewed By: shafik

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

Added: 


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

Removed: 




diff  --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp
index 54816b721a4a..5c6aa5d3c015 100644
--- a/clang/lib/AST/ASTImporter.cpp
+++ b/clang/lib/AST/ASTImporter.cpp
@@ -5393,16 +5393,16 @@ ExpectedDecl 
ASTNodeImporter::VisitClassTemplateDecl(ClassTemplateDecl *D) {
 
   CXXRecordDecl *FromTemplated = D->getTemplatedDecl();
 
+  auto TemplateParamsOrErr = import(D->getTemplateParameters());
+  if (!TemplateParamsOrErr)
+return TemplateParamsOrErr.takeError();
+
   // Create the declaration that is being templated.
   CXXRecordDecl *ToTemplated;
   if (Error Err = importInto(ToTemplated, FromTemplated))
 return std::move(Err);
 
   // Create the class template declaration itself.
-  auto TemplateParamsOrErr = import(D->getTemplateParameters());
-  if (!TemplateParamsOrErr)
-return TemplateParamsOrErr.takeError();
-
   ClassTemplateDecl *D2;
   if (GetImportedOrCreateDecl(D2, D, Importer.getToContext(), DC, Loc, Name,
   *TemplateParamsOrErr, ToTemplated))

diff  --git a/clang/unittests/AST/ASTImporterTest.cpp 
b/clang/unittests/AST/ASTImporterTest.cpp
index 2472fa265589..8a07a5b8e0df 100644
--- a/clang/unittests/AST/ASTImporterTest.cpp
+++ b/clang/unittests/AST/ASTImporterTest.cpp
@@ -6141,6 +6141,41 @@ TEST_P(ASTImporterOptionSpecificTestBase, 
TypedefWithAttribute) {
   EXPECT_EQ(ToAttr->getAnnotation(), "A");
 }
 
+TEST_P(ASTImporterOptionSpecificTestBase,
+   ImportOfTemplatedDeclWhenPreviousDeclHasNoDescribedTemplateSet) {
+  Decl *FromTU = getTuDecl(
+  R"(
+
+  namespace std {
+template
+class basic_stringbuf;
+  }
+  namespace std {
+class char_traits;
+template
+class basic_stringbuf;
+  }
+  namespace std {
+template
+class basic_stringbuf {};
+  }
+
+  )",
+  Lang_CXX11);
+
+  auto *From1 = FirstDeclMatcher().match(
+  FromTU,
+  classTemplateDecl(hasName("basic_stringbuf"), unless(isImplicit(;
+  auto *To1 = cast_or_null(Import(From1, Lang_CXX11));
+  EXPECT_TRUE(To1);
+
+  auto *From2 = LastDeclMatcher().match(
+  FromTU,
+  classTemplateDecl(hasName("basic_stringbuf"), unless(isImplicit(;
+  auto *To2 = cast_or_null(Import(From2, Lang_CXX11));
+  EXPECT_TRUE(To2);
+}
+
 INSTANTIATE_TEST_CASE_P(ParameterizedTests, ASTImporterLookupTableTest,
 DefaultTestValuesForRunOptions, );
 



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