[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
This commit is contained in:
Puyan Lotfi 2019-11-08 20:21:28 -05:00
parent b11391bb47
commit 79e345fbcc
11 changed files with 157 additions and 6 deletions

View File

@ -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 @@ public:
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;

View File

@ -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&> { };

View File

@ -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; }
};

View File

@ -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; }; };

View File

@ -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;

View File

@ -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 {};

View File

@ -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;

View File

@ -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 { };

View File

@ -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&){} }

View File

@ -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>;

View File

@ -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>;