* tree-vrp.c (get_value_range): Set VR of
SSA_NAME_IS_DEFAULT_DEF of DECL_BY_REFERENCE RESULT_DECL
to nonnull.
* g++.dg/opt/vrp3.C: New test.
* g++.dg/opt/vrp3-aux.cc: New file.
* g++.dg/opt/vrp3.h: New file.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/branches/gcc-4_7-branch@187241
138bc75d-0d04-0410-961f-
82ee72b054a4
+2012-05-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/53239
+ * tree-vrp.c (get_value_range): Set VR of
+ SSA_NAME_IS_DEFAULT_DEF of DECL_BY_REFERENCE RESULT_DECL
+ to nonnull.
+
2012-05-07 Richard Guenther <rguenther@suse.de>
PR tree-optimization/53195
+2012-05-07 Jakub Jelinek <jakub@redhat.com>
+
+ PR tree-optimization/53239
+ * g++.dg/opt/vrp3.C: New test.
+ * g++.dg/opt/vrp3-aux.cc: New file.
+ * g++.dg/opt/vrp3.h: New file.
+
2012-05-07 Tobias Burnus <burnus@net-b.de>
Backport from mainline:
--- /dev/null
+// { dg-do compile }
+// { dg-options "" }
+
+#include "vrp3.h"
+
+R::R ()
+{
+ r1 = r2 = 1;
+}
+
+R::R (int n, int d)
+{
+ r1 = n;
+ r2 = d;
+}
+
+int
+R::compare (R const &r, R const &s)
+{
+ return (int) (r.r1 * s.r2 - s.r1 * r.r2);
+}
--- /dev/null
+// PR tree-optimization/53239
+// { dg-do run }
+// { dg-options "-O2" }
+// { dg-additional-sources "vrp3-aux.cc" }
+
+#include "vrp3.h"
+
+struct M
+{
+ M (R m);
+ R val;
+ static int compare (M const &, M const &);
+};
+
+inline M const &
+min (M const & t1, M const & t2)
+{
+ return R::compare (t1.val, t2.val) < 0 ? t1 : t2;
+}
+
+M::M (R m)
+{
+ val = m;
+}
+
+M
+test (M *x)
+{
+ M n (R (0, 0));
+
+ for (int i = 0; i < 2; i++)
+ {
+ M p = x[i];
+ n = min (n, p);
+ }
+
+ if (n.val.r2 != 2 || n.val.r1 != 1)
+ __builtin_abort ();
+ return n;
+}
+
+int
+main ()
+{
+ M x[2] = { M (R (1, 2)), M (R (1, 1)) };
+ test (x);
+}
--- /dev/null
+struct R
+{
+ long long r1, r2;
+ void copy (R const &r) { r1 = r.r1; r2 = r.r2; }
+ R ();
+ explicit R (int, int);
+ R (R const &r) { copy (r); }
+ static int compare (R const &, R const &);
+};
/* If VAR is a default definition of a parameter, the variable can
take any value in VAR's type. */
sym = SSA_NAME_VAR (var);
- if (SSA_NAME_IS_DEFAULT_DEF (var)
- && TREE_CODE (sym) == PARM_DECL)
- {
- /* Try to use the "nonnull" attribute to create ~[0, 0]
- anti-ranges for pointers. Note that this is only valid with
- default definitions of PARM_DECLs. */
- if (POINTER_TYPE_P (TREE_TYPE (sym))
- && nonnull_arg_p (sym))
+ if (SSA_NAME_IS_DEFAULT_DEF (var))
+ {
+ if (TREE_CODE (sym) == PARM_DECL)
+ {
+ /* Try to use the "nonnull" attribute to create ~[0, 0]
+ anti-ranges for pointers. Note that this is only valid with
+ default definitions of PARM_DECLs. */
+ if (POINTER_TYPE_P (TREE_TYPE (sym))
+ && nonnull_arg_p (sym))
+ set_value_range_to_nonnull (vr, TREE_TYPE (sym));
+ else
+ set_value_range_to_varying (vr);
+ }
+ else if (TREE_CODE (sym) == RESULT_DECL
+ && DECL_BY_REFERENCE (sym))
set_value_range_to_nonnull (vr, TREE_TYPE (sym));
- else
- set_value_range_to_varying (vr);
}
return vr;