Skip to content

Commit

Permalink
[ItaniumMangle] Correctly mangle BuiltinTemplateDecls
Browse files Browse the repository at this point in the history
A BuiltinTemplateDecl has no underlying templated decl and as such they
cannot be relied upon for mangling.  The ItaniumMangler had some bugs
here which lead to crashes.

This fixes PR28519.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@275190 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
majnemer committed Jul 12, 2016
1 parent 2f17d0a commit e063981
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/AST/ItaniumMangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -910,6 +910,8 @@ void CXXNameMangler::mangleUnscopedTemplateName(
assert(!AdditionalAbiTags &&
"template template param cannot have abi tags");
mangleTemplateParameter(TTP->getIndex());
} else if (isa<BuiltinTemplateDecl>(ND)) {
mangleUnscopedName(ND, AdditionalAbiTags);
} else {
mangleUnscopedName(ND->getTemplatedDecl(), AdditionalAbiTags);
}
Expand Down Expand Up @@ -1715,7 +1717,10 @@ void CXXNameMangler::mangleTemplatePrefix(const TemplateDecl *ND,
mangleTemplateParameter(TTP->getIndex());
} else {
manglePrefix(getEffectiveDeclContext(ND), NoFunction);
mangleUnqualifiedName(ND->getTemplatedDecl(), nullptr);
if (isa<BuiltinTemplateDecl>(ND))
mangleUnqualifiedName(ND, nullptr);
else
mangleUnqualifiedName(ND->getTemplatedDecl(), nullptr);
}

addSubstitution(ND);
Expand Down
11 changes: 11 additions & 0 deletions test/CodeGenCXX/mangle-template.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,3 +201,14 @@ namespace test14 {

int call(bool b) { return inl<void>(b); }
}

namespace std {
template <class _Tp, _Tp...> struct integer_sequence {};
}

namespace test15 {
template <int N>
__make_integer_seq<std::integer_sequence, int, N> make() {}
template __make_integer_seq<std::integer_sequence, int, 5> make<5>();
// CHECK: define weak_odr void @_ZN6test154makeILi5EEE18__make_integer_seqISt16integer_sequenceiXT_EEv(
}

0 comments on commit e063981

Please sign in to comment.