--- gcc/c/c-typeck.c.jj	2012-12-07 17:08:05.391996135 +0100
+++ gcc/c/c-typeck.c	2012-12-07 17:31:11.831147409 +0100
@@ -5543,8 +5543,10 @@ convert_for_assignment (location_t locat
       if (VOID_TYPE_P (ttl) || VOID_TYPE_P (ttr)
 	  || (target_cmp = comp_target_types (location, type, rhstype))
 	  || is_opaque_pointer
-	  || (c_common_unsigned_type (mvl)
-	      == c_common_unsigned_type (mvr)))
+	  || ((c_common_unsigned_type (mvl)
+	       == c_common_unsigned_type (mvr))
+	      && c_common_signed_type (mvl)
+		 == c_common_signed_type (mvr)))
 	{
 	  if (pedantic
 	      && ((VOID_TYPE_P (ttl) && TREE_CODE (ttr) == FUNCTION_TYPE)
--- gcc/testsuite/gcc.dg/pr39464.c.jj	2012-12-07 17:19:33.885125923 +0100
+++ gcc/testsuite/gcc.dg/pr39464.c	2012-12-07 17:33:14.000000000 +0100
@@ -0,0 +1,19 @@
+/* PR c/39464 */
+/* { dg-do compile } */
+/* { dg-options "-Wall" } */
+
+typedef int T __attribute__((may_alias));
+typedef unsigned int U __attribute__((may_alias));
+
+void
+foo (void *p)
+{
+  T *a = (int *) p;		/* { dg-warning "initialization from incompatible pointer type" } */
+  int *b = (T *) p;		/* { dg-warning "initialization from incompatible pointer type" } */
+  U *c = (unsigned int *) p;	/* { dg-warning "initialization from incompatible pointer type" } */
+  unsigned int *d = (U *) p;	/* { dg-warning "initialization from incompatible pointer type" } */
+  (void) a;
+  (void) b;
+  (void) c;
+  (void) d;
+}
