Skip to content

Commit

Permalink
[ODRHash] Revert r303450 to fix buildbot
Browse files Browse the repository at this point in the history
r303450
[ODRHash] Support TemplateName and TemplateArgument



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@303459 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
Weverything committed May 19, 2017
1 parent b601d35 commit cd08076
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 192 deletions.
92 changes: 2 additions & 90 deletions lib/AST/ODRHash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,88 +110,8 @@ void ODRHash::AddNestedNameSpecifier(const NestedNameSpecifier *NNS) {
}
}

void ODRHash::AddTemplateName(TemplateName Name) {
const auto Kind = Name.getKind();
ID.AddInteger(Kind);
AddBoolean(Name.isDependent());
AddBoolean(Name.isInstantiationDependent());
switch (Kind) {
case TemplateName::Template:
AddDecl(Name.getAsTemplateDecl());
break;
case TemplateName::OverloadedTemplate: {
const auto *Storage = Name.getAsOverloadedTemplate();
ID.AddInteger(Storage->size());
for (const auto *ND : *Storage) {
AddDecl(ND);
}
break;
}
case TemplateName::QualifiedTemplate: {
const auto *QTN = Name.getAsQualifiedTemplateName();
AddNestedNameSpecifier(QTN->getQualifier());
AddBoolean(QTN->hasTemplateKeyword());
AddDecl(QTN->getDecl());
break;
}
case TemplateName::DependentTemplate: {
const auto *DTN = Name.getAsDependentTemplateName();
AddBoolean(DTN->isIdentifier());
if (DTN->isIdentifier()) {
AddIdentifierInfo(DTN->getIdentifier());
} else {
ID.AddInteger(DTN->getOperator());
}
break;
}
case TemplateName::SubstTemplateTemplateParm: {
const auto *Storage = Name.getAsSubstTemplateTemplateParm();
AddDecl(Storage->getParameter());
AddTemplateName(Storage->getReplacement());
break;
}
case TemplateName::SubstTemplateTemplateParmPack: {
const auto *Storage = Name.getAsSubstTemplateTemplateParmPack();
AddDecl(Storage->getParameterPack());
AddTemplateArgument(Storage->getArgumentPack());
break;
}
}
}

void ODRHash::AddTemplateArgument(TemplateArgument TA) {
const auto Kind = TA.getKind();
ID.AddInteger(Kind);
switch (Kind) {
case TemplateArgument::Null:
llvm_unreachable("Require valid TemplateArgument");
case TemplateArgument::Type:
AddQualType(TA.getAsType());
break;
case TemplateArgument::Declaration:
AddDecl(TA.getAsDecl());
break;
case TemplateArgument::NullPtr:
AddQualType(TA.getNullPtrType());
break;
case TemplateArgument::Integral:
TA.getAsIntegral().Profile(ID);
AddQualType(TA.getIntegralType());
break;
case TemplateArgument::Template:
case TemplateArgument::TemplateExpansion:
AddTemplateName(TA.getAsTemplateOrTemplatePattern());
break;
case TemplateArgument::Expression:
AddStmt(TA.getAsExpr());
break;
case TemplateArgument::Pack:
ID.AddInteger(TA.pack_size());
for (auto SubTA : TA.pack_elements())
AddTemplateArgument(SubTA);
break;
}
}
void ODRHash::AddTemplateName(TemplateName Name) {}
void ODRHash::AddTemplateArgument(TemplateArgument TA) {}
void ODRHash::AddTemplateParameterList(const TemplateParameterList *TPL) {}

void ODRHash::clear() {
Expand Down Expand Up @@ -572,14 +492,6 @@ class ODRTypeVisitor : public TypeVisitor<ODRTypeVisitor> {
AddQualType(T->getNamedType());
VisitTypeWithKeyword(T);
}

void VisitTemplateSpecializationType(const TemplateSpecializationType *T) {
ID.AddInteger(T->getNumArgs());
for (const auto &TA : T->template_arguments()) {
Hash.AddTemplateArgument(TA);
}
Hash.AddTemplateName(T->getTemplateName());
}
};

void ODRHash::AddType(const Type *T) {
Expand Down
102 changes: 0 additions & 102 deletions test/Modules/odr_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -866,108 +866,6 @@ S9 s9;
#endif
}

namespace TemplateArgument {
#if defined(FIRST)
template <typename ...T> struct A1 {};
struct S1 {
A1<int> x;
};
#elif defined(SECOND)
template <typename ...T> struct A1 {};
struct S1 {
A1<int, int> x;
};
#else
S1 s1;
// [email protected]:* {{'TemplateArgument::S1::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S1' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif

#if defined(FIRST)
template <typename T> struct A2 {};
struct S2 {
A2<int> x;
};
#elif defined(SECOND)
template <typename T> struct A2 {};
struct S2 {
A2<short> x;
};
#else
S2 s2;
// [email protected]:* {{'TemplateArgument::S2::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S2' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif

#if defined(FIRST)
template <typename T> struct A3 {};
struct S3 {
A3<int> x;
};
#elif defined(SECOND)
template <typename T> struct B3 {};
struct S3 {
B3<int> x;
};
#else
S3 s3;
// [email protected]:* {{'TemplateArgument::S3::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S3' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif

#if defined(FIRST)
template <typename T, T t> struct A4 {};
struct S4 {
A4<int, 5> x;
};
#elif defined(SECOND)
template <typename T, T t> struct A4 {};
struct S4 {
A4<int, 5 + 0> x;
};
#else
S4 s4;
// [email protected]:* {{'TemplateArgument::S4' has different definitions in different modules; first difference is definition in module 'SecondModule' found field 'x' with type 'A4<int, 5 + 0>'}}
// [email protected]:* {{but in 'FirstModule' found field 'x' with type 'A4<int, 5>'}}
#endif

#if defined(FIRST)
int x5;
template <int *ptr> struct A5 {};
struct S5 {
A5<nullptr> x;
};
#elif defined(SECOND)
int x5;
template <int *ptr> struct A5 {};
struct S5 {
A5<&x5> x;
};
#else
S5 s5;
// [email protected]:* {{'TemplateArgument::S5::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S5' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif

#if defined(FIRST)
int x6;
template <int *ptr> struct A6 {};
struct S6 {
A6<&x6> x;
};
#elif defined(SECOND)
int y6;
template <int *ptr> struct A6 {};
struct S6 {
A6<&y6> x;
};
#else
S6 s6;
// [email protected]:* {{'TemplateArgument::S6::x' from module 'FirstModule' is not present in definition of 'TemplateArgument::S6' in module 'SecondModule'}}
// [email protected]:* {{declaration of 'x' does not match}}
#endif
}

// Interesting cases that should not cause errors. struct S should not error
// while struct T should error at the access specifier mismatch at the end.
namespace AllDecls {
Expand Down

0 comments on commit cd08076

Please sign in to comment.