Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit dace804

Browse files
committedNov 26, 2017
[ASTImporter] Support TypeTraitExpr
Patch by Takafumi Kubota! Differential Revision: https://reviews.llvm.org/D39722 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@318998 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 30a844e commit dace804

File tree

2 files changed

+62
-0
lines changed

2 files changed

+62
-0
lines changed
 

‎lib/AST/ASTImporter.cpp

+21
Original file line numberDiff line numberDiff line change
@@ -291,6 +291,7 @@ namespace clang {
291291
Expr *VisitCXXDefaultInitExpr(CXXDefaultInitExpr *E);
292292
Expr *VisitCXXNamedCastExpr(CXXNamedCastExpr *E);
293293
Expr *VisitSubstNonTypeTemplateParmExpr(SubstNonTypeTemplateParmExpr *E);
294+
Expr *VisitTypeTraitExpr(TypeTraitExpr *E);
294295

295296

296297
template<typename IIter, typename OIter>
@@ -5890,6 +5891,26 @@ Expr *ASTNodeImporter::VisitSubstNonTypeTemplateParmExpr(
58905891
Replacement);
58915892
}
58925893

5894+
Expr *ASTNodeImporter::VisitTypeTraitExpr(TypeTraitExpr *E) {
5895+
QualType ToType = Importer.Import(E->getType());
5896+
if (ToType.isNull())
5897+
return nullptr;
5898+
5899+
SmallVector<TypeSourceInfo *, 4> ToArgs(E->getNumArgs());
5900+
if (ImportContainerChecked(E->getArgs(), ToArgs))
5901+
return nullptr;
5902+
5903+
// According to Sema::BuildTypeTrait(), if E is value-dependent,
5904+
// Value is always false.
5905+
bool ToValue = false;
5906+
if (!E->isValueDependent())
5907+
ToValue = E->getValue();
5908+
5909+
return TypeTraitExpr::Create(
5910+
Importer.getToContext(), ToType, Importer.Import(E->getLocStart()),
5911+
E->getTrait(), ToArgs, Importer.Import(E->getLocEnd()), ToValue);
5912+
}
5913+
58935914
void ASTNodeImporter::ImportOverrides(CXXMethodDecl *ToMethod,
58945915
CXXMethodDecl *FromMethod) {
58955916
for (auto *FromOverriddenMethod : FromMethod->overridden_methods())

‎unittests/AST/ASTImporterTest.cpp

+41
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,47 @@ TEST(ImportType, ImportPackExpansion) {
525525
declRefExpr()))))))))));
526526
}
527527

528+
/// \brief Matches __builtin_types_compatible_p:
529+
/// GNU extension to check equivalent types
530+
/// Given
531+
/// \code
532+
/// __builtin_types_compatible_p(int, int)
533+
/// \endcode
534+
// will generate TypeTraitExpr <...> 'int'
535+
const internal::VariadicDynCastAllOfMatcher<Stmt, TypeTraitExpr> typeTraitExpr;
536+
537+
TEST(ImportExpr, ImportTypeTraitExpr) {
538+
MatchVerifier<Decl> Verifier;
539+
EXPECT_TRUE(testImport("void declToImport() { "
540+
" __builtin_types_compatible_p(int, int);"
541+
"}",
542+
Lang_C, "", Lang_C, Verifier,
543+
functionDecl(
544+
hasBody(
545+
compoundStmt(
546+
has(
547+
typeTraitExpr(hasType(asString("int")))))))));
548+
}
549+
550+
TEST(ImportExpr, ImportTypeTraitExprValDep) {
551+
MatchVerifier<Decl> Verifier;
552+
EXPECT_TRUE(testImport("template<typename T> struct declToImport {"
553+
" void m() { __is_pod(T); }"
554+
"};"
555+
"void f() { declToImport<int>().m(); }",
556+
Lang_CXX11, "", Lang_CXX11, Verifier,
557+
classTemplateDecl(
558+
has(
559+
cxxRecordDecl(
560+
has(
561+
functionDecl(
562+
hasBody(
563+
compoundStmt(
564+
has(
565+
typeTraitExpr(
566+
hasType(booleanType())
567+
)))))))))));
568+
}
528569

529570
} // end namespace ast_matchers
530571
} // end namespace clang

0 commit comments

Comments
 (0)
This repository has been archived.