[cfe-commits] r91257 - in /cfe/trunk: lib/CodeGen/Mangle.cpp test/CodeGenCXX/mangle.cpp

Anders Carlsson andersca at mac.com
Sun Dec 13 17:45:37 PST 2009


Author: andersca
Date: Sun Dec 13 19:45:37 2009
New Revision: 91257

URL: http://llvm.org/viewvc/llvm-project?rev=91257&view=rev
Log:
Mangle unary, binary and ternary expressions correctly.

Modified:
    cfe/trunk/lib/CodeGen/Mangle.cpp
    cfe/trunk/test/CodeGenCXX/mangle.cpp

Modified: cfe/trunk/lib/CodeGen/Mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/Mangle.cpp?rev=91257&r1=91256&r2=91257&view=diff

==============================================================================
--- cfe/trunk/lib/CodeGen/Mangle.cpp (original)
+++ cfe/trunk/lib/CodeGen/Mangle.cpp Sun Dec 13 19:45:37 2009
@@ -117,6 +117,8 @@
   void mangleType(const TagType*);
   void mangleBareFunctionType(const FunctionType *T,
                               bool MangleReturnType);
+
+  void mangleIntegerLiteral(QualType T, const llvm::APSInt &Value);
   void mangleExpression(const Expr *E);
   void mangleCXXCtorType(CXXCtorType T);
   void mangleCXXDtorType(CXXDtorType T);
@@ -687,10 +689,13 @@
   case OO_Call: Out << "cl"; break;
   //              ::= ix        # []
   case OO_Subscript: Out << "ix"; break;
-  // UNSUPPORTED: ::= qu        # ?
+
+  //              ::= qu        # ?
+  // The conditional operator can't be overloaded, but we still handle it when
+  // mangling expressions.
+  case OO_Conditional: Out << "qu"; break;
 
   case OO_None:
-  case OO_Conditional:
   case NUM_OVERLOADED_OPERATORS:
     assert(false && "Not an overloaded operator");
     break;
@@ -1011,6 +1016,24 @@
   Out << 'E';
 }
 
+void CXXNameMangler::mangleIntegerLiteral(QualType T, 
+                                          const llvm::APSInt &Value) {
+  //  <expr-primary> ::= L <type> <value number> E # integer literal
+  Out << 'L';
+  
+  mangleType(T);
+  if (T->isBooleanType()) {
+    // Boolean values are encoded as 0/1.
+    Out << (Value.getBoolValue() ? '1' : '0');
+  } else {
+    if (Value.isNegative())
+      Out << 'n';
+    Value.abs().print(Out, false);
+  }
+  Out << 'E';
+  
+}
+
 void CXXNameMangler::mangleExpression(const Expr *E) {
   // <expression> ::= <unary operator-name> <expression>
 	//              ::= <binary operator-name> <expression> <expression>
@@ -1029,6 +1052,32 @@
   switch (E->getStmtClass()) {
   default: assert(false && "Unhandled expression kind!");
 
+  case Expr::UnaryOperatorClass: {
+    const UnaryOperator *UO = cast<UnaryOperator>(E);
+    mangleOperatorName(UnaryOperator::getOverloadedOperator(UO->getOpcode()), 
+                       /*Arity=*/1);
+    mangleExpression(UO->getSubExpr());
+    break;
+  }
+      
+  case Expr::BinaryOperatorClass: {
+    const BinaryOperator *BO = cast<BinaryOperator>(E);
+    mangleOperatorName(BinaryOperator::getOverloadedOperator(BO->getOpcode()), 
+                       /*Arity=*/2);
+    mangleExpression(BO->getLHS());
+    mangleExpression(BO->getRHS());                     
+    break;
+  }      
+
+  case Expr::ConditionalOperatorClass: {
+    const ConditionalOperator *CO = cast<ConditionalOperator>(E);
+    mangleOperatorName(OO_Conditional, /*Arity=*/3);
+    mangleExpression(CO->getCond());
+    mangleExpression(CO->getLHS());
+    mangleExpression(CO->getRHS());
+    break;
+  }
+
   case Expr::ParenExprClass:
     mangleExpression(cast<ParenExpr>(E)->getSubExpr());
     break;
@@ -1065,6 +1114,11 @@
     break;
   }
 
+  case Expr::IntegerLiteralClass:
+    mangleIntegerLiteral(E->getType(), 
+                         llvm::APSInt(cast<IntegerLiteral>(E)->getValue()));
+    break;
+
   }
 }
 
@@ -1141,23 +1195,9 @@
     mangleExpression(A.getAsExpr());
     Out << 'E';
     break;
-  case TemplateArgument::Integral: {
-    //  <expr-primary> ::= L <type> <value number> E # integer literal
-
-    const llvm::APSInt *Integral = A.getAsIntegral();
-    Out << 'L';
-    mangleType(A.getIntegralType());
-    if (A.getIntegralType()->isBooleanType()) {
-      // Boolean values are encoded as 0/1.
-      Out << (Integral->getBoolValue() ? '1' : '0');
-    } else {
-      if (Integral->isNegative())
-        Out << 'n';
-      Integral->abs().print(Out, false);
-    }
-    Out << 'E';
+  case TemplateArgument::Integral:
+    mangleIntegerLiteral(A.getIntegralType(), *A.getAsIntegral());
     break;
-  }
   case TemplateArgument::Declaration: {
     //  <expr-primary> ::= L <mangled-name> E # external name
 

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=91257&r1=91256&r2=91257&view=diff

==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Sun Dec 13 19:45:37 2009
@@ -228,3 +228,31 @@
 template void ft8<int>();
 // CHECK: @_Z3ft8IPvEN11__enable_ifIXsr11__is_scalarIT_E7__valueEvE6__typeEv
 template void ft8<void*>();
+
+namespace Expressions {
+// Unary operators.
+
+// CHECK: define void @_ZN11Expressions2f1ILi1EEEvPAplngT_Li2E_i
+template <int i> void f1(int (*)[(-i) + 2]) { };
+template void f1<1>(int (*)[1]);
+
+// CHECK: define void @_ZN11Expressions2f2ILi1EEEvPApsT__i
+template <int i> void f2(int (*)[+i]) { };
+template void f2<1>(int (*)[1]);
+
+// Binary operators.
+
+// CHECK: define void @_ZN11Expressions2f3ILi1EEEvPAplT_T__i
+template <int i> void f3(int (*)[i+i]) { };
+template void f3<1>(int (*)[2]);
+
+// CHECK: define void @_ZN11Expressions2f4ILi1EEEvPAplplLi2ET_T__i
+template <int i> void f4(int (*)[2 + i+i]) { };
+template void f4<1>(int (*)[4]);
+
+// The ternary operator.
+// CHECK: define void @_ZN11Expressions2f4ILb1EEEvPAquT_Li1ELi2E_i
+template <bool b> void f4(int (*)[b ? 1 : 2]) { };
+template void f4<true>(int (*)[1]);
+
+}





More information about the cfe-commits mailing list