[clang] 79e345f - [clang][IFS] Adds support for more decl types in clang interface stubs.
Puyan Lotfi via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 8 17:53:05 PST 2019
Author: Puyan Lotfi
Date: 2019-11-08T20:27:25-05:00
New Revision: 79e345fbcc822e914fac4838dd7a4f2ddbb5fcad
URL: https://github.com/llvm/llvm-project/commit/79e345fbcc822e914fac4838dd7a4f2ddbb5fcad
DIFF: https://github.com/llvm/llvm-project/commit/79e345fbcc822e914fac4838dd7a4f2ddbb5fcad.diff
LOG: [clang][IFS] Adds support for more decl types in clang interface stubs.
Adding support for processing the following Decls: NonTypeTemplateParmDecl,
CXXConversionDecl, UnresolvedUsingValueDecl, UsingDecl, UsingShadowDecl,
TypeAliasTemplateDecl, TypeAliasDecl, VarTemplateDecl,
VarTemplateSpecializationDecl, UsingDirectiveDecl, TemplateTemplateParmDecl,
ClassTemplatePartialSpecializationDecl, IndirectFieldDecl.
Also, this allows for processing NamedDecls that don't have an identifier and
skips over VarDecls that are dependent on template types.
Differential Revision: https://reviews.llvm.org/D69995
Added:
clang/test/InterfaceStubs/class-template-partial-specialization.cpp
clang/test/InterfaceStubs/cxx-conversion.cpp
clang/test/InterfaceStubs/indirect-field-decl.cpp
clang/test/InterfaceStubs/namespace.cpp
clang/test/InterfaceStubs/non-type-template-parm-decl.cpp
clang/test/InterfaceStubs/template-constexpr.cpp
clang/test/InterfaceStubs/template-template-parm-decl.cpp
clang/test/InterfaceStubs/trycatch.cpp
clang/test/InterfaceStubs/usings.cpp
clang/test/InterfaceStubs/var-template-specialization-decl.cpp
Modified:
clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
Removed:
################################################################################
diff --git a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
index 0b28b78de3b1..025e6eb1508f 100644
--- a/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
+++ b/clang/lib/Frontend/InterfaceStubFunctionsConsumer.cpp
@@ -182,8 +182,32 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
case Decl::Kind::Enum:
case Decl::Kind::EnumConstant:
case Decl::Kind::TemplateTypeParm:
+ case Decl::Kind::NonTypeTemplateParm:
+ case Decl::Kind::CXXConversion:
+ case Decl::Kind::UnresolvedUsingValue:
+ case Decl::Kind::Using:
+ case Decl::Kind::UsingShadow:
+ case Decl::Kind::TypeAliasTemplate:
+ case Decl::Kind::TypeAlias:
+ case Decl::Kind::VarTemplate:
+ case Decl::Kind::VarTemplateSpecialization:
+ case Decl::Kind::UsingDirective:
+ case Decl::Kind::TemplateTemplateParm:
+ case Decl::Kind::ClassTemplatePartialSpecialization:
+ case Decl::Kind::IndirectField:
return true;
- case Decl::Kind::Var:
+ case Decl::Kind::Var: {
+ // Bail on any VarDecl that either has no named symbol.
+ if (!ND->getIdentifier())
+ return true;
+ const auto *VD = cast<VarDecl>(ND);
+ // Bail on any VarDecl that is a dependent or templated type.
+ if (VD->isTemplated() || VD->getType()->isDependentType())
+ return true;
+ if (WriteNamedDecl(ND, Symbols, RDO))
+ return true;
+ break;
+ }
case Decl::Kind::ParmVar:
case Decl::Kind::CXXMethod:
case Decl::Kind::CXXConstructor:
@@ -251,14 +275,16 @@ class InterfaceStubFunctionsConsumer : public ASTConsumer {
for (const NamedDecl *ND : v.NamedDecls)
HandleNamedDecl(ND, Symbols, FromTU);
- auto writeIfsV1 =
- [this](const llvm::Triple &T, const MangledSymbols &Symbols,
- const ASTContext &context, StringRef Format,
- raw_ostream &OS) -> void {
+ auto writeIfsV1 = [this](const llvm::Triple &T,
+ const MangledSymbols &Symbols,
+ const ASTContext &context, StringRef Format,
+ raw_ostream &OS) -> void {
OS << "--- !" << Format << "\n";
OS << "IfsVersion: 1.0\n";
OS << "Triple: " << T.str() << "\n";
- OS << "ObjectFileFormat: " << "ELF" << "\n"; // TODO: For now, just ELF.
+ OS << "ObjectFileFormat: "
+ << "ELF"
+ << "\n"; // TODO: For now, just ELF.
OS << "Symbols:\n";
for (const auto &E : Symbols) {
const MangledSymbol &Symbol = E.second;
diff --git a/clang/test/InterfaceStubs/class-template-partial-specialization.cpp b/clang/test/InterfaceStubs/class-template-partial-specialization.cpp
new file mode 100644
index 000000000000..ae6e7bf2458a
--- /dev/null
+++ b/clang/test/InterfaceStubs/class-template-partial-specialization.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<typename> struct S7 { };
+template<typename T> struct S7<T&> { };
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/cxx-conversion.cpp b/clang/test/InterfaceStubs/cxx-conversion.cpp
new file mode 100644
index 000000000000..e1f7b569d59b
--- /dev/null
+++ b/clang/test/InterfaceStubs/cxx-conversion.cpp
@@ -0,0 +1,13 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<typename T> class C1 {
+ long a;
+ operator long() const { return a; }
+};
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/indirect-field-decl.cpp b/clang/test/InterfaceStubs/indirect-field-decl.cpp
new file mode 100644
index 000000000000..4bad17d70b50
--- /dev/null
+++ b/clang/test/InterfaceStubs/indirect-field-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<typename T> class C2 { union { T c; }; };
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/namespace.cpp b/clang/test/InterfaceStubs/namespace.cpp
new file mode 100644
index 000000000000..c0891a33df41
--- /dev/null
+++ b/clang/test/InterfaceStubs/namespace.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+namespace NS1 { }
+using namespace NS1;
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/non-type-template-parm-decl.cpp b/clang/test/InterfaceStubs/non-type-template-parm-decl.cpp
new file mode 100644
index 000000000000..c0bfeb90454a
--- /dev/null
+++ b/clang/test/InterfaceStubs/non-type-template-parm-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<bool T> struct S1 {};
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/template-constexpr.cpp b/clang/test/InterfaceStubs/template-constexpr.cpp
new file mode 100644
index 000000000000..770a307b8b34
--- /dev/null
+++ b/clang/test/InterfaceStubs/template-constexpr.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<typename T, T v> struct S8 { static constexpr T value = v; };
+template<typename T, T v> constexpr T S8<T, v>::value;
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/template-template-parm-decl.cpp b/clang/test/InterfaceStubs/template-template-parm-decl.cpp
new file mode 100644
index 000000000000..d9edf6b0296d
--- /dev/null
+++ b/clang/test/InterfaceStubs/template-template-parm-decl.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<template<typename...> class a> struct S6 { };
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/trycatch.cpp b/clang/test/InterfaceStubs/trycatch.cpp
new file mode 100644
index 000000000000..310e9038f1a5
--- /dev/null
+++ b/clang/test/InterfaceStubs/trycatch.cpp
@@ -0,0 +1,15 @@
+// REQUIRES: x86-registered-target
+
+// RUN: %clang -target x86_64-unknown-linux-gnu -c -o - -emit-interface-stubs %s | FileCheck %s
+
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: "_Z1fv" : { Type: Func }
+// CHECK-NEXT: ...
+
+class C5 {};
+void f() { try {} catch(C5&){} }
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/usings.cpp b/clang/test/InterfaceStubs/usings.cpp
new file mode 100644
index 000000000000..3c49fa3f3fb1
--- /dev/null
+++ b/clang/test/InterfaceStubs/usings.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: ...
+
+template<typename T> struct S2 { static unsigned f(); };
+template<typename T> struct S3 { using S2<T>::f; };
+
+typedef struct {} S4;
+using ::S4;
+
+template<typename T, T t> struct C3{};
+template<bool b> using U1 = C3<bool, b>;
\ No newline at end of file
diff --git a/clang/test/InterfaceStubs/var-template-specialization-decl.cpp b/clang/test/InterfaceStubs/var-template-specialization-decl.cpp
new file mode 100644
index 000000000000..81cc70aaee6a
--- /dev/null
+++ b/clang/test/InterfaceStubs/var-template-specialization-decl.cpp
@@ -0,0 +1,17 @@
+// REQUIRES: x86-registered-target
+// RUN: %clang -target x86_64-unknown-linux-gnu -c -o - -emit-interface-stubs %s | FileCheck %s
+
+// CHECK: --- !experimental-ifs-v1
+// CHECK-NEXT: IfsVersion: 1.0
+// CHECK-NEXT: Triple: x86_64-unknown-linux-gnu
+// CHECK-NEXT: ObjectFileFormat: ELF
+// CHECK-NEXT: Symbols:
+// CHECK-NEXT: "a" : { Type: Object, Size: 4 }
+// CHECK-NEXT: ...
+
+template<typename T, T v> struct S9 {
+ static constexpr T value = v;
+};
+template<typename T> struct S0 : public S9<bool, true> { };
+template<typename T> constexpr bool CE2 = S0<T>::value;
+int a = CE2<int>;
\ No newline at end of file
More information about the cfe-commits
mailing list