From patchwork Sat Sep 9 12:30:56 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 811955 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-461771-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="GKLSTeSD"; 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 3xqD7g4Gw9z9s75 for ; Sat, 9 Sep 2017 22:31:11 +1000 (AEST) 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=BPbKu5j25YSMdXih NK72vD0KrUW1xAkpMb8vHXdOxdQmMBQxVB7juIHlH5Pq+yFPTNDFZTIoDgQMC+dO HSICmMdCven6KYHFIO4z3K22SjQlejSd9wCapllyvSDptpi4Hp2o76X2b5QduDIt CEPeaDxSukYKyLjyGnbL0I3mjqE= 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=KHFpKKK4kSnh/Bn9SVLLcF DPaHA=; b=GKLSTeSDOYG+Mt8bGp7qH48lg3ze1UQ9SJM+JxIDkuKEsEDFzaSQ2d CpknAcA1PuMqSoLNZGrLDhzulhMtosvDQaLQ06zVoWQlLU2QPVngLoVKWJc4L0Et dsXR6Al1KwcbkaiU6xiWvroDfMMnw4sct9ndRv8sL08B6Et+VwMDY= Received: (qmail 53753 invoked by alias); 9 Sep 2017 12:31:04 -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 52086 invoked by uid 89); 9 Sep 2017 12:31:01 -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=enti 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; Sat, 09 Sep 2017 12:30:59 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 506A7822BB for ; Sat, 9 Sep 2017 14:30:57 +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 49o-gjUzTR6F for ; Sat, 9 Sep 2017 14:30:57 +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 1ABB082284 for ; Sat, 9 Sep 2017 14:30:57 +0200 (CEST) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Pragma Atomic wrongly rejected on composite component Date: Sat, 09 Sep 2017 14:30:56 +0200 Message-ID: <1672448.CyEKtT8OQq@polaris> User-Agent: KMail/4.14.10 (Linux/3.16.7-53-desktop; KDE/4.14.9; x86_64; ; ) MIME-Version: 1.0 The compiler wrongly rejects a pragma Atomic on a component of a record whose type is composite, but it accepts the pragma on a variable of the same type. Tested on x86_64-suse-linux, applied on the mainline and 7 branch. 2017-09-09 Eric Botcazou * gcc-interface/decl.c (promote_object_alignment): New function taken from... (gnat_to_gnu_entity) : ...here. Invoke it. (gnat_to_gnu_field): If the field is Atomic or VFA, invoke it and create a padding type on success before doing the atomic check. 2017-09-09 Eric Botcazou * gnat.dg/specs/atomic3.ads: New test. Index: gcc-interface/decl.c =================================================================== --- gcc-interface/decl.c (revision 251929) +++ gcc-interface/decl.c (working copy) @@ -230,6 +230,7 @@ static vec build_variant_l static tree validate_size (Uint, tree, Entity_Id, enum tree_code, bool, bool); static void set_rm_size (Uint, tree, Entity_Id); static unsigned int validate_alignment (Uint, Entity_Id, unsigned int); +static unsigned int promote_object_alignment (tree, Entity_Id); static void check_ok_for_atomic_type (tree, Entity_Id, bool); static tree create_field_decl_from (tree, tree, tree, tree, tree, vec); @@ -856,45 +857,7 @@ gnat_to_gnu_entity (Entity_Id gnat_entit && No (Renamed_Object (gnat_entity)) && No (Address_Clause (gnat_entity)))) && TREE_CODE (TYPE_SIZE (gnu_type)) == INTEGER_CST) - { - unsigned int size_cap, align_cap; - - /* No point in promoting the alignment if this doesn't prevent - BLKmode access to the object, in particular block copy, as - this will for example disable the NRV optimization for it. - No point in jumping through all the hoops needed in order - to support BIGGEST_ALIGNMENT if we don't really have to. - So we cap to the smallest alignment that corresponds to - a known efficient memory access pattern of the target. */ - if (Is_Atomic_Or_VFA (gnat_entity)) - { - size_cap = UINT_MAX; - align_cap = BIGGEST_ALIGNMENT; - } - else - { - size_cap = MAX_FIXED_MODE_SIZE; - align_cap = get_mode_alignment (ptr_mode); - } - - if (!tree_fits_uhwi_p (TYPE_SIZE (gnu_type)) - || compare_tree_int (TYPE_SIZE (gnu_type), size_cap) > 0) - align = 0; - else if (compare_tree_int (TYPE_SIZE (gnu_type), align_cap) > 0) - align = align_cap; - else - align = ceil_pow2 (tree_to_uhwi (TYPE_SIZE (gnu_type))); - - /* But make sure not to under-align the object. */ - if (align <= TYPE_ALIGN (gnu_type)) - align = 0; - - /* And honor the minimum valid atomic alignment, if any. */ -#ifdef MINIMUM_ATOMIC_ALIGNMENT - else if (align < MINIMUM_ATOMIC_ALIGNMENT) - align = MINIMUM_ATOMIC_ALIGNMENT; -#endif - } + align = promote_object_alignment (gnu_type, gnat_entity); /* If the object is set to have atomic components, find the component type and validate it. @@ -6891,7 +6854,15 @@ gnat_to_gnu_field (Entity_Id gnat_field, } if (Is_Atomic_Or_VFA (gnat_field)) - check_ok_for_atomic_type (gnu_field_type, gnat_field, false); + { + const unsigned int align + = promote_object_alignment (gnu_field_type, gnat_field); + if (align > 0) + gnu_field_type + = maybe_pad_type (gnu_field_type, NULL_TREE, align, gnat_field, + false, false, definition, true); + check_ok_for_atomic_type (gnu_field_type, gnat_field, false); + } if (Present (Component_Clause (gnat_field))) { @@ -8807,6 +8778,53 @@ validate_alignment (Uint alignment, Enti return align; } + +/* Promote the alignment of GNU_TYPE corresponding to GNAT_ENTITY. Return + a positive value on success or zero on failure. */ + +static unsigned int +promote_object_alignment (tree gnu_type, Entity_Id gnat_entity) +{ + unsigned int align, size_cap, align_cap; + + /* No point in promoting the alignment if this doesn't prevent BLKmode access + to the object, in particular block copy, as this will for example disable + the NRV optimization for it. No point in jumping through all the hoops + needed in order to support BIGGEST_ALIGNMENT if we don't really have to. + So we cap to the smallest alignment that corresponds to a known efficient + memory access pattern, except for Atomic and Volatile_Full_Access. */ + if (Is_Atomic_Or_VFA (gnat_entity)) + { + size_cap = UINT_MAX; + align_cap = BIGGEST_ALIGNMENT; + } + else + { + size_cap = MAX_FIXED_MODE_SIZE; + align_cap = get_mode_alignment (ptr_mode); + } + + /* Do the promotion within the above limits. */ + if (!tree_fits_uhwi_p (TYPE_SIZE (gnu_type)) + || compare_tree_int (TYPE_SIZE (gnu_type), size_cap) > 0) + align = 0; + else if (compare_tree_int (TYPE_SIZE (gnu_type), align_cap) > 0) + align = align_cap; + else + align = ceil_pow2 (tree_to_uhwi (TYPE_SIZE (gnu_type))); + + /* But make sure not to under-align the object. */ + if (align <= TYPE_ALIGN (gnu_type)) + align = 0; + + /* And honor the minimum valid atomic alignment, if any. */ +#ifdef MINIMUM_ATOMIC_ALIGNMENT + else if (align < MINIMUM_ATOMIC_ALIGNMENT) + align = MINIMUM_ATOMIC_ALIGNMENT; +#endif + + return align; +} /* Verify that TYPE is something we can implement atomically. If not, issue an error for GNAT_ENTITY. COMPONENT_P is true if we are being called to