From patchwork Sat Jan 26 16:04:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1031458 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-494779-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="FG5SwfTA"; 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 43n1134l0xz9sDB for ; Sun, 27 Jan 2019 03:04:22 +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=FAopmN7PWMb9iUJd VXIq8EmxiLzAuhrkEIR6IlRXYkZWjB5BLqUv2x/WTdyciN/AcYGLYVsP/oRCUf6d ps0PkwIqaW/PG4MDy3XuI+7+F1PnTQJUsQuxgxSERgdsD6G2N14U+p3a/5QmuQih yLzysWX0v/9PhR1FliHWvqgPFaU= 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=c2St3f1n3I0hzXWHEehrbO UI0p0=; b=FG5SwfTANtbQeNsGIG6bFgM8+mwdPzIcHwBKcnzTj2jYpZTaXBcPJh +yG5uyCKK+KYVXKg8Ab9eGDAuI5at07WI8i7CwLEaP5I3zjvpzlqos2H23srQC6o 3SRbDN+yeccvcDDQlrYF15nW1Ov1fqAtEa4s1cguTR+FRtu5LwT9g= Received: (qmail 40899 invoked by alias); 26 Jan 2019 16:04:15 -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 40888 invoked by uid 89); 26 Jan 2019 16:04:15 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS, UNSUBSCRIBE_BODY autolearn=ham version=3.3.2 spammy=ra, UD:B 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, 26 Jan 2019 16:04:13 +0000 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id 56CA98138E for ; Sat, 26 Jan 2019 17:04:11 +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 L5WPOYhv0uEk for ; Sat, 26 Jan 2019 17:04:11 +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 2D1EC8138B for ; Sat, 26 Jan 2019 17:04:11 +0100 (CET) From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix wrong assignment of overaligned array component Date: Sat, 26 Jan 2019 17:04:10 +0100 Message-ID: <1837832.mtSFLPvUZp@polaris> MIME-Version: 1.0 This is a regression present on all active branches: under a specific set of circumstances, the compiler generate wrong code for the assignment of an array component of a record type, when the nominal subtype of the component is an array type with an alignment clause that specifies a larger alignment than the natural one. Tested on x86_64-suse-linux, applied on all active branches. 2019-01-26 Eric Botcazou * gcc-interface/trans.c (gnat_to_gnu) : Use DECL_SIZE_UNIT instead of TYPE_SIZE_UNIT for the size to be assigned by a call to memset if the LHS is a DECL. 2019-01-26 Eric Botcazou * gnat.dg/array34.adb: New test. Index: gcc-interface/trans.c =================================================================== --- gcc-interface/trans.c (revision 335507) +++ gcc-interface/trans.c (revision 335508) @@ -7754,12 +7754,17 @@ gnat_to_gnu (Node_Id gnat_node) = real_zerop (gnu_rhs) ? integer_zero_node : fold_convert (integer_type_node, gnu_rhs); - tree to = gnu_lhs; - tree type = TREE_TYPE (to); - tree size - = SUBSTITUTE_PLACEHOLDER_IN_EXPR (TYPE_SIZE_UNIT (type), to); - tree to_ptr = build_fold_addr_expr (to); + tree dest = build_fold_addr_expr (gnu_lhs); tree t = builtin_decl_explicit (BUILT_IN_MEMSET); + /* Be extra careful not to write too much data. */ + tree size; + if (TREE_CODE (gnu_lhs) == COMPONENT_REF) + size = DECL_SIZE_UNIT (TREE_OPERAND (gnu_lhs, 1)); + else if (DECL_P (gnu_lhs)) + size = DECL_SIZE_UNIT (gnu_lhs); + else + size = TYPE_SIZE_UNIT (TREE_TYPE (gnu_lhs)); + size = SUBSTITUTE_PLACEHOLDER_IN_EXPR (size, gnu_lhs); if (TREE_CODE (value) == INTEGER_CST && !integer_zerop (value)) { tree mask @@ -7767,7 +7772,7 @@ gnat_to_gnu (Node_Id gnat_node) ((HOST_WIDE_INT) 1 << BITS_PER_UNIT) - 1); value = int_const_binop (BIT_AND_EXPR, value, mask); } - gnu_result = build_call_expr (t, 3, to_ptr, value, size); + gnu_result = build_call_expr (t, 3, dest, value, size); } /* Otherwise build a regular assignment. */