[cfe-commits] r147653 - in /cfe/trunk: lib/AST/ItaniumMangle.cpp test/CodeGenCXX/mangle-template.cpp

John McCall rjmccall at apple.com
Thu Jan 5 21:06:35 PST 2012


Author: rjmccall
Date: Thu Jan  5 23:06:35 2012
New Revision: 147653

URL: http://llvm.org/viewvc/llvm-project?rev=147653&view=rev
Log:
Fix the mangling of class template arguments in a particular
dependent case.  Thanks to Jason Merrill for pointing this out.

Modified:
    cfe/trunk/lib/AST/ItaniumMangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle-template.cpp

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=147653&r1=147652&r2=147653&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Thu Jan  5 23:06:35 2012
@@ -2899,11 +2899,26 @@
     Out << "Dp";
     mangleType(A.getAsTemplateOrTemplatePattern());
     break;
-  case TemplateArgument::Expression:
+  case TemplateArgument::Expression: {
+    // It's possible to end up with a DeclRefExpr here in certain
+    // dependent cases, in which case we should mangle as a
+    // declaration.
+    const Expr *E = A.getAsExpr()->IgnoreParens();
+    if (const DeclRefExpr *DRE = dyn_cast<DeclRefExpr>(E)) {
+      const ValueDecl *D = DRE->getDecl();
+      if (isa<VarDecl>(D) || isa<FunctionDecl>(D)) {
+        Out << "L";
+        mangle(D, "_Z");
+        Out << 'E';
+        break;
+      }
+    }
+    
     Out << 'X';
-    mangleExpression(A.getAsExpr());
+    mangleExpression(E);
     Out << 'E';
     break;
+  }
   case TemplateArgument::Integral:
     mangleIntegerLiteral(A.getIntegralType(), *A.getAsIntegral());
     break;

Modified: cfe/trunk/test/CodeGenCXX/mangle-template.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-template.cpp?rev=147653&r1=147652&r2=147653&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle-template.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle-template.cpp Thu Jan  5 23:06:35 2012
@@ -144,3 +144,12 @@
     f(i, d);
   }
 }
+
+// Report from Jason Merrill on cxx-abi-dev, 2012.01.04.
+namespace test11 {
+  int cmp(char a, char b);
+  template <typename T, int (*cmp)(T, T)> struct A {};
+  template <typename T> void f(A<T,cmp> &) {}
+  template void f<char>(A<char,cmp> &);
+  // CHECK: @_ZN6test111fIcEEvRNS_1AIT_L_ZNS_3cmpEccEEE(
+}





More information about the cfe-commits mailing list