From patchwork Fri May 22 12:45:22 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 475595 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id D7BB0140D3F for ; Fri, 22 May 2015 22:45:33 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=aW/odgY9; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; q=dns; s=default; b=jF1hgToQV/IqdSQl2cXoj549mphy4XZztSNQ3Wj5Bpn+gsV4Lj +CwK1W/6zxVPEvoUepMAskTi+96oQUnTgcpgWsqiJaM0qfhN2lJoaqY91quhzUFk Zxvp5FHQIbm63/ATyc/1Yf317aSznvBwFg81mYUQzEq2V5BqdarhJiOu0= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:cc:subject:message-id:mime-version:content-type; s= default; bh=2tqJ7OYTcZH6JQmbgvPpzJWj/Wg=; b=aW/odgY9oIsB/CM3UUji d9HHOhQzbmaaqOhe5IzDJYiPGFCdgd6iLiXgvdrindn4bc5GNOuo54d52JjDlaYq FeJf7hIwlyhgsQ/ZHy9yyBI183dmdJMn87PGI+MHbHAsT5Xj0imyRGMR9z1fbKdp A9wN+QFnQJ1zys8cHSq80ps= Received: (qmail 85354 invoked by alias); 22 May 2015 12:45:25 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 85321 invoked by uid 89); 22 May 2015 12:45:25 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.3 required=5.0 tests=AWL, BAYES_40, KAM_LAZY_DOMAIN_SECURITY autolearn=no version=3.3.2 X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-SHA encrypted) ESMTPS; Fri, 22 May 2015 12:45:24 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 4F5B128CF9; Fri, 22 May 2015 08:45:22 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 889NgCUz4RQm; Fri, 22 May 2015 08:45:22 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 3EF3C286C4; Fri, 22 May 2015 08:45:22 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 3AEFC439C4; Fri, 22 May 2015 08:45:22 -0400 (EDT) Date: Fri, 22 May 2015 08:45:22 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Small enhancement to unchecked conversion warning in -gnatf mode Message-ID: <20150522124522.GA4926@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) In full warning mode, when an unchecked conversion is applied to types of different sizes, the compiler issues a warning describing the effects of the conversion on the additional or missing bits. When the source is smaller than the target, it was issuing a specific warning if the target is of a discrete type but, when the source is larger than the target, it wasn't doing the same if the source is of a discrete type. The compiler must issue the following warnings with -gnatf: ucw.ads:12:03: warning: types for unchecked conversion have different sizes ucw.ads:12:03: warning: size of "REC" is 16, size of "INTEGER" is 32 ucw.ads:12:03: warning: target value will include 16 undefined high order bits ucw.ads:13:03: warning: types for unchecked conversion have different sizes ucw.ads:13:03: warning: size of "INTEGER" is 32, size of "REC" is 16 ucw.ads:13:03: warning: 16 high order bits of source will be ignored on with Unchecked_Conversion; package UCW is type Int8_t is mod 2**8; type Rec is record I1 : Int8_t; I2 : Int8_t; end record; function C1 is new Unchecked_Conversion (Source => Rec, Target => Integer); function C2 is new Unchecked_Conversion (Source => Integer, Target => Rec); end UCW; Tested on x86_64-pc-linux-gnu, committed on trunk 2015-05-22 Eric Botcazou * sem_ch13.adb (Validate_Unchecked_Conversions): Also issue specific warning for discrete types when the source is larger than the target. Index: sem_ch13.adb =================================================================== --- sem_ch13.adb (revision 223534) +++ sem_ch13.adb (working copy) @@ -13483,9 +13483,22 @@ end if; else pragma Assert (Source_Siz > Target_Siz); - Error_Msg - ("\?z?^ trailing bits of source will be ignored!", - Eloc); + if Is_Discrete_Type (Source) then + if Bytes_Big_Endian then + Error_Msg + ("\?z?^ low order bits of source will be " + & "ignored!", Eloc); + else + Error_Msg + ("\?z?^ high order bits of source will be " + & "ignored!", Eloc); + end if; + + else + Error_Msg + ("\?z?^ trailing bits of source will be " + & "ignored!", Eloc); + end if; end if; end if; end if;