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

Richard Smith richard at metafoo.co.uk
Sat Feb 25 13:50:39 PST 2012


There is a proposal for this mangling on the cxx-abi-dev list, which we
should follow rather than making up our own:

http://sourcerytools.com/pipermail/cxx-abi-dev/2012-January/000042.html

GCC 4.7 appears to already implement this proposal.

On Sat, Feb 25, 2012 at 12:51 PM, Sebastian Redl <
sebastian.redl at getdesigned.at> wrote:

> Author: cornedbee
> Date: Sat Feb 25 14:51:07 2012
> New Revision: 151455
>
> URL: http://llvm.org/viewvc/llvm-project?rev=151455&view=rev
> Log:
> Better mangling for new-expressions. Also, although we can't mangle
> arbitrary initializer lists yet (we will need this), turn the crash into a
> controlled error.
>
> Modified:
>    cfe/trunk/lib/AST/ItaniumMangle.cpp
>    cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
>
> Modified: cfe/trunk/lib/AST/ItaniumMangle.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ItaniumMangle.cpp?rev=151455&r1=151454&r2=151455&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/AST/ItaniumMangle.cpp (original)
> +++ cfe/trunk/lib/AST/ItaniumMangle.cpp Sat Feb 25 14:51:07 2012
> @@ -2356,12 +2356,12 @@
>   case Expr::CXXThisExprClass:
>   case Expr::DesignatedInitExprClass:
>   case Expr::ImplicitValueInitExprClass:
> -  case Expr::InitListExprClass:
>   case Expr::ParenListExprClass:
>   case Expr::LambdaExprClass:
>     llvm_unreachable("unexpected statement kind");
>
>   // FIXME: invent manglings for all these.
> +  case Expr::InitListExprClass:
>   case Expr::BlockExprClass:
>   case Expr::CXXPseudoDestructorExprClass:
>   case Expr::ChooseExprClass:
> @@ -2454,7 +2454,6 @@
>   }
>
>   case Expr::CXXNewExprClass: {
> -    // Proposal from David Vandervoorde, 2010.06.30
>     const CXXNewExpr *New = cast<CXXNewExpr>(E);
>     if (New->isGlobalNew()) Out << "gs";
>     Out << (New->isArray() ? "na" : "nw");
> @@ -2464,8 +2463,14 @@
>     Out << '_';
>     mangleType(New->getAllocatedType());
>     if (New->hasInitializer()) {
> -      // FIXME: Does this mean "parenthesized initializer"?
> -      Out << "pi";
> +      // <initializer> is 'pi <expression>* E' in the current ABI for
> +      // parenthesized initializers, but braced initializers are
> unspecified.
> +      // We use 'bl <expression>* E' for "braced list". "bi" is too easy
> to
> +      // confuse.
> +      if (New->getInitializationStyle() == CXXNewExpr::ListInit)
> +        Out << "bl";
> +      else
> +        Out << "pi";
>       const Expr *Init = New->getInitializer();
>       if (const CXXConstructExpr *CCE = dyn_cast<CXXConstructExpr>(Init)) {
>         // Directly inline the initializers.
> @@ -2476,6 +2481,12 @@
>       } else if (const ParenListExpr *PLE = dyn_cast<ParenListExpr>(Init))
> {
>         for (unsigned i = 0, e = PLE->getNumExprs(); i != e; ++i)
>           mangleExpression(PLE->getExpr(i));
> +      } else if (New->getInitializationStyle() == CXXNewExpr::ListInit &&
> +                 isa<InitListExpr>(Init)) {
> +        // Only take ParenListExprs apart for list-initialization.
> +        const InitListExpr *InitList = cast<InitListExpr>(Init);
> +        for (unsigned i = 0, e = InitList->getNumInits(); i != e; ++i)
> +          mangleExpression(InitList->getInit(i));
>       } else
>         mangleExpression(Init);
>     }
>
> Modified: cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp?rev=151455&r1=151454&r2=151455&view=diff
>
> ==============================================================================
> --- cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp (original)
> +++ cfe/trunk/test/CodeGenCXX/mangle-exprs.cpp Sat Feb 25 14:51:07 2012
> @@ -1,5 +1,37 @@
>  // RUN: %clang_cc1 -std=c++11 -emit-llvm %s -o -
> -triple=x86_64-apple-darwin9 | FileCheck %s
>
> +namespace std {
> +  typedef decltype(sizeof(int)) size_t;
> +
> +  // libc++'s implementation
> +  template <class _E>
> +  class initializer_list
> +  {
> +    const _E* __begin_;
> +    size_t    __size_;
> +
> +    initializer_list(const _E* __b, size_t __s)
> +      : __begin_(__b),
> +        __size_(__s)
> +    {}
> +
> +  public:
> +    typedef _E        value_type;
> +    typedef const _E& reference;
> +    typedef const _E& const_reference;
> +    typedef size_t    size_type;
> +
> +    typedef const _E* iterator;
> +    typedef const _E* const_iterator;
> +
> +    initializer_list() : __begin_(nullptr), __size_(0) {}
> +
> +    size_t    size()  const {return __size_;}
> +    const _E* begin() const {return __begin_;}
> +    const _E* end()   const {return __begin_ + __size_;}
> +  };
> +}
> +
>  template < bool condition, typename T = void >
>  struct enable_if { typedef T type; };
>
> @@ -132,3 +164,31 @@
>     a(x, &X::member, ip);
>   }
>  }
> +
> +namespace test4 {
> +  struct X {
> +    X(int);
> +    X(std::initializer_list<int>);
> +  };
> +
> +  template <typename T>
> +  void tf1(decltype(new T(1)) p)
> +  {}
> +
> +  template <typename T>
> +  void tf2(decltype(new T({1})) p)
> +  {}
> +
> +  template <typename T>
> +  void tf3(decltype(new T{1}) p)
> +  {}
> +
> +  // CHECK: void @_ZN5test43tf1INS_1XEEEvDTnw_T_piLi1EEE
> +  template void tf1<X>(X*);
> +
> +  // FIXME: Need mangling for braced initializers
> +  //template void tf2<X>(X*);
> +
> +  // CHECK: void @_ZN5test43tf3INS_1XEEEvDTnw_T_blLi1EEE
> +  template void tf3<X>(X*);
> +}
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20120225/4cf26090/attachment.html>


More information about the cfe-commits mailing list