From patchwork Fri Dec 14 10:54:01 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1013472 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-492468-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="KQZXIwwk"; 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 43GS933c2wz9s4s for ; Fri, 14 Dec 2018 21:54:14 +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=BGTq1V6LYTt6//Cs GAgd01M2VT7npOLaMmXNlvAyj3pnkDVldZDdUvWI0DkCractgxjqyHpRDa9mIYdU BJJSP04WW64A882+YL4Hma+aOwxH87bnKFkcKOrCc2tnXjLH08YscFjysJiquxPK 7KyK4DlyI+mMNFVFKXckNhwh4JI= 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=f+x6ILB1b82a/2YHvn5IrM n+DMk=; b=KQZXIwwkmMXb+13XuBaNLT/sRrFEChdP95AH9gwxbYtsidSMCJ/YEe AHRfX3A0A2YaJOgTOrWgXT3Asey/PXzYMY1xHOPaa6emOuztDA3MGbxfpI6raRR5 5+Z94VDWmKe+51F4GL24EubC3jBKE9JxWK/n44SGeSXY4rc/UGByE= Received: (qmail 27680 invoked by alias); 14 Dec 2018 10:54:07 -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 27665 invoked by uid 89); 14 Dec 2018 10:54:06 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=binfo, Small, comparisons, sk:ebotcaz 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; Fri, 14 Dec 2018 10:54:04 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id F19B181398 for ; Fri, 14 Dec 2018 11:54:01 +0100 (CET) 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 MpD19EdSMuSf for ; Fri, 14 Dec 2018 11:54:01 +0100 (CET) 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 C8D79812EF for ; Fri, 14 Dec 2018 11:54:01 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Small fix for records with boolean discriminants Date: Fri, 14 Dec 2018 11:54:01 +0100 Message-ID: <20065154.R3ZBKFATig@polaris> MIME-Version: 1.0 The point is to avoid building comparisons of the form "D == true" in this case for the qualifiers of the union describing the variant part because 1) it's useless and 2) it's output as "D = 1" by -gnatR, which is not valid Ada. The dwarf2out.c change only affects the Ada compiler. Tested on x86_64-suse-linux, applied on the mainline as obvious. 2018-12-14 Eric Botcazou * dwarf2out.c (analyze_discr_in_predicate): Simplify. (analyze_variants_discr): Deal with naked boolean discriminants. ada/ * gcc-interface/decl.c (choices_to_gnu): Directly use a naked boolean discriminant if the value is the boolean true. Index: dwarf2out.c =================================================================== --- dwarf2out.c (revision 267062) +++ dwarf2out.c (working copy) @@ -24537,6 +24537,7 @@ gen_inheritance_die (tree binfo, tree ac /* Return whether DECL is a FIELD_DECL that represents the variant part of a structure. */ + static bool is_variant_part (tree decl) { @@ -24550,17 +24551,8 @@ is_variant_part (tree decl) static tree analyze_discr_in_predicate (tree operand, tree struct_type) { - bool continue_stripping = true; - while (continue_stripping) - switch (TREE_CODE (operand)) - { - CASE_CONVERT: - operand = TREE_OPERAND (operand, 0); - break; - default: - continue_stripping = false; - break; - } + while (CONVERT_EXPR_P (operand)) + operand = TREE_OPERAND (operand, 0); /* Match field access to members of struct_type only. */ if (TREE_CODE (operand) == COMPONENT_REF @@ -24780,6 +24772,19 @@ analyze_variants_discr (tree variant_par new_node->dw_discr_range = true; } + else if ((candidate_discr + = analyze_discr_in_predicate (match_expr, struct_type)) + && TREE_TYPE (candidate_discr) == boolean_type_node) + { + /* We are matching: for a boolean discriminant. + This sub-expression matches boolean_true_node. */ + new_node = ggc_cleared_alloc (); + if (!get_discr_value (boolean_true_node, + &new_node->dw_discr_lower_bound)) + goto abort; + new_node->dw_discr_range = false; + } + else /* Unsupported sub-expression: we cannot determine the set of matching discriminant values. Abort everything. */ Index: ada/gcc-interface/decl.c =================================================================== --- ada/gcc-interface/decl.c (revision 267062) +++ ada/gcc-interface/decl.c (working copy) @@ -6848,6 +6848,9 @@ choices_to_gnu (tree gnu_operand, Node_I build_binary_op (LE_EXPR, boolean_type_node, gnu_operand, gnu_high, true), true); + else if (gnu_low == boolean_true_node + && TREE_TYPE (gnu_operand) == boolean_type_node) + gnu_test = gnu_operand; else if (gnu_low) gnu_test = build_binary_op (EQ_EXPR, boolean_type_node, gnu_operand, gnu_low,