From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-ej1-x62c.google.com (mail-ej1-x62c.google.com [IPv6:2a00:1450:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id C0EA83851404 for ; Wed, 13 Jul 2022 10:03:01 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org C0EA83851404 Received: by mail-ej1-x62c.google.com with SMTP id z23so2388556eju.8 for ; Wed, 13 Jul 2022 03:03:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=NER4nMLy+U1y383UWOzqwali56clXXhs454iSyubrJk=; b=I489tqGMbxJxbUanTQxn69B6zCCeisV+ZhuJVMk7qokU2mMjhxl5XpH9L58RqNsxne Lrt3MzatnYCrjS7CqgMzHvjGkijmG0pu7QXOPFoflcy3dd6v9V4j72tV86HK9rjitcHI /oy5GUqgpPVNpAfp3GSTqeUeIBZcJZDVBiYDAA3gQDdKPH2ohVZbf54eOaKY2WiDKihE LXVEGW3lZEzyCZ6jJ0GlBVlmKjHrydAnAzI+Wr4pPMsMFOpP+LQvpLNA68PolzbWzeK4 Sv/pEnXKPWJF6HIYfTM7BY5rolgQppzL8ZVOrrvradgpPfNPzyOAiX86VuUQRphoj2yd HpXA== X-Gm-Message-State: AJIora93htH4EPdZDho8z6F8JgFEM3ITtUQJUqZ1PfRUfqPA1K95Kxgu ivhPlUvU4nWQ4GklIMcg29SrUjxM4g+hJg== X-Google-Smtp-Source: AGRyM1ts5HMqNJ6ytLCcMbXlNpMWQvXmOL7k731wARnBTlAJrlVX8fABLVDM5cdrWpyu7mx5EmcM6A== X-Received: by 2002:a17:906:98c8:b0:72b:408f:f499 with SMTP id zd8-20020a17090698c800b0072b408ff499mr2624488ejb.736.1657706580477; Wed, 13 Jul 2022 03:03:00 -0700 (PDT) Received: from adacore.com ([45.147.211.82]) by smtp.gmail.com with ESMTPSA id x19-20020aa7cd93000000b0043a3b90748asm7627981edv.26.2022.07.13.03.02.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Jul 2022 03:02:59 -0700 (PDT) Date: Wed, 13 Jul 2022 10:02:59 +0000 From: Pierre-Marie de Rodat To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [Ada] Fix wrong access check with access-to-unconstrained-array Message-ID: <20220713100259.GA994723@adacore.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ZGiS0Q5IWpPtfppv" Content-Disposition: inline X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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: , X-List-Received-Date: Wed, 13 Jul 2022 10:03:03 -0000 --ZGiS0Q5IWpPtfppv Content-Type: text/plain; charset=us-ascii Content-Disposition: inline The current implementation may create dangling references from a superset of the alias set of the dummy pointer-to-array type when it exists. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * gcc-interface/decl.cc (gnat_to_gnu_entity) : Save and restore the alias set of the dummy pointer-to-array type. --ZGiS0Q5IWpPtfppv Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" diff --git a/gcc/ada/gcc-interface/decl.cc b/gcc/ada/gcc-interface/decl.cc --- a/gcc/ada/gcc-interface/decl.cc +++ b/gcc/ada/gcc-interface/decl.cc @@ -2102,15 +2102,15 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) const bool convention_fortran_p = (Convention (gnat_entity) == Convention_Fortran); const int ndim = Number_Dimensions (gnat_entity); - tree gnu_template_type; - tree gnu_ptr_template; - tree gnu_template_reference, gnu_template_fields, gnu_fat_type; + tree gnu_fat_type, gnu_template_type, gnu_ptr_template; + tree gnu_template_reference, gnu_template_fields; tree *gnu_index_types = XALLOCAVEC (tree, ndim); tree *gnu_temp_fields = XALLOCAVEC (tree, ndim); - tree gnu_max_size = size_one_node, tem, obj; + tree gnu_max_size = size_one_node; + tree comp_type, tem, obj; Entity_Id gnat_index; + alias_set_type ptr_set = -1; int index; - tree comp_type; /* Create the type for the component now, as it simplifies breaking type reference loops. */ @@ -2181,6 +2181,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) if (COMPLETE_TYPE_P (gnu_fat_type)) { tem = TYPE_FIELDS (gnu_fat_type); + if (TYPE_ALIAS_SET_KNOWN_P (TREE_TYPE (tem))) + ptr_set = TYPE_ALIAS_SET (TREE_TYPE (tem)); TREE_TYPE (tem) = ptr_type_node; TREE_TYPE (DECL_CHAIN (tem)) = gnu_ptr_template; TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (gnu_fat_type)) = 0; @@ -2389,7 +2391,10 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) tem = change_qualified_type (tem, TYPE_QUAL_VOLATILE); /* Adjust the type of the pointer-to-array field of the fat pointer - and record the aliasing relationships if necessary. If this is + and preserve its existing alias set, if any. Note that calling + again record_component_aliases on the fat pointer is not enough + because this may leave dangling references to the existing alias + set from types containing a fat pointer component. If this is a packed type implemented specially, then use a ref-all pointer type since the implementation type may vary between constrained subtypes and unconstrained base type. */ @@ -2398,8 +2403,8 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, bool definition) = build_pointer_type_for_mode (tem, ptr_mode, true); else TREE_TYPE (TYPE_FIELDS (gnu_fat_type)) = build_pointer_type (tem); - if (TYPE_ALIAS_SET_KNOWN_P (gnu_fat_type)) - record_component_aliases (gnu_fat_type); + if (ptr_set != -1) + TYPE_ALIAS_SET (TREE_TYPE (TYPE_FIELDS (gnu_fat_type))) = ptr_set; /* If the maximum size doesn't overflow, use it. */ if (gnu_max_size --ZGiS0Q5IWpPtfppv--