From: Jakub Jelinek Date: Thu, 21 Jan 2016 07:59:32 +0000 (+0100) Subject: re PR tree-optimization/69355 (Wrong results with -O1 optimization) X-Git-Tag: basepoints/gcc-7~1435 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5463c2c89362c64ad49953bd06e10cc8925bfe06;p=thirdparty%2Fgcc.git re PR tree-optimization/69355 (Wrong results with -O1 optimization) PR c++/69355 * tree-dfa.c (get_ref_base_and_extent): Use GET_MODE_BITSIZE (mode) for bitsize instead of GET_MODE_PRECISION (mode). * g++.dg/torture/pr69355.C: New test. From-SVN: r232663 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 36a210a699a9..5b4ed595fd6c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2016-01-21 Jakub Jelinek + + PR c++/69355 + * tree-dfa.c (get_ref_base_and_extent): Use GET_MODE_BITSIZE (mode) + for bitsize instead of GET_MODE_PRECISION (mode). + 2016-01-20 Martin Sebor PR c/52291 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 50aa4392641f..a6bc40c1ece4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2016-01-21 Jakub Jelinek + + PR c++/69355 + * g++.dg/torture/pr69355.C: New test. + 2016-01-21 Aditya Kumar Sebastian Pop diff --git a/gcc/testsuite/g++.dg/torture/pr69355.C b/gcc/testsuite/g++.dg/torture/pr69355.C new file mode 100644 index 000000000000..58cb9615e21c --- /dev/null +++ b/gcc/testsuite/g++.dg/torture/pr69355.C @@ -0,0 +1,150 @@ +// PR c++/69355 +// { dg-do run } + +template struct A; +template <> struct A<1> {}; +template struct B +{ + template struct C + { + typedef T *iterator; + C (iterator p1) : m_iter (p1) {} + void operator, (T p1) { *m_iter = p1; } + iterator m_iter; + }; + typedef double *iterator; + B (Obj &p1, double) : m_object (p1) {} + C operator, (double); + Obj &m_object; +}; +template +typename B::template C +B::operator, (double p1) +{ + iterator a = m_object.data (), b = a + 1; + *a = 1; + *b = p1; + return C(b + 1); +} +class D {}; +inline double operator+(const double &p1, D) { return p1; } +template class U; +template struct F +{ + enum { doIt = K < Sz - 1 ? 1 : 0 }; + template + static void assign (Dest &p1, Src &p2, Assign &p3) + { + p3.apply_on (p1 (K), p2 (K)); + F::assign (p1, p2, p3); + } + template static double dot (Dest &p1, Src &p2) + { + return p1 (K) * p2 (K) + F::dot (p1, p2); + } +}; +template <> struct F<0> +{ + template + static void assign (Dest &, Src &, Assign &) {} + template static D dot (Dest &, Src &) { return D (); } +}; +template struct G +{ + enum { ops_assign, use_meta }; + G (const E &p1) : m_expr (p1) {} + double operator()(int p1) const { return m_expr (p1); } + template + static void do_assign (A<1>, Dest &p2, Src &p3, Assign &p4) + { + F::assign (p2, p3, p4); + } + template + void assign_to (Dest &p1, const Assign &p2) const + { + do_assign (A<1>(), p1, *this, p2); + } + E m_expr; +}; +struct H +{ + static double apply_on (double p1, long double p2) { return p1 / p2; } + static void apply_on (double &p1, double p2) { p1 = p2; } +}; +template struct I +{ + I (const E1 &p1, const E2 &p2) : m_lhs (p1), m_rhs (p2) {} + double operator()(int p1) const + { + double c = m_lhs (p1); + return H::apply_on (c, m_rhs (0)); + } + E1 m_lhs; + const E2 m_rhs; +}; +struct J +{ + J (double p1) : m_data (p1) {} + long double operator()(int) const { return m_data; } + long double m_data; +}; +template struct K +{ + K (const U &p1) : m_data (p1.data ()) {} + double operator()(int p1) const { return m_data[p1]; } + const double *m_data; +}; +template struct U +{ + U () {} + U (const U &p1) + { + *this = G(p1.const_ref ()); + } + B operator=(double) { return B(*this, 0); } + double *data () { return m_data; } + const double *data () const { return m_data; } + double &operator()(int p1) { return m_data[p1]; } + double operator()(int p1) const { return m_data[p1]; } + typedef K ConstReference; + ConstReference const_ref () const { return *this; } + template void operator=(const G &p1) + { + p1.assign_to (*this, H ()); + } + double m_data[Sz]; +}; +template +G, J>, Sz> div (U &p1, double p2) +{ + typedef I, J> expr_type; + return G(expr_type (p1.const_ref (), p2)); +} +template double norm2 (U &p1) +{ + return __builtin_sqrt (F::dot (p1, p1)); +} +template +G, J>, Sz> operator/(U &p1, double p2) +{ + return div (p1, p2); +} +typedef U<3> V; +V foo (V p1) +{ + double e = norm2 (p1); + V r; + r = p1 / e; + return r; +} +int +main () +{ + V f; + f = 1, 2, 3; + V r = foo (f); + if (__builtin_fabs (r (0) - 0.267261) > 0.01 + || __builtin_fabs (r (1) - 0.534522) > 0.01 + || __builtin_fabs (r (2) - 0.801784) > 0.01) + __builtin_abort (); +} diff --git a/gcc/tree-dfa.c b/gcc/tree-dfa.c index 54a6d07dbd55..db560cf73602 100644 --- a/gcc/tree-dfa.c +++ b/gcc/tree-dfa.c @@ -395,7 +395,7 @@ get_ref_base_and_extent (tree exp, HOST_WIDE_INT *poffset, if (mode == BLKmode) size_tree = TYPE_SIZE (TREE_TYPE (exp)); else - bitsize = int (GET_MODE_PRECISION (mode)); + bitsize = int (GET_MODE_BITSIZE (mode)); } if (size_tree != NULL_TREE && TREE_CODE (size_tree) == INTEGER_CST)