[PATCH] D58586: Clear TimerGroup to avoid redundant profile results

2019-02-23 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 created this revision.
tk1012 added a project: clang.
Herald added a subscriber: cfe-commits.

This patch clears out all timers just after printing all timers.


Repository:
  rC Clang

https://reviews.llvm.org/D58586

Files:
  clang/tools/driver/cc1_main.cpp
  clang/tools/driver/cc1as_main.cpp


Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -590,6 +590,7 @@
   // If any timers were active but haven't been destroyed yet, print their
   // results now.
   TimerGroup::printAll(errs());
+  TimerGroup::clearAll();
 
   return !!Failed;
 }
Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -220,6 +220,7 @@
   // If any timers were active but haven't been destroyed yet, print their
   // results now.  This happens in -disable-free mode.
   llvm::TimerGroup::printAll(llvm::errs());
+  llvm::TimerGroup::clearAll();
 
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any


Index: clang/tools/driver/cc1as_main.cpp
===
--- clang/tools/driver/cc1as_main.cpp
+++ clang/tools/driver/cc1as_main.cpp
@@ -590,6 +590,7 @@
   // If any timers were active but haven't been destroyed yet, print their
   // results now.
   TimerGroup::printAll(errs());
+  TimerGroup::clearAll();
 
   return !!Failed;
 }
Index: clang/tools/driver/cc1_main.cpp
===
--- clang/tools/driver/cc1_main.cpp
+++ clang/tools/driver/cc1_main.cpp
@@ -220,6 +220,7 @@
   // If any timers were active but haven't been destroyed yet, print their
   // results now.  This happens in -disable-free mode.
   llvm::TimerGroup::printAll(llvm::errs());
+  llvm::TimerGroup::clearAll();
 
   // Our error handler depends on the Diagnostics object, which we're
   // potentially about to delete. Uninstall the handler now so that any
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 124057.
tk1012 added a comment.

Hello there,

I update the diff, reflecting the comments.

Updates:

1. Use ImportContainerChecked() for importing TypeSourceInfo.
2. Modify `bool ToValue = (...) ? ... : false;`.
3. Add a test case for the value-dependent `TypeTraitExpr`.




https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,46 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); };"
+ "};",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ classTemplateDecl(
+   has(
+ cxxRecordDecl(
+   has(
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(
+   hasType(asString("_Bool"))
+   )));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,26 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgs(E->getNumArgs());
+  if (ImportContainerChecked(E->getArgs(), ToArgs))
+return nullptr;
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = false;
+  if (!E->isValueDependent())
+ToValue = E->getValue();
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,46 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); };"
+ 

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-23 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 124124.
tk1012 added a comment.

Hello there,

I update the diff and add `void f() { declToImport().m(); }` after 
`declToImport` definition.
I leave the matcher for private in the test file, so I don't update the 
documentation.


https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); };"
+ "};"
+ "void f() { declToImport().m(); }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ classTemplateDecl(
+   has(
+ cxxRecordDecl(
+   has(
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(
+   hasType(asString("_Bool"))
+   )));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,26 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgs(E->getNumArgs());
+  if (ImportContainerChecked(E->getArgs(), ToArgs))
+return nullptr;
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = false;
+  if (!E->isValueDependent())
+ToValue = E->getValue();
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __i

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-24 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 124232.
tk1012 added a comment.

Hello Aaron,

I remove the semicolon.

> Is this type actually correct for C++?

Yes, it is.
clang generates the AST for `declToImport` struct like this.

  |-CXXRecordDecl 0x8b19fe0  col:29 implicit struct declToImport
  `-CXXMethodDecl 0x8b1a0d0  col:8 m 'void (void)'
`-CompoundStmt 0x8b1a1e8 
  `-TypeTraitExpr 0x8b1a1c8  '_Bool'




https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); }"
+ "};"
+ "void f() { declToImport().m(); }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ classTemplateDecl(
+   has(
+ cxxRecordDecl(
+   has(
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(
+   hasType(asString("_Bool"))
+   )));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,26 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgs(E->getNumArgs());
+  if (ImportContainerChecked(E->getArgs(), ToArgs))
+return nullptr;
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = false;
+  if (!E->isValueDependent())
+ToValue = E->getValue();
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTr

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-26 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 124286.
tk1012 added a comment.

Hello there,

I update the diff to follow your comments.


https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); }"
+ "};"
+ "void f() { declToImport().m(); }",
+ Lang_CXX11, "", Lang_CXX11, Verifier,
+ classTemplateDecl(
+   has(
+ cxxRecordDecl(
+   has(
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(
+   hasType(booleanType())
+   )));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,26 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgs(E->getNumArgs());
+  if (ImportContainerChecked(E->getArgs(), ToArgs))
+return nullptr;
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = false;
+  if (!E->isValueDependent())
+ToValue = E->getValue();
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,47 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
+
+TEST(ImportExpr, ImportTypeTraitExprValDep) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("template struct declToImport {"
+ "  void m() { __is_pod(T); }"
+ "};"
+ "void f() { declToImport().m(); }",
+ Lang_CXX11, "

[PATCH] D39722: [ASTImporter] Support Import TypeTraitExpr

2017-11-07 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 created this revision.
Herald added a subscriber: klimek.

This fixes unsupporting of importing TypeTraitExpr in ASTImporter.
TypeTraitExpr is caused by "__builtin_types_compatible_p()" that is usually 
used in the assertion in C code.
For example, PostgreSQL uses the builtin function in its assertion, and 
ASTImporter currently fails to import the assertion because of 
diag::err_unsupported_ast_node.


https://reviews.llvm.org/D39722

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -485,6 +485,16 @@
has(atomicType()));
 }
 
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { 
__builtin_types_compatible_p(int, int); }",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr()));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -280,6 +280,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5529,6 +5530,27 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for(auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+ToArgVec.push_back(ToTI);
+  }
+  ArrayRef ToArgRef(ToArgVec);
+
+  return TypeTraitExpr::Create( Importer.getToContext(),
+ ToType,
+ Importer.Import(E->getLocStart()),
+ E->getTrait(),
+ ToArgRef,
+ Importer.Import(E->getLocEnd()),
+ E->getValue());
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2239,6 +2239,17 @@
 2, std::numeric_limits::max()>
 allOf = {internal::DynTypedMatcher::VO_AllOf};
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher<
+  Stmt,
+  TypeTraitExpr> typeTraitExpr;
+
 /// \brief Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
 ///
 /// Given


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -485,6 +485,16 @@
has(atomicType()));
 }
 
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { __builtin_types_compatible_p(int, int); }",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr()));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -280,6 +280,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5529,6 +5530,27 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for(auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+ToArgVec.push_back(ToTI);

[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-09 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 created this revision.

This patch fixes wrong conflict detections for unnamed structures.
Current ASTImporter mistakenly identifies two different unnamed structs as the 
same one.
This is because ASTImporter checks the name of each RecordDecl for the conflict 
identification and the both of them have the same "unnamed" name.
To avoid this, this patch skips the confliction check if SearchName is the null 
string and also adds a tase case.


https://reviews.llvm.org/D39886

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -485,6 +485,36 @@
has(atomicType()));
 }
 
+TEST(ImportDecl, ImportUnnamedRecordDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "void declToImport() {"
+  "  struct Root {"
+  "struct { int a; } A;"
+  "struct { float b; } B;"
+  "  } root;"
+  "}",
+  Lang_C, "", Lang_C, Verifier,
+  functionDecl(
+hasBody(
+  compoundStmt(
+has(
+declStmt(
+  has(
+recordDecl(
+  has(
+recordDecl(
+  has(
+fieldDecl(
+  hasType(asString("int")),
+  has(
+recordDecl(
+  has(
+fieldDecl(
+  hasType(asString("float"))
+  );
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1631,7 +1631,7 @@
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *AdoptDecl = nullptr;
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod()) {
+  if (!DC->isFunctionOrMethod() && SearchName.getAsString() != "") {
 SmallVector ConflictingDecls;
 SmallVector FoundDecls;
 DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -485,6 +485,36 @@
has(atomicType()));
 }
 
+TEST(ImportDecl, ImportUnnamedRecordDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "void declToImport() {"
+  "  struct Root {"
+  "struct { int a; } A;"
+  "struct { float b; } B;"
+  "  } root;"
+  "}",
+  Lang_C, "", Lang_C, Verifier,
+  functionDecl(
+hasBody(
+  compoundStmt(
+has(
+declStmt(
+  has(
+recordDecl(
+  has(
+recordDecl(
+  has(
+fieldDecl(
+  hasType(asString("int")),
+  has(
+recordDecl(
+  has(
+fieldDecl(
+  hasType(asString("float"))
+  );
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1631,7 +1631,7 @@
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *AdoptDecl = nullptr;
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod()) {
+  if (!DC->isFunctionOrMethod() && SearchName.getAsString() != "") {
 SmallVector ConflictingDecls;
 SmallVector FoundDecls;
 DC->getRedeclContext()->localUncachedLookup(SearchName, FoundDecls);
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-13 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.






Comment at: lib/AST/ASTImporter.cpp:1634
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod()) {
+  if (!DC->isFunctionOrMethod() && SearchName.getAsString() != "") {
 SmallVector ConflictingDecls;

According to include/clang/AST/Decl.h file, we cannot use 
"RecordDecl::isAnonymousStructOrUnion()" here because "struct { int a; } A;" is 
not an anonymous struct but is unnamed.


https://reviews.llvm.org/D39886



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-13 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.

Hallo Aleksei and Gábor,

Thank you for your response.

> 1. Are import conflicts for anonymous structures resolved correctly?

In fact, this patch only fixes the unnamed structures that are not anonymous.

In https://reviews.llvm.org/D39886#923188, @tk1012 wrote:

>


I added an inline comment

> 2. Are equal structures present in both TUs imported correctly, without 
> duplication?

As far as my experience, ASTImporter cannot import without duplication when the 
same structure definition exists in the both TUs ( e.g. include the same header 
file).
Then, in some cases ( e.g. using ICmpExpr for the imported structures), LLVM 
asserts and fails in the compilation.

First, I think this situation is not considered in the usage of ASTImporter ( I 
mean ASTImporter assumes that one structure is defined only once).
But, is this not correct?

In any case, I will check both things and try to test them.


https://reviews.llvm.org/D39886



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 123493.
tk1012 added a comment.
Herald added a subscriber: rnkovacs.

Hello,

I update the diff to solve the below thing.

> 1. Are import conflicts for anonymous structures resolved correctly?

Before I describe the updates, I want to detail the difference between unnamed 
structs and anonymous structs in clang.
According to the comment of RecordDecl::isAnonymousStructOrUnion in 
include/AST/Decl.h, 
there are unnamed structures that are not anonymous.
For example,

  union { int i; float f; } obj;
  struct { int a } A;

both of them are not anonymous but unnamed.

Originally, the anonymous structs/unions are checked by making sure that they 
occur in the same location.
However, the unnamed structures that are not anonymous are only checked by 
their name.
This results in the different unnamed structures are identified as the same one 
because their names are the null string.

So, this update makes the skip of the confliction check more strictly. 
It also adds a test for importing the anonymous unions

>   Are equal structures present in both TUs imported correctly, without 
> duplication?

I think this is a more complicated problem because this does not depend on the 
structures are unnamed or not. 
For example, I try the below test and "make check-clang" fails due to "the 
Multiple declarations were found!".

  TEST(ImportDecl, ImportSameRecordDecl) {
MatchVerifier Verifier;
EXPECT_TRUE(
  testImport(
"struct A {"
" int a;"
"};",
Lang_C,
"struct A {"
" int a;"
"};",
Lang_C, Verifier,
recordDecl()));
  }

struct A is not anonymous and also not unnamed.

To avoid this, in my application, I check the same structure already exists in 
the "To" ASTContext before the import.
If the same struct is found, I map the "From" RecordDecl to the "To" one in 
advance.
However, I'm not sure I should request the review of this solution. ( I mean, 
should ASTImporter support this ?)
Even if I should, I think this feature must be in a different patch.

Best regards


https://reviews.llvm.org/D39886

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -485,6 +485,65 @@
has(atomicType()));
 }
 
+TEST(ImportDecl, ImportUnnamedRecordDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "void declToImport() {"
+  "  struct Root {"
+  "struct { int a; } A;"
+  "struct { float b; } B;"
+  "  } root;"
+  "}",
+  Lang_C, "", Lang_C, Verifier,
+  functionDecl(
+hasBody(
+  compoundStmt(
+has(
+  declStmt(
+has(
+  recordDecl(
+has(
+  recordDecl(
+has(
+  fieldDecl(
+hasType(asString("int")),
+has(
+  recordDecl(
+has(
+  fieldDecl(
+hasType(asString("float"))
+);
+}
+
+TEST(ImportDecl, ImportAnonymousRecordDecl) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(
+testImport(
+  "void declToImport() {"
+  "  struct Root {"
+  "union { char a;};"
+  "union { int b;};"
+  "  } root;"
+  "}",
+  Lang_C, "", Lang_C, Verifier,
+  functionDecl(
+hasBody(
+  compoundStmt(
+has(
+  declStmt(
+has(
+  recordDecl(
+has(
+  recordDecl(
+has(
+  fieldDecl(hasType(asString("char")),
+has(
+  recordDecl(
+has(
+  fieldDecl(hasType(asString("int"))
+);
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -1631,7 +1631,12 @@
   // We may already have a record of the same name; try to find and match it.
   RecordDecl *AdoptDecl = nullptr;
   RecordDecl *PrevDecl = nullptr;
-  if (!DC->isFunctionOrMethod()) {
+
+  // There are unnamed structures that are not anonymous.
+  // They cause wrong conflict detections due to the null string name.
+  bool isNotAnonymousButUnnamed = 

[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 marked an inline comment as done.
tk1012 added a comment.

Fix the broken indentation.


https://reviews.llvm.org/D39886



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added inline comments.



Comment at: lib/AST/ASTImporter.cpp:1665
   // they occur in the same location in the context records.
   if (Optional Index1 =
   StructuralEquivalenceContext::findUntaggedStructOrUnionIndex(

Anonymous structs/unions are checked here.


https://reviews.llvm.org/D39886



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 123539.
tk1012 added a comment.
Herald added a subscriber: rnkovacs.

Hello, Aleksei.

I'm sorry for the long response time.
I update the diff to follow your comments.

Updates

1. I apply clang-format -style=llvm to ASTMatchers.h and ASTImporter.cpp. I 
don't apply it to ASTImporterTest.cpp for readability of the matching types.
2. I add `return nullptr;` if `ToTI` is `nullptr`.
3. I directly pass `ToArgVec` to `TypeTraitExpr::Create()`
4. I add a check for the value-dependent of `E'.




https://reviews.llvm.org/D39722

Files:
  include/clang/ASTMatchers/ASTMatchers.h
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,16 @@
  declRefExpr()));
 }
 
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { 
__builtin_types_compatible_p(int, int); }",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr()));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+if (!ToTI)
+  return nullptr;
+ToArgVec.push_back(ToTI);
+  }
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = (!E->isValueDependent()) ? E->getValue() : false;
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgVec, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())
Index: include/clang/ASTMatchers/ASTMatchers.h
===
--- include/clang/ASTMatchers/ASTMatchers.h
+++ include/clang/ASTMatchers/ASTMatchers.h
@@ -2241,6 +2241,15 @@
 2, std::numeric_limits::max()>
 allOf;
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
 /// \brief Matches sizeof (C99), alignof (C++11) and vec_step (OpenCL)
 ///
 /// Given


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,16 @@
  declRefExpr()));
 }
 
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { __builtin_types_compatible_p(int, int); }",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr()));
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+Type

[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 marked 3 inline comments as done.
tk1012 added a comment.




https://reviews.llvm.org/D39722



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-19 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.

Description of the Sema::BuildTypeTrait()




Comment at: lib/AST/ASTImporter.cpp:5631
+  // Value is always false.
+  bool ToValue = (!E->isValueDependent()) ? E->getValue() : false;
+

According to Sema::BuildTypeTrait() in lib/Sema/SemaExprCXX.cpp, 
if an argument of TypeTraitExpr has a dependent type,
TypeTraitExpr's value (`Result`) is always false.

```
ExprResult Sema::BuildTypeTrait(TypeTrait Kind, SourceLocation KWLoc,

 bool Dependent = false;
 for (unsigned I = 0, N = Args.size(); I != N; ++I) {
   if (Args[I]->getType()->isDependentType()) {
 Dependent = true;
 break;
   }
 }

 bool Result = false;
 if (!Dependent)
   Result = evaluateTypeTrait(*this, Kind, KWLoc, Args, RParenLoc);

 return TypeTraitExpr::Create(Context, ResultType, KWLoc, Kind, Args,
  RParenLoc, Result);
...

```


https://reviews.llvm.org/D39722



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


[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-21 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.

Oh, yes.

https://reviews.llvm.org/D30876 is motivated by the same problem.

The notable difference between this patch and https://reviews.llvm.org/D30876 
is that ASTImporter should check the conflict resolution for the unnamed 
structs/unions in a record context or not.
Then, I think https://reviews.llvm.org/D30876's solution is more conservative.
In fact,  simply omitting the conflict check for all unnamed structures works 
well in my experience.
I have not hit the case where two unnamed structs have the same `Index`.
However, according to two past patches (1cef459 

 and 11ce5fe 

 ), he clearly added the anonymous structs/unions to the checking path.
So, I guess there is an example where ASTImporter has to handle them rather 
than simply skips them.
https://reviews.llvm.org/D30876 more reflects the policy of these patches.

Furthermore, I also agree with the fix of findUntaggedStructOrUnionIndex(), 
although findUntaggedStructOrUnionIndex() is not in ASTImporter.cpp anymore.
The function exists in ASTStructuralEquivalence.cpp insead.

Sorry for this redundant patch.


https://reviews.llvm.org/D39886



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


[PATCH] D39722: [ASTImporter] Support TypeTraitExpr Importing

2017-11-21 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 updated this revision to Diff 123792.
tk1012 added a comment.

Hello Gábor,

Thank you for responding.

I move the definition of the mather `typeTraitExpr` into 
unittests/AST/ASTImporterTest.cpp.
I also slightly modify the test code.


https://reviews.llvm.org/D39722

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


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,27 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+if (!ToTI)
+  return nullptr;
+ToArgVec.push_back(ToTI);
+  }
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = (!E->isValueDependent()) ? E->getValue() : false;
+
+  return TypeTraitExpr::Create(
+  Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
+  E->getTrait(), ToArgVec, Importer.Import(E->getLocEnd()), ToValue);
+}
+
 void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
   CXXMethodDecl *FromMethod) {
   for (auto *FromOverriddenMethod : FromMethod->overridden_methods())


Index: unittests/AST/ASTImporterTest.cpp
===
--- unittests/AST/ASTImporterTest.cpp
+++ unittests/AST/ASTImporterTest.cpp
@@ -525,6 +525,27 @@
  declRefExpr()));
 }
 
+/// \brief Matches __builtin_types_compatible_p:
+/// GNU extension to check equivalent types
+/// Given
+/// \code
+///   __builtin_types_compatible_p(int, int)
+/// \endcode
+//  will generate TypeTraitExpr <...> 'int'
+const internal::VariadicDynCastAllOfMatcher typeTraitExpr;
+
+TEST(ImportExpr, ImportTypeTraitExpr) {
+  MatchVerifier Verifier;
+  EXPECT_TRUE(testImport("void declToImport() { "
+ "  __builtin_types_compatible_p(int, int);"
+ "}",
+ Lang_C, "", Lang_C, Verifier,
+ functionDecl(
+   hasBody(
+ compoundStmt(
+   has(
+ typeTraitExpr(hasType(asString("int");
+}
 
 } // end namespace ast_matchers
 } // end namespace clang
Index: lib/AST/ASTImporter.cpp
===
--- lib/AST/ASTImporter.cpp
+++ lib/AST/ASTImporter.cpp
@@ -283,6 +283,7 @@
 Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
 Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
 Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
+Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
 
 
 template
@@ -5612,6 +5613,28 @@
 Replacement);
 }
 
+Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
+  QualType ToType = Importer.Import(E->getType());
+  if (ToType.isNull())
+return nullptr;
+
+  SmallVector ToArgVec;
+  for (auto FromArg : E->getArgs()) {
+TypeSourceInfo *ToTI = Importer.Import(FromArg);
+if (!ToTI)
+  return nullptr;
+ToArgVec.push_back(ToTI);
+  }
+
+  // According to Sema::BuildTypeTrait(), if E is value-dependent,
+  // Value is always false.
+  bool ToValue = (!E->isV

[PATCH] D39886: [ASTImporter] Fix wrong conflict detections for unnamed structures

2017-11-21 Thread Takafumi Kubota via Phabricator via cfe-commits
tk1012 added a comment.

Hello Aleksei,

Unfortunately, I find the related problem with the unnamed structs/unions, even 
if I apply https://reviews.llvm.org/D39886.

For example, in PostgreSQL, there is a part of code like below.

  typedef struct { int  a; } b;
  
  struct { const char *x; } y;

then, original AST becomse like below.

  -RecordDecl 0x7ac3900 ... struct definition
  | `-FieldDecl 0x7b18690 ... a 'int'
  |-TypedefDecl 0x7b18730 ... b 'struct b':'b'
  | `-ElaboratedType 0x7b186e0 'struct b' sugar
  |   `-RecordType 0x7ac3990 'b'
  | `-Record 0x7ac3900 ''
  |-RecordDecl 0x7b187a0 ... struct definition
  | `-FieldDecl 0x7b18868 ... x 'const char *'
  `-VarDecl 0x7b18900 ... y 'struct (anonymous struct at ...)':'struct 
(anonymous at ...)'

However, ASTImporter imports the AST incorrectly.
The result AST becomes

  |-RecordDecl 0x7f696c07ee50 ... struct definition
  | `-FieldDecl 0x7f696c177470 ... a 'int'
  |-TypedefDecl 0x7f696c177510 ...  b 'struct b':'b'
  | `-ElaboratedType 0x7f696c1774c0 'struct b' sugar
  |   `-RecordType 0x7f696c07eee0 'b'
  | `-Record 0x7f696c07ee50 ''
  |-RecordDecl 0x7f696c177568 prev 0x7f696c07ee50 ...  struct
  `-VarDecl 0x7f696c177660 ...  y 'struct b':'b'

The variable `y`'s type becomes `struct b` mistakenly.
This is because `FoundDecl` is set into `PrevDecl` at L1676.
In this case, `FoundDecl` is `struct { int a; }`.
Then, ASTImporter set  `PrevDecl` as a previous RecordDecl of the imported 
RecordDecl at L1772.

To avoid this, I think there are two possible solutions.

1. Like this patch, skipping conflict resolution part for the unnamed 
structs/unions.
2. Add a condition for setting the previous decl at L1676.

What do you think?
( I guess the first is unexpectedly dependable. )

p.s.
Should I also share this in https://reviews.llvm.org/D39886?




Comment at: lib/AST/ASTImporter.cpp:1676
 
 PrevDecl = FoundRecord;
 

highlight



Comment at: lib/AST/ASTImporter.cpp:1772
   // FIXME: do this for all Redeclarables, not just RecordDecls.
   D2->setPreviousDecl(PrevDecl);
 }

highlight


https://reviews.llvm.org/D39886



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