From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24816 invoked by alias); 7 Dec 2012 19:44:53 -0000 Received: (qmail 24807 invoked by uid 22791); 7 Dec 2012 19:44:52 -0000 X-SWARE-Spam-Status: No, hits=-6.2 required=5.0 tests=AWL,BAYES_00,KHOP_RCVD_UNTRUST,RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,SPF_HELO_PASS,TW_MV X-Spam-Check-By: sourceware.org Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Fri, 07 Dec 2012 19:44:41 +0000 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id qB7JidZX019608 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Fri, 7 Dec 2012 14:44:40 -0500 Received: from zalov.redhat.com (vpn1-4-240.ams2.redhat.com [10.36.4.240]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id qB7JicKW026773 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Fri, 7 Dec 2012 14:44:39 -0500 Received: from zalov.cz (localhost [127.0.0.1]) by zalov.redhat.com (8.14.5/8.14.5) with ESMTP id qB7Jib2A024583; Fri, 7 Dec 2012 20:44:37 +0100 Received: (from jakub@localhost) by zalov.cz (8.14.5/8.14.5/Submit) id qB7Jia1M024582; Fri, 7 Dec 2012 20:44:36 +0100 Date: Fri, 07 Dec 2012 19:44:00 -0000 From: Jakub Jelinek To: "Joseph S. Myers" Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] Fix up convert_for_assignment warnings (PR c/39464) Message-ID: <20121207194436.GC2315@tucnak.redhat.com> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org X-SW-Source: 2012-12/txt/msg00523.txt.bz2 Hi! As the testcase shows, for implicit conversions between signed integer and signed integer with some attribute that makes it a distinct type from that such as may_alias attribute, we warn that the pointer targets differ in signedness, even when they have the same size. For similar unsigned integer vs. unsigned integer with attribute we warn about initialization from incompatible pointer type. This patch ensures we treat the former as the latter. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2012-12-07 Jakub Jelinek PR c/39464 * c-typeck.c (convert_for_assignment): For -Wpointer-sign warning require that both c_common_unsigned_type as well as c_common_signed_type is the same for both mvl and mvr types. * gcc.dg/pr39464.c: New test. --- 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; +} Jakub