This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[patch] tree-vrp.c: Work around a bug in the front end thatproduces a comparison of mismatched types.


Hi,

Attached is a patch to work around a bug in the front end that
produces a comparison of mismatched types.

For an analysis of this bug, please refer to PR 21021.  Meanwhile,
I'll continue to look for the real cause (and a real fix).

Tested on i686-pc-linux-gnu.  OK to apply?

Kazu Hirata

2005-04-14  Kazu Hirata  <kazu@cs.umass.edu>

	PR tree-optimization/21021
	* tree-vrp.c (compare_values): Work around a bug in the front
	end that produces a comparison of mismatched types.

Index: tree-vrp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-vrp.c,v
retrieving revision 2.7
diff -c -d -p -r2.7 tree-vrp.c
*** tree-vrp.c	14 Apr 2005 13:34:28 -0000	2.7
--- tree-vrp.c	14 Apr 2005 17:19:13 -0000
*************** compare_values (tree val1, tree val2)
*** 287,293 ****
      return 0;
  
    /* Do some limited symbolic comparisons.  */
!   if (!POINTER_TYPE_P (TREE_TYPE (val1)))
      {
        /* We can determine some comparisons against +INF and -INF even
  	 if the other value is an expression.  */
--- 287,299 ----
      return 0;
  
    /* Do some limited symbolic comparisons.  */
!   /* FIXME: The second check of POINTER_TYPE_P should not be necessary
!      because we should be comparing values of the same type here, but
!      for whatever reason, the front end throws us a type mismatched
!      comparison.  For now, work around the problem by checking both
!      types.  See PR 21021 and PR 21024.  */
!   if (!POINTER_TYPE_P (TREE_TYPE (val1))
!       && !POINTER_TYPE_P (TREE_TYPE (val2)))
      {
        /* We can determine some comparisons against +INF and -INF even
  	 if the other value is an expression.  */
*************** compare_values (tree val1, tree val2)
*** 400,406 ****
    if (!is_gimple_min_invariant (val1) || !is_gimple_min_invariant (val2))
      return -2;
  
!   if (!POINTER_TYPE_P (TREE_TYPE (val1)))
      return tree_int_cst_compare (val1, val2);
    else
      {
--- 406,418 ----
    if (!is_gimple_min_invariant (val1) || !is_gimple_min_invariant (val2))
      return -2;
  
!   /* FIXME: The second check of POINTER_TYPE_P should not be necessary
!      because we should be comparing values of the same type here, but
!      for whatever reason, the front end throws us a type mismatched
!      comparison.  For now, work around the problem by checking both
!      types.  See PR 21021 and PR 21024.  */
!   if (!POINTER_TYPE_P (TREE_TYPE (val1))
!       && !POINTER_TYPE_P (TREE_TYPE (val2)))
      return tree_int_cst_compare (val1, val2);
    else
      {
--- /dev/null	2005-04-13 14:59:22.325563136 -0400
+++ testsuite/gcc.c-torture/compile/pr21021.c	2005-04-14 13:26:54.000000000 -0400
@@ -0,0 +1,19 @@
+/* PR tree-optimization/21021
+
+   The front end produces a comparison of mismatched types, namely an
+   integer and a pointer, causing VRP to compute TYPE_MAX_VALUE for a
+   pointer, which we cannot.  */
+
+extern void *bar (void);
+
+int
+foo (unsigned int *p, unsigned int *q)
+{
+  const void *r = bar ();
+
+  if (r >= (const void *) *p
+      && r < (const void *) *q)
+    return 1;
+
+  return 0;
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]