From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 33590 invoked by alias); 5 Sep 2017 09:17:20 -0000 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 Received: (qmail 33554 invoked by uid 89); 5 Sep 2017 09:17:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=AWL,BAYES_00,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy= X-HELO: smtp.eu.adacore.com Received: from mel.act-europe.fr (HELO smtp.eu.adacore.com) (194.98.77.210) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Sep 2017 09:17:13 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id C544F822CA for ; Tue, 5 Sep 2017 11:17:10 +0200 (CEST) Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WcqT9liscpGA for ; Tue, 5 Sep 2017 11:17:10 +0200 (CEST) Received: from polaris.localnet (bon31-6-88-161-99-133.fbx.proxad.net [88.161.99.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id 94A1782266 for ; Tue, 5 Sep 2017 11:17:10 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix ICE on type witn zero precision Date: Tue, 05 Sep 2017 09:17:00 -0000 Message-ID: <2161599.Jq0VYmRpBJ@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1687800.tmyKgH94DP" Content-Transfer-Encoding: 7Bit X-SW-Source: 2017-09/txt/msg00229.txt.bz2 This is a multi-part message in MIME format. --nextPart1687800.tmyKgH94DP Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="us-ascii" Content-length: 525 This is a regression present on the mainline, 7 and 6 branches, in the form of an ICE during tree-ccp, which is confused by a type witn zero precision. Tested on x86_64-suse-linux, applied on mainline, 7 and 6 branches. 2017-09-05 Eric Botcazou * gcc-interface/utils.c (unchecked_convert): When the result type is a non-biased integral type with size 0, set the result to 0 directly. 2017-09-05 Eric Botcazou * gnat.dg/specs/uc2.ads: New test. -- Eric Botcazou --nextPart1687800.tmyKgH94DP Content-Disposition: attachment; filename="p.diff" Content-Transfer-Encoding: 7Bit Content-Type: text/x-patch; charset="UTF-8"; name="p.diff" Content-length: 1458 Index: gcc-interface/utils.c =================================================================== --- gcc-interface/utils.c (revision 251700) +++ gcc-interface/utils.c (working copy) @@ -5257,20 +5257,26 @@ unchecked_convert (tree type, tree expr, ? TYPE_RM_SIZE (etype) : TYPE_SIZE (etype)) == 0))) { - tree base_type - = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)), - type_unsigned_for_rm (type)); - tree shift_expr - = convert (base_type, - size_binop (MINUS_EXPR, - TYPE_SIZE (type), TYPE_RM_SIZE (type))); - expr - = convert (type, - build_binary_op (RSHIFT_EXPR, base_type, - build_binary_op (LSHIFT_EXPR, base_type, - convert (base_type, expr), - shift_expr), - shift_expr)); + if (integer_zerop (TYPE_RM_SIZE (type))) + expr = build_int_cst (type, 0); + else + { + tree base_type + = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)), + type_unsigned_for_rm (type)); + tree shift_expr + = convert (base_type, + size_binop (MINUS_EXPR, + TYPE_SIZE (type), TYPE_RM_SIZE (type))); + expr + = convert (type, + build_binary_op (RSHIFT_EXPR, base_type, + build_binary_op (LSHIFT_EXPR, base_type, + convert (base_type, + expr), + shift_expr), + shift_expr)); + } } /* An unchecked conversion should never raise Constraint_Error. The code --nextPart1687800.tmyKgH94DP Content-Disposition: attachment; filename="uc2.ads" Content-Transfer-Encoding: 7Bit Content-Type: text/x-adasrc; charset="UTF-8"; name="uc2.ads" Content-length: 354 -- { dg-do compile } -- { dg-options "-O" } with Ada.Unchecked_Conversion; package UC2 is subtype Word_Type is Integer range 0 .. 0; type Arr is array (1 .. Word_Type'Size) of Boolean; pragma Pack(Arr); function Conv is new Ada.Unchecked_Conversion (Source => Arr, Target => Word_Type); A : Arr; W : Word_Type := Conv(A); end UC2; --nextPart1687800.tmyKgH94DP--