From patchwork Mon Oct 22 11:09:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 987587 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-488013-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="NjDlpi8N"; dkim-atps=neutral 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 42dvBf3mf5z9sCh for ; Mon, 22 Oct 2018 22:17:45 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; q=dns; s=default; b=wlprYMuQkf9SL8P2 4Tbrb8JaD+9KOMBrvdp1XzWZfXVI5twFxE9Iu9w8lRA6eVzAhfoyVJNsqxbrV6fh GOWpDjxgr0LtuXzP2vnFUa+vBQJ2U99e8eH6fMwSrm/jnqrjrpyiXE+/088NdBNj rln0sSTrDS9qSkS6Bj7Pjvh3e4A= 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:from :to:subject:date:message-id:mime-version:content-type :content-transfer-encoding; s=default; bh=y8/Ch7KD4piOcfnoJyMWYe c0ono=; b=NjDlpi8NAV/8HZuqTXTSLaRGu513oelh91Q96TamYCnoswiunz/ueP eFQkot0q10MiOEDQfCMljlEvys8wn9Y3Ih/iP+y9XztTq2vVPPElVSscCm06fdTi on7XBzm6fRN+p9VRR+w0O3tIcekap6L2/RbtpmCN8N7lZv+zxincY= Received: (qmail 46977 invoked by alias); 22 Oct 2018 11:11:12 -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 45611 invoked by uid 89); 22 Oct 2018 11:09:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 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=gnatdg, considerations, gnat.dg, rtype 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; Mon, 22 Oct 2018 11:09:42 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 260FF81387 for ; Mon, 22 Oct 2018 13:09:40 +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 LNos2IlRQqb8 for ; Mon, 22 Oct 2018 13:09:40 +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 EA3A681353 for ; Mon, 22 Oct 2018 13:09:39 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix Unchecked_Conversion between FP and rev SSO Date: Mon, 22 Oct 2018 13:09:37 +0200 Message-ID: <3040993.2Tl05FCGrf@polaris> MIME-Version: 1.0 This extends the treatment of Unchecked_Conversion between integral types and aggregates types with reverse scalar storage order to floating-point types. Tested on x86_64-suse-linux, applied on mainline, 8 and 7 branches. 2018-10-22 Eric Botcazou * gcc-interface/utils.c (unchecked_convert): Use local variables for the biased and reverse SSO attributes of both types. Further extend the processing of integral types in the presence of reverse SSO to all scalar types. 2018-10-22 Eric Botcazou * gnat.dg/sso14.adb: New test. * gnat.dg/sso15.adb: Likewise. Index: gcc-interface/utils.c =================================================================== --- gcc-interface/utils.c (revision 265367) +++ gcc-interface/utils.c (working copy) @@ -5092,8 +5092,16 @@ unchecked_convert (tree type, tree expr, tree etype = TREE_TYPE (expr); enum tree_code ecode = TREE_CODE (etype); enum tree_code code = TREE_CODE (type); + const bool ebiased + = (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)); + const bool biased + = (code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)); + const bool ereverse + = (AGGREGATE_TYPE_P (etype) && TYPE_REVERSE_STORAGE_ORDER (etype)); + const bool reverse + = (AGGREGATE_TYPE_P (type) && TYPE_REVERSE_STORAGE_ORDER (type)); tree tem; - int c; + int c = 0; /* If the expression is already of the right type, we are done. */ if (etype == type) @@ -5109,7 +5117,7 @@ unchecked_convert (tree type, tree expr, || (ecode == RECORD_TYPE && TYPE_JUSTIFIED_MODULAR_P (etype)))) || code == UNCONSTRAINED_ARRAY_TYPE) { - if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype)) + if (ebiased) { tree ntype = copy_type (etype); TYPE_BIASED_REPRESENTATION_P (ntype) = 0; @@ -5117,7 +5125,7 @@ unchecked_convert (tree type, tree expr, expr = build1 (NOP_EXPR, ntype, expr); } - if (code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)) + if (biased) { tree rtype = copy_type (type); TYPE_BIASED_REPRESENTATION_P (rtype) = 0; @@ -5146,30 +5154,35 @@ unchecked_convert (tree type, tree expr, Finally, for the sake of consistency, we do the unchecked conversion to an integral type with reverse storage order as soon as the source type is an aggregate type with reverse storage order, even if there - are no considerations of precision or size involved. */ - else if (INTEGRAL_TYPE_P (type) - && TYPE_RM_SIZE (type) - && (tree_int_cst_compare (TYPE_RM_SIZE (type), - TYPE_SIZE (type)) < 0 - || (AGGREGATE_TYPE_P (etype) - && TYPE_REVERSE_STORAGE_ORDER (etype)))) + are no considerations of precision or size involved. Ultimately, we + further extend this processing to any scalar type. */ + else if ((INTEGRAL_TYPE_P (type) + && TYPE_RM_SIZE (type) + && ((c = tree_int_cst_compare (TYPE_RM_SIZE (type), + TYPE_SIZE (type))) < 0 + || ereverse)) + || (SCALAR_FLOAT_TYPE_P (type) && ereverse)) { tree rec_type = make_node (RECORD_TYPE); - unsigned HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_RM_SIZE (type)); tree field_type, field; - if (AGGREGATE_TYPE_P (etype)) - TYPE_REVERSE_STORAGE_ORDER (rec_type) - = TYPE_REVERSE_STORAGE_ORDER (etype); + TYPE_REVERSE_STORAGE_ORDER (rec_type) = ereverse; - if (type_unsigned_for_rm (type)) - field_type = make_unsigned_type (prec); + if (c < 0) + { + const unsigned HOST_WIDE_INT prec + = TREE_INT_CST_LOW (TYPE_RM_SIZE (type)); + if (type_unsigned_for_rm (type)) + field_type = make_unsigned_type (prec); + else + field_type = make_signed_type (prec); + SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (type)); + } else - field_type = make_signed_type (prec); - SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (type)); + field_type = type; field = create_field_decl (get_identifier ("OBJ"), field_type, rec_type, - NULL_TREE, bitsize_zero_node, 1, 0); + NULL_TREE, bitsize_zero_node, c < 0, 0); finish_record_type (rec_type, field, 1, false); @@ -5184,31 +5197,35 @@ unchecked_convert (tree type, tree expr, The same considerations as above apply if the target type is an aggregate type with reverse storage order and we also proceed similarly. */ - else if (INTEGRAL_TYPE_P (etype) - && TYPE_RM_SIZE (etype) - && (tree_int_cst_compare (TYPE_RM_SIZE (etype), - TYPE_SIZE (etype)) < 0 - || (AGGREGATE_TYPE_P (type) - && TYPE_REVERSE_STORAGE_ORDER (type)))) + else if ((INTEGRAL_TYPE_P (etype) + && TYPE_RM_SIZE (etype) + && ((c = tree_int_cst_compare (TYPE_RM_SIZE (etype), + TYPE_SIZE (etype))) < 0 + || reverse)) + || (SCALAR_FLOAT_TYPE_P (etype) && reverse)) { tree rec_type = make_node (RECORD_TYPE); - unsigned HOST_WIDE_INT prec = TREE_INT_CST_LOW (TYPE_RM_SIZE (etype)); vec *v; vec_alloc (v, 1); tree field_type, field; - if (AGGREGATE_TYPE_P (type)) - TYPE_REVERSE_STORAGE_ORDER (rec_type) - = TYPE_REVERSE_STORAGE_ORDER (type); + TYPE_REVERSE_STORAGE_ORDER (rec_type) = reverse; - if (type_unsigned_for_rm (etype)) - field_type = make_unsigned_type (prec); + if (c < 0) + { + const unsigned HOST_WIDE_INT prec + = TREE_INT_CST_LOW (TYPE_RM_SIZE (etype)); + if (type_unsigned_for_rm (etype)) + field_type = make_unsigned_type (prec); + else + field_type = make_signed_type (prec); + SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (etype)); + } else - field_type = make_signed_type (prec); - SET_TYPE_RM_SIZE (field_type, TYPE_RM_SIZE (etype)); + field_type = etype; field = create_field_decl (get_identifier ("OBJ"), field_type, rec_type, - NULL_TREE, bitsize_zero_node, 1, 0); + NULL_TREE, bitsize_zero_node, c < 0, 0); finish_record_type (rec_type, field, 1, false); @@ -5308,8 +5325,8 @@ unchecked_convert (tree type, tree expr, signed and have the same precision. */ tree type_rm_size; if (!notrunc_p + && !biased && INTEGRAL_TYPE_P (type) - && !(code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type)) && (type_rm_size = TYPE_RM_SIZE (type)) && tree_int_cst_compare (type_rm_size, TYPE_SIZE (type)) < 0 && !(INTEGRAL_TYPE_P (etype)