[tuples] dereference POINTER_PLUS_EXPR check

Aldy Hernandez aldyh@redhat.com
Wed Nov 21 23:25:00 GMT 2007


> Maybe we could make this a helper in tree.c.  Something like 
> pointed_to_type().  I don't think one exists already, but I may be wrong.

Things are a bit cleaner now too, bonus!

Is this OK?

	* tree.c (pointed_to_type): New.
	* tree.h (pointed_to_type): Protoize.
	* tree-cfg.c (verify_types_in_gimple_assign): Use the dereferenced
	type when checking the validity of a POINTER_PLUS_EXPR.

Index: tree.c
===================================================================
--- tree.c	(revision 130313)
+++ tree.c	(working copy)
@@ -8833,4 +8833,14 @@ block_nonartificial_location (tree block
   return ret;
 }
 
+/* Given a tree type T, drill down to the type it points to and return
+   it.  */
+tree
+pointed_to_type (tree t)
+{
+  while (POINTER_TYPE_P (t) || TREE_CODE (t) == ARRAY_TYPE)
+    t = TREE_TYPE (t);
+  return t;
+}
+
 #include "gt-tree.h"
Index: tree.h
===================================================================
--- tree.h	(revision 130313)
+++ tree.h	(working copy)
@@ -4918,6 +4918,7 @@ extern tree *tree_block (tree);
 extern tree *generic_tree_operand (tree, int);
 extern tree *generic_tree_type (tree);
 extern location_t *block_nonartificial_location (tree);
+extern tree pointed_to_type (tree);
 
 /* In function.c */
 extern void expand_main_function (void);
Index: tree-cfg.c
===================================================================
--- tree-cfg.c	(revision 130313)
+++ tree-cfg.c	(working copy)
@@ -3558,8 +3558,16 @@ verify_types_in_gimple_assign (gimple st
 	    error ("invalid operands in pointer plus expression");
 	    return true;
 	  }
-	if (!POINTER_TYPE_P (rhs1_type)
-	    || !useless_type_conversion_p (lhs_type, rhs1_type)
+
+	if (!POINTER_TYPE_P (lhs_type)
+	    || !POINTER_TYPE_P (rhs1_type))
+	  {
+	    error ("type mismatch in pointer plus expression");
+	    return true;
+	  }
+
+	if (!useless_type_conversion_p (pointed_to_type (lhs_type),
+					pointed_to_type (rhs1_type))
 	    || !useless_type_conversion_p (sizetype, rhs2_type))
 	  {
 	    error ("type mismatch in pointer plus expression");



More information about the Gcc-patches mailing list