Index: cfe/trunk/lib/AST/ItaniumMangle.cpp =================================================================== --- cfe/trunk/lib/AST/ItaniumMangle.cpp +++ cfe/trunk/lib/AST/ItaniumMangle.cpp @@ -375,6 +375,7 @@ NamedDecl *firstQualifierLookup, DeclarationName name, unsigned knownArity); + void mangleCastExpression(const Expr *E, StringRef CastEncoding); void mangleExpression(const Expr *E, unsigned Arity = UnknownArity); void mangleCXXCtorType(CXXCtorType T); void mangleCXXDtorType(CXXDtorType T); @@ -2572,12 +2573,23 @@ return true; } +void CXXNameMangler::mangleCastExpression(const Expr *E, StringRef CastEncoding) { + const ExplicitCastExpr *ECE = cast(E); + Out << CastEncoding; + mangleType(ECE->getType()); + mangleExpression(ECE->getSubExpr()); +} + void CXXNameMangler::mangleExpression(const Expr *E, unsigned Arity) { // ::= // ::= // ::= // ::= cv expression # conversion with one argument // ::= cv _ * E # conversion with a different number of arguments + // ::= dc # dynamic_cast (expression) + // ::= sc # static_cast (expression) + // ::= cc # const_cast (expression) + // ::= rc # reinterpret_cast (expression) // ::= st # sizeof (a type) // ::= at # alignof (a type) // ::= @@ -2982,17 +2994,22 @@ // Fall through to mangle the cast itself. case Expr::CStyleCastExprClass: + case Expr::CXXFunctionalCastExprClass: + mangleCastExpression(E, "cv"); + break; + case Expr::CXXStaticCastExprClass: + mangleCastExpression(E, "sc"); + break; case Expr::CXXDynamicCastExprClass: + mangleCastExpression(E, "dc"); + break; case Expr::CXXReinterpretCastExprClass: + mangleCastExpression(E, "rc"); + break; case Expr::CXXConstCastExprClass: - case Expr::CXXFunctionalCastExprClass: { - const ExplicitCastExpr *ECE = cast(E); - Out << "cv"; - mangleType(ECE->getType()); - mangleExpression(ECE->getSubExpr()); + mangleCastExpression(E, "cc"); break; - } case Expr::CXXOperatorCallExprClass: { const CXXOperatorCallExpr *CE = cast(E); Index: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp =================================================================== --- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp +++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp @@ -56,6 +56,18 @@ void static_(typename enable_if< O <= static_cast(4) >::type* = 0) { } + template + void reinterpret_(typename enable_if(0))>::type * = 0) { + } + + template + void const_(typename enable_if<0 <= sizeof(const_cast(p))>::type * = 0) { + } + + template + void dynamic_(typename enable_if<0 <= sizeof(dynamic_cast(p))>::type * = 0) { + } + template< typename T > void auto_(decltype(new auto(T()))) { } @@ -64,11 +76,12 @@ void scalar_(decltype(T(), int())) { } - // FIXME: Test const_cast, reinterpret_cast, dynamic_cast, which are - // a bit harder to use in template arguments. template struct T {}; template T f() { return T(); } + + extern int i; + extern struct S {} s; // CHECK-LABEL: define weak_odr void @_ZN5Casts8implicitILj4EEEvPN9enable_ifIXleT_Li4EEvE4typeE template void implicit<4>(void*); @@ -76,8 +89,14 @@ template void cstyle<4>(void*); // CHECK-LABEL: define weak_odr void @_ZN5Casts10functionalILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE template void functional<4>(void*); - // CHECK-LABEL: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_cvjLi4EEvE4typeE + // CHECK-LABEL: define weak_odr void @_ZN5Casts7static_ILj4EEEvPN9enable_ifIXleT_scjLi4EEvE4typeE template void static_<4>(void*); + // CHECK-LABEL: define weak_odr void @_ZN5Casts12reinterpret_ILj4EiEEvPN9enable_ifIXleT_szrcPT0_Li0EEvE4typeE + template void reinterpret_<4, int>(void*); + // CHECK-LABEL: define weak_odr void @_ZN5Casts6const_IiXadL_ZNS_1iEEEEEvPN9enable_ifIXleLi0EszccPT_T0_EvE4typeE + template void const_(void*); + // CHECK-LABEL: define weak_odr void @_ZN5Casts8dynamic_INS_1SEXadL_ZNS_1sEEEEEvPN9enable_ifIXleLi0EszdcPT_T0_EvE4typeE + template void dynamic_(void*); // CHECK-LABEL: define weak_odr void @_ZN5Casts1fILi6EEENS_1TIXT_EEEv template T<6> f<6>();