From patchwork Mon Sep 12 08:19:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Marc_Poulhi=C3=A8s?= X-Patchwork-Id: 1156 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp1782365wrt; Mon, 12 Sep 2022 01:34:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5S6gMT0KG59pG2YuHQBAVbmzKkQWj6GPapoImwGEX9yWSarV6jlbm/8qcJX9V55T6LYdGD X-Received: by 2002:a17:907:7da3:b0:776:a0ae:5147 with SMTP id oz35-20020a1709077da300b00776a0ae5147mr13167710ejc.662.1662971680181; Mon, 12 Sep 2022 01:34:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662971680; cv=none; d=google.com; s=arc-20160816; b=RAfq1xOsczDkL7S6HJStegKoKfbLD/LxdOIlsaHGqcF3HrT9jJckIZVIV1BntMK2/6 EuzfnfiMIXeIlUpUCZ1luSqqLhiI32TB3TdK8Et1gpl2g6lMPpQqg6HmsGngYix9IbGo 2OXjlYSQY6L3LrTchhbeTXh0B0pEcsSulo0hlXEDQD8ZQydsFJVtpW51ONSiRO5v4w/2 QH/QwiHKVJ6aOooVrZcA0+iiZnmXlngD8sWh2H/IO0K9VAPVWT5j+SVzO9suYQPA3QsS hvES+cx6ej61p7nwLn9w7Bmb7jfkbBSPyx2/VzLm2VQY1i9T6xJG427wroQ7dhg04ydY k5iw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:reply-to:from:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence :content-disposition:mime-version:message-id:subject:to:date :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=/3KemylXokMcalcQjETLXuCnPOkUieuLBWHo7KO0z0U=; b=P6XiBLxWtIHFxRVs1zxqzFkd0FPKzl3G/rEtbN7l7NauAGxxIYfwFdsHRzEGlrCwmq WKVQvxx5rFdAy2aDeDn8A9Qf/cEQu46MUHixWbJljWCwSoCJDkssmSlS3MD3MDrtNBAG EvHXl/jUCleNKZ/ccF/0yG7omkI3xmQU4oo6Yb9arpEmucQZy3MeOb5siw9tHoX4fybH zLHRyQbSbZwA0NoefTwlRNsUTyA2fYI5VenPsfinfcmx1JHt9WnGHQ3hcUnX0etnLAos MMiTQfKqC7uk0/9QS1vAk143zBGr9ubS8q/BQH7ow3EdFxrrVAI/OmGOFVe638FUFuT0 4UYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Fm0w8F6W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ev14-20020a056402540e00b00451f749fbb4si721603edb.411.2022.09.12.01.34.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:34:40 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=Fm0w8F6W; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81A403947C27 for ; Mon, 12 Sep 2022 08:26:14 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 81A403947C27 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662971174; bh=/3KemylXokMcalcQjETLXuCnPOkUieuLBWHo7KO0z0U=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Fm0w8F6Wr//ld2JpgLt2JRcsFOkW8KvejE/l83z/hdohvChyiwXVrPKxvywKwWSzM oqw707wVZwAiNtG2OVEiqO/eFkoFBiYM2VSPF2/6qJ6uIgdv83ILGwm2XYhCY1BZqf ExGNuoe5tdQEiVyJMvsY++Kcjox+vnXx0r9RMPIw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by sourceware.org (Postfix) with ESMTPS id E5F203850438 for ; Mon, 12 Sep 2022 08:19:42 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E5F203850438 Received: by mail-wm1-x331.google.com with SMTP id v185-20020a1cacc2000000b003b42e4f278cso7416022wme.5 for ; Mon, 12 Sep 2022 01:19:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=/3KemylXokMcalcQjETLXuCnPOkUieuLBWHo7KO0z0U=; b=JQUL7aaf1FP/0IL3C/2Bm+B0NGP8Xh6DosKeJUuN0fYSeYtFg1sUy1wqPxe+wupOeq o8M0lKQmxdVfE4+MoOXZHDq/BrCz9MPQc1cfFkfeeQHAq9W/cVYTNOn51reHaVcyE4T9 H1Fp7NuHpcFJyROnUiJQpEHJI4qS6KxyB5LNyPmFGNiv7v/oyLe8ilYAcMj85jzTOzLc 9RRm77muUph6WNvC59sVDYFDR53SlEQ82MKLMasEX1EkCMpKO46ZvyKcgUn5THrJA3du 9HvFXtB8ZN9BmlHFeWMCPEEIdkZULrlg/hfUeomgzcrItPgU5b4YxeRMKuCNjeM1onIe lZXw== X-Gm-Message-State: ACgBeo3hP4l9pe/cNOIWkvWSspISD8Oy/E4RfjsX4WZfYhYdbXRwWvBG 3E7+l8FE+j3206lzLApu1DL6YeTqinYvPw== X-Received: by 2002:a1c:f709:0:b0:3a6:3452:fcbe with SMTP id v9-20020a1cf709000000b003a63452fcbemr13264785wmh.164.1662970782619; Mon, 12 Sep 2022 01:19:42 -0700 (PDT) Received: from poulhies-Precision-5550 (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id c19-20020a05600c4a1300b003a1980d55c4sm8267935wmp.47.2022.09.12.01.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 12 Sep 2022 01:19:42 -0700 (PDT) Date: Mon, 12 Sep 2022 10:19:41 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Reject 'Valid_Scalars on Unchecked_Union regardless of privacy Message-ID: <20220912081941.GA1513116@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.8 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-Patchwork-Original-From: =?utf-8?q?Marc_Poulhi=C3=A8s_via_Gcc-patches?= From: =?utf-8?q?Marc_Poulhi=C3=A8s?= Reply-To: Marc =?iso-8859-1?q?Poulhi=E8s?= Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1743752192158322543?= X-GMAIL-MSGID: =?utf-8?q?1743752192158322543?= Attribute Valid_Scalars applied to prefix with an unchecked union component causes a legitimate crash in the backend. It was already rejected in the frontend for prefixes of a public type; now it is rejected in the frontend regardless of the type privacy. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_attr.adb (Analyze_Attribute [Valid_Scalars]): Move check for unchecked union before checks for private and public types. diff --git a/gcc/ada/sem_attr.adb b/gcc/ada/sem_attr.adb --- a/gcc/ada/sem_attr.adb +++ b/gcc/ada/sem_attr.adb @@ -7399,10 +7399,19 @@ package body Sem_Attr is if Comes_From_Source (N) then Check_Object_Reference (P); + -- Attribute 'Valid_Scalars is illegal on unchecked union types + -- regardles of the privacy, because it is not always guaranteed + -- that the components are retrievable based on whether the + -- discriminants are inferable. + + if Has_Unchecked_Union (Validated_View (P_Type)) then + Error_Attr_P + ("attribute % not allowed for Unchecked_Union type"); + -- Do not emit any diagnostics related to private types to avoid -- disclosing the structure of the type. - if Is_Private_Type (P_Type) then + elsif Is_Private_Type (P_Type) then -- Attribute 'Valid_Scalars is not supported on private tagged -- types due to a code generation issue. Is_Visible_Component @@ -7432,15 +7441,6 @@ package body Sem_Attr is ("??attribute % always True, no scalars to check", P); Set_Boolean_Result (N, True); end if; - - -- Attribute 'Valid_Scalars is illegal on unchecked union types - -- because it is not always guaranteed that the components are - -- retrievable based on whether the discriminants are inferable - - if Has_Unchecked_Union (P_Type) then - Error_Attr_P - ("attribute % not allowed for Unchecked_Union type"); - end if; end if; end if;