[PATCH] Adjust integer <-> pointer conversion IL checking

Richard Biener rguenther@suse.de
Mon May 4 12:11:26 GMT 2020


This patch sits in my trees for quite some years and I always forget
to push it - it usually gets triggered by weird targets (PSImode
pointers/sizetype) which run into GIMPLE IL checking asserts for
pointer -> integer conversions and the "sizetype" special-case
not triggering.  That special-case should not exist but instead
it should be something like the patch below - the whole point
of the IL consistecy check is to ensure we know how to extend
from pointer to integer.

I've bootstrapped / tested the patch on x86_64 where it is a no-op.

But from the looks, can you punch any holes in it?  (it was able
to resolve reporters issues at least).

Thanks,
Richard.

-

The existing check doesn't reflect the actual reason why it exists,
the patch makes us to use POINTERS_EXTEND_UNSIGNED instead which
is specified for ptr_mode and word_mode/Pmode precision.

	* tree-cfg.c (verify_gimple_assign_unary): Adjust integer
	to/from pointer conversion checking.
---
 gcc/tree-cfg.c | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index e99fb9ff5d1..c6140af50e7 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -3591,13 +3591,21 @@ verify_gimple_assign_unary (gassign *stmt)
 	/* Allow conversions from pointer type to integral type only if
 	   there is no sign or zero extension involved.
 	   For targets were the precision of ptrofftype doesn't match that
-	   of pointers we need to allow arbitrary conversions to ptrofftype.  */
+	   of pointers we allow conversions to types where
+	   POINTERS_EXTEND_UNSIGNED specifies how that works.  */
 	if ((POINTER_TYPE_P (lhs_type)
 	     && INTEGRAL_TYPE_P (rhs1_type))
 	    || (POINTER_TYPE_P (rhs1_type)
 		&& INTEGRAL_TYPE_P (lhs_type)
 		&& (TYPE_PRECISION (rhs1_type) >= TYPE_PRECISION (lhs_type)
-		    || ptrofftype_p (lhs_type))))
+#if defined(POINTERS_EXTEND_UNSIGNED)
+		    || (TYPE_MODE (rhs1_type) == ptr_mode
+			&& (TYPE_PRECISION (lhs_type)
+			      == BITS_PER_WORD /* word_mode */
+			    || (TYPE_PRECISION (lhs_type)
+				  == GET_MODE_PRECISION (Pmode))))
+#endif
+		   )))
 	  return false;
 
 	/* Allow conversion from integral to offset type and vice versa.  */
-- 
2.16.4


More information about the Gcc-patches mailing list