This revision was automatically updated to reflect the committed changes.
Closed by commit rGba7bde65dcff: [ASTImporter] Add support for
BuiltinTemplateDecl (authored by teemperor).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D69566/new/
https://reviews.llvm.org/D69566
Files:
clang/lib/AST/ASTImporter.cpp
clang/test/Import/builtin-template/Inputs/S.cpp
clang/test/Import/builtin-template/test.cpp
Index: clang/test/Import/builtin-template/test.cpp
===================================================================
--- /dev/null
+++ clang/test/Import/builtin-template/test.cpp
@@ -0,0 +1,30 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s
-Xcc -DSEQ | FileCheck --check-prefix=CHECK-SEQ %s
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s
-Xcc -DPACK | FileCheck --check-prefix=CHECK-PACK %s
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s
-Xcc -DPACK -Xcc -DSEQ | FileCheck --check-prefixes=CHECK-SEQ,CHECK-PACK %s
+
+// CHECK-SEQ: BuiltinTemplateDecl
+// CHECK-SEQ-SAME: <invalid sloc>
+// CHECK-SEQ-SAME: implicit
+// CHECK-SEQ-SAME: __make_integer_seq
+
+// CHECK-PACK: BuiltinTemplateDecl
+// CHECK-PACK-SAME: <invalid sloc>
+// CHECK-PACK-SAME: implicit
+// CHECK-PACK-SAME: __type_pack_element
+
+void expr() {
+#ifdef SEQ
+ typedef MakeSeq<int, 3> M1;
+ M1 m1;
+ typedef MakeSeq<long, 4> M2;
+ M2 m2;
+ static_assert(M1::PackSize == 3, "");
+ static_assert(M2::PackSize == 4, "");
+#endif
+
+#ifdef PACK
+ static_assert(__is_same(TypePackElement<0, X<0>>, X<0>), "");
+ static_assert(__is_same(TypePackElement<0, X<0>, X<1>>, X<0>), "");
+ static_assert(__is_same(TypePackElement<1, X<0>, X<1>>, X<1>), "");
+#endif
+}
Index: clang/test/Import/builtin-template/Inputs/S.cpp
===================================================================
--- /dev/null
+++ clang/test/Import/builtin-template/Inputs/S.cpp
@@ -0,0 +1,16 @@
+template <class T, T... I>
+struct Seq {
+ static constexpr T PackSize = sizeof...(I);
+};
+
+template <typename T, T N>
+using MakeSeq = __make_integer_seq<Seq, T, N>;
+
+
+using SizeT = decltype(sizeof(int));
+
+template <SizeT i, typename ...T>
+using TypePackElement = __type_pack_element<i, T...>;
+
+template <int i>
+struct X;
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -44,6 +44,7 @@
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/AST/UnresolvedSet.h"
+#include "clang/Basic/Builtins.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
@@ -483,6 +484,7 @@
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl
*D);
+ ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
Expected<ObjCTypeParamList *>
ImportObjCTypeParamList(ObjCTypeParamList *list);
@@ -4464,6 +4466,20 @@
return ToUsing;
}
+ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D)
{
+ Decl* ToD = nullptr;
+ switch (D->getBuiltinTemplateKind()) {
+ case BuiltinTemplateKind::BTK__make_integer_seq:
+ ToD = Importer.getToContext().getMakeIntegerSeqDecl();
+ break;
+ case BuiltinTemplateKind::BTK__type_pack_element:
+ ToD = Importer.getToContext().getTypePackElementDecl();
+ break;
+ }
+ assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
+ Importer.MapImported(D, ToD);
+ return ToD;
+}
Error ASTNodeImporter::ImportDefinition(
ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind)
{
Index: clang/test/Import/builtin-template/test.cpp
===================================================================
--- /dev/null
+++ clang/test/Import/builtin-template/test.cpp
@@ -0,0 +1,30 @@
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s -Xcc -DSEQ | FileCheck --check-prefix=CHECK-SEQ %s
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s -Xcc -DPACK | FileCheck --check-prefix=CHECK-PACK %s
+// RUN: clang-import-test -dump-ast -import %S/Inputs/S.cpp -expression %s -Xcc -DPACK -Xcc -DSEQ | FileCheck --check-prefixes=CHECK-SEQ,CHECK-PACK %s
+
+// CHECK-SEQ: BuiltinTemplateDecl
+// CHECK-SEQ-SAME: <invalid sloc>
+// CHECK-SEQ-SAME: implicit
+// CHECK-SEQ-SAME: __make_integer_seq
+
+// CHECK-PACK: BuiltinTemplateDecl
+// CHECK-PACK-SAME: <invalid sloc>
+// CHECK-PACK-SAME: implicit
+// CHECK-PACK-SAME: __type_pack_element
+
+void expr() {
+#ifdef SEQ
+ typedef MakeSeq<int, 3> M1;
+ M1 m1;
+ typedef MakeSeq<long, 4> M2;
+ M2 m2;
+ static_assert(M1::PackSize == 3, "");
+ static_assert(M2::PackSize == 4, "");
+#endif
+
+#ifdef PACK
+ static_assert(__is_same(TypePackElement<0, X<0>>, X<0>), "");
+ static_assert(__is_same(TypePackElement<0, X<0>, X<1>>, X<0>), "");
+ static_assert(__is_same(TypePackElement<1, X<0>, X<1>>, X<1>), "");
+#endif
+}
Index: clang/test/Import/builtin-template/Inputs/S.cpp
===================================================================
--- /dev/null
+++ clang/test/Import/builtin-template/Inputs/S.cpp
@@ -0,0 +1,16 @@
+template <class T, T... I>
+struct Seq {
+ static constexpr T PackSize = sizeof...(I);
+};
+
+template <typename T, T N>
+using MakeSeq = __make_integer_seq<Seq, T, N>;
+
+
+using SizeT = decltype(sizeof(int));
+
+template <SizeT i, typename ...T>
+using TypePackElement = __type_pack_element<i, T...>;
+
+template <int i>
+struct X;
Index: clang/lib/AST/ASTImporter.cpp
===================================================================
--- clang/lib/AST/ASTImporter.cpp
+++ clang/lib/AST/ASTImporter.cpp
@@ -44,6 +44,7 @@
#include "clang/AST/TypeLoc.h"
#include "clang/AST/TypeVisitor.h"
#include "clang/AST/UnresolvedSet.h"
+#include "clang/Basic/Builtins.h"
#include "clang/Basic/ExceptionSpecificationType.h"
#include "clang/Basic/FileManager.h"
#include "clang/Basic/IdentifierTable.h"
@@ -483,6 +484,7 @@
ExpectedDecl VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
ExpectedDecl VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
ExpectedDecl VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
+ ExpectedDecl VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
Expected<ObjCTypeParamList *>
ImportObjCTypeParamList(ObjCTypeParamList *list);
@@ -4464,6 +4466,20 @@
return ToUsing;
}
+ExpectedDecl ASTNodeImporter::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
+ Decl* ToD = nullptr;
+ switch (D->getBuiltinTemplateKind()) {
+ case BuiltinTemplateKind::BTK__make_integer_seq:
+ ToD = Importer.getToContext().getMakeIntegerSeqDecl();
+ break;
+ case BuiltinTemplateKind::BTK__type_pack_element:
+ ToD = Importer.getToContext().getTypePackElementDecl();
+ break;
+ }
+ assert(ToD && "BuiltinTemplateDecl of unsupported kind!");
+ Importer.MapImported(D, ToD);
+ return ToD;
+}
Error ASTNodeImporter::ImportDefinition(
ObjCInterfaceDecl *From, ObjCInterfaceDecl *To, ImportDefinitionKind Kind) {
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits