r186233 - [ms-cxxabi] Don't consider function templates for name backrefs

Reid Kleckner reid at kleckner.net
Fri Jul 12 17:43:39 PDT 2013


Author: rnk
Date: Fri Jul 12 19:43:39 2013
New Revision: 186233

URL: http://llvm.org/viewvc/llvm-project?rev=186233&view=rev
Log:
[ms-cxxabi] Don't consider function templates for name backrefs

They don't seem to be used for back references, presumably because a
function template is unlikely to reoccur, while a class template name
may reoccur as a type.

This fixes a mangling issue for llvm::hash_combine() in Hashing.h.

Reviewers: timurrrr

Differential Revision: http://llvm-reviews.chandlerc.com/D1078

Modified:
    cfe/trunk/lib/AST/MicrosoftMangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp
    cfe/trunk/test/CodeGenCXX/mangle-ms-back-references.cpp

Modified: cfe/trunk/lib/AST/MicrosoftMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/MicrosoftMangle.cpp?rev=186233&r1=186232&r2=186233&view=diff
==============================================================================
--- cfe/trunk/lib/AST/MicrosoftMangle.cpp (original)
+++ cfe/trunk/lib/AST/MicrosoftMangle.cpp Fri Jul 12 19:43:39 2013
@@ -421,7 +421,16 @@ MicrosoftCXXNameMangler::mangleUnqualifi
   // Check if we have a template.
   const TemplateArgumentList *TemplateArgs = 0;
   if (const TemplateDecl *TD = isTemplate(ND, TemplateArgs)) {
-    // We have a template.
+    // Function templates aren't considered for name back referencing.  This
+    // makes sense since function templates aren't likely to occur multiple
+    // times in a symbol.
+    // FIXME: Test alias template mangling with MSVC 2013.
+    if (!isa<ClassTemplateDecl>(TD)) {
+      mangleTemplateInstantiationName(TD, *TemplateArgs);
+      return;
+    }
+
+    // We have a class template.
     // Here comes the tricky thing: if we need to mangle something like
     //   void foo(A::X<Y>, B::X<Y>),
     // the X<Y> part is aliased. However, if you need to mangle

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp?rev=186233&r1=186232&r2=186233&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-back-references-pr13207.cpp Fri Jul 12 19:43:39 2013
@@ -107,7 +107,7 @@ void call_l_foo(L* l) { l->foo(I<A>());
 void foo(I<A> x) {}
 // CHECK: "\01?foo at PR13207@@YAXV?$I at VA@PR13207@@@1@@Z"
 void foo2(I<A> x, I<A> y) { }
-// CHECK "\01?foo2 at PR13207@@YAXV?$I at VA@PR13207@@@1 at 0@Z"
+// CHECK: "\01?foo2 at PR13207@@YAXV?$I at VA@PR13207@@@1 at 0@Z"
 void bar(J<A,B> x) {}
 // CHECK: "\01?bar at PR13207@@YAXV?$J at VA@PR13207@@VB at 2@@1@@Z"
 void spam(K<A,B,C> x) {}
@@ -163,3 +163,31 @@ void foobar(NC::Y<NB::Y<NA::Y<NA::X> > >
 // CHECK: "\01?foobar at NC@PR13207@@YAXV?$Y at V?$Y at V?$Y at VX@NA at PR13207@@@NA at PR13207@@@NB at PR13207@@@12@@Z"
 }
 }
+
+// Function template names are not considered for backreferencing, but normal
+// function names are.
+namespace fn_space {
+struct RetVal { int hash; };
+template <typename T>
+RetVal fun_tmpl(const T &t) { return RetVal(); }
+RetVal fun_normal(int t) { return RetVal(); }
+void fun_instantiate() {
+  fun_normal(1);
+  fun_tmpl(1);
+}
+// CHECK: "\01?fun_normal at fn_space@@YA?AURetVal at 1@H at Z"
+// CHECK: "\01??$fun_tmpl at H@fn_space@@YA?AURetVal at 0@ABH at Z"
+
+template <typename T, RetVal (*F)(T)>
+RetVal fun_tmpl_recurse(T t) {
+  if (!t)
+    return RetVal();
+  return F(t - 1);
+}
+RetVal ident(int x) { return RetVal(); }
+void fun_instantiate2() {
+  fun_tmpl_recurse<int, fun_tmpl_recurse<int, ident> >(10);
+}
+// CHECK: "\01??$fun_tmpl_recurse at H$1??$fun_tmpl_recurse at H$1?ident at fn_space@@YA?AURetVal at 2@H at Z@fn_space@@YA?AURetVal at 1@H at Z@fn_space@@YA?AURetVal at 0@H at Z"
+// CHECK: "\01??$fun_tmpl_recurse at H$1?ident at fn_space@@YA?AURetVal at 2@H at Z@fn_space@@YA?AURetVal at 0@H at Z"
+}

Modified: cfe/trunk/test/CodeGenCXX/mangle-ms-back-references.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-ms-back-references.cpp?rev=186233&r1=186232&r2=186233&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-ms-back-references.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-ms-back-references.cpp Fri Jul 12 19:43:39 2013
@@ -61,3 +61,8 @@ void h2(void (*f_ptr)(void *), void *arg
 
 PInt3Func h3(PInt3Func x, PInt3Func y, int* z) { return 0; }
 // CHECK: "\01?h3@@YAP6APAHPAH0 at ZP6APAH00@Z10 at Z"
+
+namespace foo {
+void foo() { }
+// CHECK: "\01?foo at 0@YAXXZ"
+}





More information about the cfe-commits mailing list