OSDN Git Service

gcc/cp
authorjanis <janis@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Sep 2011 17:33:41 +0000 (17:33 +0000)
committerjanis <janis@138bc75d-0d04-0410-961f-82ee72b054a4>
Fri, 30 Sep 2011 17:33:41 +0000 (17:33 +0000)
PR c++/44473
* mangle.c (write_type): Handle CV qualifiers for decimal classes.
gcc/testsuite
PR c++/44473
* g++.dg/dfp/44473-1.C: New test.
* g++.dg/dfp/44473-2.C: New test.
* g++.dg/dfp/mangle-1.C: New test.
* g++.dg/dfp/mangle-2.C: New test.
* g++.dg/dfp/mangle-3.C: New test.
* g++.dg/dfp/mangle-4.C: New test.
* g++.dg/dfp/mangle-5.C: New test.

git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@179399 138bc75d-0d04-0410-961f-82ee72b054a4

gcc/cp/ChangeLog
gcc/cp/mangle.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/dfp/44473-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/44473-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/mangle-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/mangle-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/mangle-3.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/mangle-4.C [new file with mode: 0644]
gcc/testsuite/g++.dg/dfp/mangle-5.C [new file with mode: 0644]

index 0058e43..4cd3ff9 100644 (file)
@@ -1,3 +1,8 @@
+2011-09-30  Janis Johnson  <janisjo@codesourcery.com>
+
+       PR c++/44473
+       * mangle.c (write_type): Handle CV qualifiers for decimal classes.
+
 2011-09-26   Andi Kleen <ak@linux.intel.com>
 
        * repo.c (finish_repo): Use HOST_WIDE_INT_PRINT_HEX_PURE.
index 1fcd999..55851e6 100644 (file)
@@ -1802,11 +1802,6 @@ write_type (tree type)
   if (find_substitution (type))
     return;
 
-  /* According to the C++ ABI, some library classes are passed the
-     same as the scalar type of their single member and use the same
-     mangling.  */
-  if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
-    type = TREE_TYPE (first_field (type));
 
   if (write_CV_qualifiers_for_type (type) > 0)
     /* If TYPE was CV-qualified, we just wrote the qualifiers; now
@@ -1826,6 +1821,12 @@ write_type (tree type)
       /* See through any typedefs.  */
       type = TYPE_MAIN_VARIANT (type);
 
+      /* According to the C++ ABI, some library classes are passed the
+        same as the scalar type of their single member and use the same
+        mangling.  */
+      if (TREE_CODE (type) == RECORD_TYPE && TYPE_TRANSPARENT_AGGR (type))
+       type = TREE_TYPE (first_field (type));
+
       if (TYPE_PTRMEM_P (type))
        write_pointer_to_member_type (type);
       else
index 7005e74..d7b163a 100644 (file)
@@ -1,3 +1,14 @@
+2011-09-30  Janis Johnson  <janisjo@codesourcery.com>
+
+       PR c++/44473
+       * g++.dg/dfp/44473-1.C: New test.
+       * g++.dg/dfp/44473-2.C: New test.
+       * g++.dg/dfp/mangle-1.C: New test.
+       * g++.dg/dfp/mangle-2.C: New test.
+       * g++.dg/dfp/mangle-3.C: New test.
+       * g++.dg/dfp/mangle-4.C: New test.
+       * g++.dg/dfp/mangle-5.C: New test.
+
 2011-09-30  Jakub Jelinek  <jakub@redhat.com>
 
        PR inline-asm/50571
diff --git a/gcc/testsuite/g++.dg/dfp/44473-1.C b/gcc/testsuite/g++.dg/dfp/44473-1.C
new file mode 100644 (file)
index 0000000..38689fa
--- /dev/null
@@ -0,0 +1,122 @@
+/* { dg-do assemble } */
+
+/* Minimized from the testcase in PR c++/44473; mangling of decimal types
+   did not include CV qualifiers. */
+
+namespace std
+{
+  namespace decimal
+  {
+    class decimal32
+    {
+    public:
+      typedef float __decfloat32 __attribute__ ((mode (SD)));
+      explicit decimal32 (float __r):__val (__r) {}
+    private:
+      __decfloat32 __val;
+    };
+  };
+
+  template <typename _BI1, typename _BI2>
+  _BI2 copy_backward (_BI1 __first, _BI2 __result);
+}
+
+namespace __gnu_cxx
+{
+  template <typename _Iterator, typename _Container>
+  class __normal_iterator
+  {
+  public:
+    explicit __normal_iterator (const _Iterator & __i) {}
+    const _Iterator & base () const {}
+  };
+
+  template <typename _IteratorL, typename _IteratorR, typename _Container>
+  bool operator== (const __normal_iterator <_IteratorL, _Container> &__lhs,
+                  const __normal_iterator <_IteratorR, _Container> &__rhs)
+  {
+    return __lhs.base () == __rhs.base ();
+  }
+
+  template <typename _Tp>
+  class new_allocator
+  {
+  public:
+    typedef _Tp *pointer;
+    typedef const _Tp *const_pointer;
+    template <typename _Tp1>
+    struct rebind
+    {
+      typedef new_allocator <_Tp1> other;
+    };
+  };
+}
+
+namespace std
+{
+  template <typename _Tp>
+  class allocator:public __gnu_cxx::new_allocator <_Tp> {};
+
+  template <typename _Tp, typename _Alloc>
+  struct _Vector_base
+  {
+    typedef typename _Alloc::template rebind <_Tp>::other _Tp_alloc_type;
+    struct _Vector_impl:public _Tp_alloc_type
+    {
+      typename _Tp_alloc_type::pointer _M_finish;
+    };
+  public:  _Vector_impl _M_impl;
+  };
+
+  template <typename _Tp, typename _Alloc = std::allocator <_Tp> >
+  class vector:protected _Vector_base <_Tp, _Alloc>
+  {
+    typedef _Vector_base <_Tp, _Alloc> _Base;
+    typedef typename _Base::_Tp_alloc_type _Tp_alloc_type;
+  public:
+    typedef _Tp value_type;
+    typedef typename _Tp_alloc_type::pointer pointer;
+    typedef typename _Tp_alloc_type::const_pointer const_pointer;
+    typedef __gnu_cxx::__normal_iterator <pointer, vector> iterator;
+    typedef __gnu_cxx::__normal_iterator <const_pointer, vector>
+      const_iterator;
+    const_iterator begin () const;
+    iterator end ()
+    {
+      return iterator (this->_M_impl._M_finish);
+    }
+    const_iterator end () const
+    {
+      return const_iterator (this->_M_impl._M_finish);
+    }
+    bool empty () const
+    {
+      return begin () == end ();
+    }
+    void push_back (const value_type & __x)
+    {
+      _M_insert_aux (end ());
+    }
+    void _M_insert_aux (iterator __position);
+  };
+
+  template <typename _Tp, typename _Alloc>
+  void vector <_Tp, _Alloc>::_M_insert_aux (iterator __position)
+  {
+    std::copy_backward (__position.base (), this->_M_impl._M_finish - 1);
+  }
+}
+
+std::vector <std::decimal::decimal32> vec;
+
+int
+foo ()
+{
+  return (vec.empty ()) ? 1 : 0;
+}
+
+bool
+bar ()
+{
+  vec.push_back (std::decimal::decimal32 (0));
+}
diff --git a/gcc/testsuite/g++.dg/dfp/44473-2.C b/gcc/testsuite/g++.dg/dfp/44473-2.C
new file mode 100644 (file)
index 0000000..311f622
--- /dev/null
@@ -0,0 +1,25 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+
+namespace std {
+  namespace decimal {
+    class decimal64 {
+      public:
+       typedef float __decfloat64 __attribute__ ((mode (DD)));
+       explicit decimal64 (int __r):__val (__r) {}
+      private:
+       __decfloat64 __val;
+    };
+  }
+}
+
+int bar (const std::decimal::decimal64 & x) { }
+
+int foo ()
+{
+  std::decimal::decimal64 x(0);
+  bar (x);
+}
+
+// { dg-final { scan-assembler "_Z3barRKDd:" } }
diff --git a/gcc/testsuite/g++.dg/dfp/mangle-1.C b/gcc/testsuite/g++.dg/dfp/mangle-1.C
new file mode 100644 (file)
index 0000000..455d3e4
--- /dev/null
@@ -0,0 +1,40 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+// Derived from g++.dg/abi/mangle13.C.
+
+namespace std {
+  namespace decimal {
+    class decimal64 {
+      public:
+       typedef float __decfloat64 __attribute__ ((mode (DD)));
+       explicit decimal64 (float __r):__val (__r) {}
+      private:
+       __decfloat64 __val;
+    };
+  }
+}
+
+struct A {
+  template <typename T> std::decimal::decimal64 f ();
+  std::decimal::decimal64 operator+();
+  operator std::decimal::decimal64 ();
+  template <typename T>
+  std::decimal::decimal64 operator-();
+};
+
+typedef std::decimal::decimal64 (A::*P)();
+
+template <P> struct S {};
+
+template <typename T> void g (S<&T::template f<std::decimal::decimal64> >) {}
+template <typename T> void g (S<&T::operator+ >) {}
+template <typename T> void g (S<&T::operator std::decimal::decimal64>) {}
+template <typename T> void g (S<&T::template operator- <std::decimal::decimal64> >) {}
+
+template void g<A> (S<&A::f<std::decimal::decimal64> >);
+template void g<A> (S<&A::operator+>);
+template void g<A> (S<&A::operator std::decimal::decimal64>);
+
+// { dg-final { scan-assembler "\n?_Z1gI1AEv1SIXadsrT_1fIDdEEE\[: \t\n\]" } }
+// { dg-final { scan-assembler "\n?_Z1gI1AEv1SIXadsrT_plEE\[: \t\n\]" } }
diff --git a/gcc/testsuite/g++.dg/dfp/mangle-2.C b/gcc/testsuite/g++.dg/dfp/mangle-2.C
new file mode 100644 (file)
index 0000000..1af9aa1
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+// Derived from g++.dg/abi/mangle15.C.
+
+namespace std {
+  namespace decimal {
+    class decimal64 {
+      public:
+       typedef float __decfloat64 __attribute__ ((mode (DD)));
+       explicit decimal64 (float __r):__val (__r) {}
+      private:
+       __decfloat64 __val;
+    };
+  }
+}
+
+struct A {
+  template <typename T> std::decimal::decimal64 f ();
+};
+
+typedef std::decimal::decimal64 (A::*P)();
+
+template <P> struct S {};
+
+void g (S<&A::f<std::decimal::decimal64> >) {}
+
+// { dg-final { scan-assembler "\n?_Z1g1SIXadL_ZN1A1fIDdEEDdvEEE\[: \t\n\]" } }
diff --git a/gcc/testsuite/g++.dg/dfp/mangle-3.C b/gcc/testsuite/g++.dg/dfp/mangle-3.C
new file mode 100644 (file)
index 0000000..c716ed0
--- /dev/null
@@ -0,0 +1,28 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+// Derived from g++.dg/abi/mangle20-1.C.
+
+namespace std {
+  namespace decimal {
+    class decimal64 {
+      public:
+       typedef float __decfloat64 __attribute__ ((mode (DD)));
+       explicit decimal64 (int __r):__val (__r) {}
+      private:
+       __decfloat64 __val;
+    };
+  }
+}
+
+template <int I> void f(std::decimal::decimal64 (*)[2]) {}
+template <int I> void g(std::decimal::decimal64 (*)[I+2]) {}
+
+static const std::decimal::decimal64 I(1);
+static const std::decimal::decimal64 J(2);
+
+template void f<1>(std::decimal::decimal64 (*)[2]);
+template void g<1>(std::decimal::decimal64 (*)[3]);
+
+//  { dg-final { scan-assembler "\n_?_Z1fILi1EEvPA2_Dd\[: \t\n\]" } }
+//  { dg-final { scan-assembler "\n_?_Z1gILi1EEvPAplT_Li2E_Dd\[: \t\n\]" } }
diff --git a/gcc/testsuite/g++.dg/dfp/mangle-4.C b/gcc/testsuite/g++.dg/dfp/mangle-4.C
new file mode 100644 (file)
index 0000000..899d566
--- /dev/null
@@ -0,0 +1,35 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+// Derived from g++.dg/abi/mangle30.C.
+
+namespace std {
+  namespace decimal {
+    class decimal64 {
+      public:
+       typedef float __decfloat64 __attribute__ ((mode (DD)));
+       explicit decimal64 (int __r):__val (__r) {}
+      private:
+       __decfloat64 __val;
+    };
+  }
+}
+
+struct A
+{
+  template <class T>
+  struct B
+  {
+    typedef T myT;
+  };
+};
+
+template <class T>
+void f (T t, typename T::template B<std::decimal::decimal64>::myT u, typename T::template B<int>::myT v);
+
+void foo ()
+{
+  f (A(), std::decimal::decimal64(0), 1);
+}
+
+// { dg-final { scan-assembler "_Z1fI1AEvT_NS1_1BIDdE3myTENS2_IiE3myTE" } }
diff --git a/gcc/testsuite/g++.dg/dfp/mangle-5.C b/gcc/testsuite/g++.dg/dfp/mangle-5.C
new file mode 100644 (file)
index 0000000..794577f
--- /dev/null
@@ -0,0 +1,29 @@
+// { dg-do compile }
+
+// Mangling of classes from std::decimal are special-cased.
+// Derived from g++.dg/abi/mangle35.C.
+
+namespace std {
+  namespace decimal {
+    class decimal128 {
+      public:
+       typedef float __decfloat128 __attribute__ ((mode (TD)));
+       explicit decimal128 (int __r):__val (__r) {}
+      private:
+       __decfloat128 __val;
+    };
+  }
+}
+
+template<void (*)()> struct A {};
+
+template<typename> void foo();
+
+template<typename T> A<foo<T> > bar();
+
+void baz()
+{
+  bar<std::decimal::decimal128>();
+}
+
+// { dg-final { scan-assembler "_Z3barIDeE1AIX3fooIT_EEEv" } }