From patchwork Fri May 8 15:20:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Botcazou X-Patchwork-Id: 1286198 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=adacore-com.20150623.gappssmtp.com header.i=@adacore-com.20150623.gappssmtp.com header.a=rsa-sha256 header.s=20150623 header.b=aY4WVcBk; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49JZ1G6vNjz9sRY for ; Sat, 9 May 2020 01:26:26 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F1B2D3973047; Fri, 8 May 2020 15:26:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by sourceware.org (Postfix) with ESMTPS id 452423851C03 for ; Fri, 8 May 2020 15:26:05 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 452423851C03 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=botcazou@adacore.com Received: by mail-wm1-x330.google.com with SMTP id e26so10602936wmk.5 for ; Fri, 08 May 2020 08:26:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore-com.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=LXIy2R17e28N3v3dEtTP0SmNohDweoQNQJndLfjS46Q=; b=aY4WVcBk2LBL4Jp61L+x2zS4OKM9TK86wCiAh/EV5qMF61vCtg1xYDjScZHLY6o6IP mnSzh/3svv1DfAtEFkMA509BucE5aFWNDkXpVEotGtElFcuDLcyAhEvTOVnMxh8xQVFt bTUys83JPG89bSMTzoCRcK7mit3qMnAc5tIYMogU1WjRffC50Z7hmIwyd1FS2G0NE9RO lIjktrEWGHZ7BT8cLyhf+CSr0LtyM/80MK0CpyNVJWy/Cx0zpFSCOGxMlI88sHj7cRM6 5HeqtXRpj9cJpNc5QQ7gKzyYVCp3Jq3Pd9W4y/NWgF7zZmgHhe2YQS7tbLoZ2WBqCwqZ mu2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=LXIy2R17e28N3v3dEtTP0SmNohDweoQNQJndLfjS46Q=; b=oUJvTBHB+NJ2HsB5XFzxBbWfTV5766pxxnax2GnxvYWbPLtXFHsnyWKnCF916I0GIp D4SYlM8LlwHujeFnMldIgpKfNl3lCy2Gk/4V56Eghmb2v0jnCZe26brZFOj4O9tQVJs+ YyDZSN3Tuv8qtgHxPF+u/7ainS1rTLtPBAo14L0nihgwVS+io3OVsq3yLr8d2IGM2px2 uCtYtrncxuLvbvnacZzpg576kBBhvs9cc+0AymvBkF3qop6gICthAdWBfnI7NEyaC9wq 3xtkPLCv6E34Cc8xwzMcIeSVxL/mARAemg21yHkjyUCqsTy7xIReLn3dV1d2Y5P5+DBc RVJA== X-Gm-Message-State: AGi0PuYGlWpX8kjgskE6sidQ/zHT7GFxpXqU0VrUHQliZCUeGcFi6DGB qv857QTN3ITRQw+UHr28p73IwqOb4+Z7mQ== X-Google-Smtp-Source: APiQypLmiF8deoQ4utk4vmlt3fYvwzw91NnuhvOg/mBchB52sX1V3Eu5t3+NFjxt8shzmG73cSwUKg== X-Received: by 2002:a1c:492:: with SMTP id 140mr17504708wme.9.1588951563965; Fri, 08 May 2020 08:26:03 -0700 (PDT) Received: from polaris.localnet ([2a01:e0a:41b:9230:1a03:73ff:fe45:373a]) by smtp.gmail.com with ESMTPSA id b23sm11184625wmb.26.2020.05.08.08.26.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 08 May 2020 08:26:02 -0700 (PDT) From: Eric Botcazou X-Google-Original-From: Eric Botcazou To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix uniqueness of address for aliased objects Date: Fri, 08 May 2020 17:20:07 +0200 Message-ID: <12226560.lY36sMyjSC@polaris> MIME-Version: 1.0 X-Spam-Status: No, score=-12.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, GIT_PATCH_0, JMQ_SPF_NEUTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Two aliased objects must have distinct addresses, even if they have size zero, so we make sure to allocate at least one byte for them. Tested on x86-64/Linux, applied on the mainline. 2020-05-08 Eric Botcazou * gcc-interface/decl.c (gnat_to_gnu_entity) : Force at least the unit size for an aliased object of a constrained nominal subtype whose size is variable. 2020-05-08 Eric Botcazou * gnat.dg/addr15.adb: New test. diff --git a/gcc/ada/gcc-interface/decl.c b/gcc/ada/gcc-interface/decl.c index a4053eec839..9c1acd9f23f 100644 --- a/gcc/ada/gcc-interface/decl.c +++ b/gcc/ada/gcc-interface/decl.c @@ -969,10 +969,19 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) align = MINIMUM_ATOMIC_ALIGNMENT; #endif - /* Make a new type with the desired size and alignment, if needed. - But do not take into account alignment promotions to compute the - size of the object. */ + /* Do not take into account aliased adjustments or alignment promotions + to compute the size of the object. */ tree gnu_object_size = gnu_size ? gnu_size : TYPE_SIZE (gnu_type); + + /* If the object is aliased, of a constrained nominal subtype and its + size might be zero at run time, we force at least the unit size. */ + if (Is_Aliased (gnat_entity) + && !Is_Constr_Subt_For_UN_Aliased (gnat_type) + && Is_Array_Type (Underlying_Type (gnat_type)) + && !TREE_CONSTANT (gnu_object_size)) + gnu_size = size_binop (MAX_EXPR, gnu_object_size, bitsize_unit_node); + + /* Make a new type with the desired size and alignment, if needed. */ if (gnu_size || align > 0) { tree orig_type = gnu_type;