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

Douglas Gregor dgregor at apple.com
Mon Jul 11 21:47:21 PDT 2011


Author: dgregor
Date: Mon Jul 11 23:47:20 2011
New Revision: 134963

URL: http://llvm.org/viewvc/llvm-project?rev=134963&view=rev
Log:
Implement the Itanium C++ ABI's mangling rule for
non-instantiation-dependent sizeof and alignof expressions.

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

Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=134963&r1=134962&r2=134963&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
+++ cfe/trunk/lib/AST/ItaniumMangle.cpp Mon Jul 11 23:47:20 2011
@@ -2169,6 +2169,9 @@
   // <expr-primary> ::= L <type> <value number> E    # integer literal
   //                ::= L <type <value float> E      # floating literal
   //                ::= L <mangled-name> E           # external name
+  QualType ImplicitlyConvertedToType;
+  
+recurse:
   switch (E->getStmtClass()) {
   case Expr::NoStmtClass:
 #define ABSTRACT_STMT(Type)
@@ -2363,6 +2366,23 @@
 
   case Expr::UnaryExprOrTypeTraitExprClass: {
     const UnaryExprOrTypeTraitExpr *SAE = cast<UnaryExprOrTypeTraitExpr>(E);
+    
+    if (!SAE->isInstantiationDependent()) {
+      // Itanium C++ ABI:
+      //   If the operand of a sizeof or alignof operator is not 
+      //   instantiation-dependent it is encoded as an integer literal 
+      //   reflecting the result of the operator.
+      //
+      //   If the result of the operator is implicitly converted to a known 
+      //   integer type, that type is used for the literal; otherwise, the type 
+      //   of std::size_t or std::ptrdiff_t is used.
+      QualType T = (ImplicitlyConvertedToType.isNull() || 
+                    !ImplicitlyConvertedToType->isIntegerType())? SAE->getType()
+                                                    : ImplicitlyConvertedToType;
+      mangleIntegerLiteral(T, SAE->EvaluateAsInt(Context.getASTContext()));
+      break;
+    }
+    
     switch(SAE->getKind()) {
     case UETT_SizeOf:
       Out << 's';
@@ -2466,8 +2486,9 @@
   }
 
   case Expr::ImplicitCastExprClass: {
-    mangleExpression(cast<ImplicitCastExpr>(E)->getSubExpr(), Arity);
-    break;
+    ImplicitlyConvertedToType = E->getType();
+    E = cast<ImplicitCastExpr>(E)->getSubExpr();
+    goto recurse;
   }
       
   case Expr::ObjCBridgedCastExprClass: {

Modified: cfe/trunk/test/CodeGenCXX/mangle.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle.cpp?rev=134963&r1=134962&r2=134963&view=diff
==============================================================================
--- cfe/trunk/test/CodeGenCXX/mangle.cpp (original)
+++ cfe/trunk/test/CodeGenCXX/mangle.cpp Mon Jul 11 23:47:20 2011
@@ -804,9 +804,25 @@
 }
 
 namespace test34 {
+  // Mangling for instantiation-dependent decltype expressions.
   template<typename T>
   void f(decltype(sizeof(decltype(T() + T())))) {}
 
   // CHECK: define weak_odr void @_ZN6test341fIiEEvDTstDTplcvT__EcvS1__EEE
   template void f<int>(decltype(sizeof(1)));
+
+  // Mangling for non-instantiation-dependent sizeof expressions.
+  template<unsigned N>
+  void f2(int (&)[N + sizeof(int*)]) {}
+
+  // CHECK: define weak_odr void @_ZN6test342f2ILj4EEEvRAplT_Lm8E_i
+  template void f2<4>(int (&)[4 + sizeof(int*)]);
+
+  // Mangling for non-instantiation-dependent sizeof expressions
+  // involving an implicit conversion of the result of the sizeof.
+  template<unsigned long long N>
+  void f3(int (&)[N + sizeof(int*)]) {}
+
+  // CHECK: define weak_odr void @_ZN6test342f3ILy4EEEvRAplT_Ly8E_i
+  template void f3<4>(int (&)[4 + sizeof(int*)]);
 }





More information about the cfe-commits mailing list