]> granicus.if.org Git - clang/commitdiff
[ItaniumMangle] Correctly mangle BuiltinTemplateDecls
authorDavid Majnemer <david.majnemer@gmail.com>
Tue, 12 Jul 2016 16:48:17 +0000 (16:48 +0000)
committerDavid Majnemer <david.majnemer@gmail.com>
Tue, 12 Jul 2016 16:48:17 +0000 (16:48 +0000)
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

lib/AST/ItaniumMangle.cpp
test/CodeGenCXX/mangle-template.cpp

index 015e9d7214f412bfefef632030a6e272781d96fc..5a7c45594e08ba7c74636724d71cd7fde29d5f1c 100644 (file)
@@ -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);
   }
@@ -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);
index 7fa300ae237b5b9963d798b26f7b67c9950b7e5d..60481b3328f6426a1aee84fc81fd55f4592cbeac 100644 (file)
@@ -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(
+}