From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com Received: by mail-wm1-x331.google.com with SMTP id v185-20020a1cacc2000000b003b42e4f278cso7416022wme.5 for ; Mon, 12 Sep 2022 01:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-disposition:mime-version:message-id:subject:cc:to:from:date :from:to:cc:subject:date; bh=/3KemylXokMcalcQjETLXuCnPOkUieuLBWHo7KO0z0U=; b=jOwp6jF2Po1f40WSrebgJ9XP7XRBDUqUIZnnUaET7WzqmipDJIdUGghQDA6BQ/GcmL WUm43C/sdJ7VGdshGWQdRWwVRUvOSY5YcwO+6IcNwMRBYsBmc1jV9E8+XxT4UHsYkDMv mXX8Qk1vjCvC7t38mqYc+YZx0UjiwXMpA4PKvdXShrKn8calb60YRLULEWq/EGtTBEd0 tIwnLFBkZbri1qIgHPlHbc5qywTTXbYixKSRR48QfEYUQKqhntm31zup+LI6toxd4Cpb wyGiR0JRoghPBxX+r4iIjWz+tgmr+36r/mcof6HCt9XIsUj9lMCpCkZUHT+gpfLayLk/ Dwjg== 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-Google-Smtp-Source: AA6agR4lQNTiAXB+d5Ed1ELvGy1Zge1u+zSTL5iDfNk5QkHAVWgO+7e/EXidw034GgrHfYOtp35+5Q== 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 From: Marc =?iso-8859-1?Q?Poulhi=E8s?= To: gcc-patches@gcc.gnu.org Cc: Piotr Trojanek Subject: [Ada] Reject 'Valid_Scalars on Unchecked_Union regardless of privacy Message-ID: <20220912081941.GA1513116@poulhies-Precision-5550> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="azLHFNyN32YCQGCU" 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 List-Id: --azLHFNyN32YCQGCU Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --azLHFNyN32YCQGCU Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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; --azLHFNyN32YCQGCU--