From patchwork Tue Sep 6 07:15:49 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: 1017 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp504877wrt; Tue, 6 Sep 2022 00:21:43 -0700 (PDT) X-Google-Smtp-Source: AA6agR5u6l+FGGiYtEBBLxTJcrfvw0sLML6LbqRro39kCi4e0rfWPuv8RjgM3i1Zvo5guqQTnOTq X-Received: by 2002:a05:6402:3506:b0:43e:954b:bc8a with SMTP id b6-20020a056402350600b0043e954bbc8amr47375126edd.266.1662448902961; Tue, 06 Sep 2022 00:21:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662448902; cv=none; d=google.com; s=arc-20160816; b=gQ6MSvWjMW8Q1TkmWPUJm2tW2TkDUIQjTBSVoPhp188pV02pQ6vhDUqISNUqtRfLlf 2Dz5usYj5sbgtYJAS+NpM0fOMsUlnq0DAw/pBssiRaLYNkeQsInEn7dYm+o4FNFZthSs PaKjF3O6yyP18tfNZVyiTROzNMFfop3E9GhHyRUjnHdXYS0TSvEHpNC1ujTtVXWyipV+ 9477kpUDAnpZDhugd7aRAre6wgxcVAfaI8Z4YPmqrOG9Ugd17qLuO/iS8OV/ta67hOD9 N0Qkr8zh7Xa7MxWiOuw9D38sKsXYwA8WUjwr4GO9KT3pKHjyd0hbBqRnw0aPeDjWxTdm wXvA== 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=8BY5XfD8/wmAhH8GnDjhtqXjyk4RV7sDR4CyBaJL8EI=; b=h/0KcYBTXPyOFc3hIB6jS34m43mcZpVVTyusDThNRg4NbqnTqHM4P9bl97UqP479WT zJO8mYWfyvOvEIOpLt72f+6qpAy4Jl0iS5mfwyzIF//C6i7kNEEAgLj/EEQ8uw6cHoSV lE1/oHkseBEcXmxPa2/eycZbneCdhpT/ypy9HRJkVpMCbsCosSSkCYSlarchgyM7/fdz cnbz+MAjgMPNiGHFeBvcdMvhCy+xxjF2DCAcOYMfZClwH/HArcyyL75OZl19rr/vh0B5 1iSKtlnEUds3V8Xa4DSC0QzUSv5BWqVI/dh2vnxAPWpDcROEYI7nj2qlfsCtx0WCPWFR vb8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=MoW0i6G7; 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 (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id i21-20020a170906091500b007419a23eb1dsi8073822ejd.171.2022.09.06.00.21.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 00:21:42 -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=MoW0i6G7; 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 49628393A412 for ; Tue, 6 Sep 2022 07:18:25 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 49628393A412 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662448705; bh=8BY5XfD8/wmAhH8GnDjhtqXjyk4RV7sDR4CyBaJL8EI=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=MoW0i6G7OWKfQRlCJQ4RWSJFiVoXZihvcvwgwsEnng+RgjHXhpztQTZ27N8mn8st/ GsRp7gtlU4vDuAEVH8K+hUfRQn5zoidSeZTWhKEOu0PyZLnztiYtI1AcLnQ2Pv1FTg R/roJnI0DS4prnAbV3l8r7PmJSUI6qGJHTOQfxD4= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id 95F62385AC24 for ; Tue, 6 Sep 2022 07:15:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 95F62385AC24 Received: by mail-wr1-x42a.google.com with SMTP id c11so9782489wrp.11 for ; Tue, 06 Sep 2022 00:15:51 -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=8BY5XfD8/wmAhH8GnDjhtqXjyk4RV7sDR4CyBaJL8EI=; b=xEtygCamLwn7J1vvAcEVPwah9MOqP2pX/NPkC/IFYbCNkKwTYklpv/LXGZY4KfzE5D kifMs/5UhHiPQ3rnc/aCuTnvTj9ITxLSFGbE/iADgUrLDBYJ5idvk+jSe/7p7gm8x3fg qg/teweYh5uK5gfMlaqIVUJYx+oAmcxszWPr+DPcHZgJoAVIbAL9hiF6/bDtxh3Tyaki 3aiLkQ3D7ncn+PNBZvFfzTauD3wUkQrkn8O2qGooIX/tjarCS+ExNlViiCDikUU6JFaR 4IwfMig7w7/gXN60iBqx4IIXK7HJQD2KHLdcJ6XhMetIwfX7a4wlFrE8YHmjbcfPiHDR JaTQ== X-Gm-Message-State: ACgBeo0JJykLeKULgpIZuUKp8PfGplw1VsscW34r4s6cqTg2ouPE7mEu HIvu9oG16a36HhDgwqRsRQQX4bxqUIp16w== X-Received: by 2002:a5d:5b1c:0:b0:226:fe54:cd52 with SMTP id bx28-20020a5d5b1c000000b00226fe54cd52mr11867148wrb.417.1662448550566; Tue, 06 Sep 2022 00:15:50 -0700 (PDT) Received: from poulhies-Precision-5550 (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id x13-20020a1c7c0d000000b003a5ca627333sm19125834wmc.8.2022.09.06.00.15.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 00:15:50 -0700 (PDT) Date: Tue, 6 Sep 2022 09:15:49 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Cope with scalar subtypes that have a non-scalar basetype. Message-ID: <20220906071549.GA1280346@poulhies-Precision-5550> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.9 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: Steve Baird 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?1743204020718345760?= X-GMAIL-MSGID: =?utf-8?q?1743204020718345760?= In some cases, the compiler builds a subtype entity Typ such that Is_Scalar (Typ) is True and Is_Scalar (Base_Type (Typ)) is False. This comes up in some cases involving a subtype of a private type, where the full view of the private type is a scalar type. In such a situation, it may also be the case that Is_Enumeration_Type (Typ) is True and Is_Enumeration_Type (Base_Type (Typ)) is False. Some code incorrectly assumed that if a subtype is known to be a scalar (respectively, enumeration) type, then the same must be true of the base type of that subtype. Fix that code to handle the case where that assumption does not hold. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_attr.adb (Attribute_Valid): Ensure that PBtyp is initialized to a value for which Is_Scalar_Type is True. * checks.adb (Determine_Range): Call Implemention_Base_Type instead of Base_Type in order to ensure that result is suitable for passing to Enum_Pos_To_Rep. diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -5094,7 +5094,8 @@ package body Checks is -- Don't deal with enumerated types with non-standard representation or else (Is_Enumeration_Type (Typ) - and then Present (Enum_Pos_To_Rep (Base_Type (Typ)))) + and then Present (Enum_Pos_To_Rep + (Implementation_Base_Type (Typ)))) -- Ignore type for which an error has been posted, since range in -- this case may well be a bogosity deriving from the error. Also diff --git a/gcc/ada/exp_attr.adb b/gcc/ada/exp_attr.adb --- a/gcc/ada/exp_attr.adb +++ b/gcc/ada/exp_attr.adb @@ -7103,7 +7103,10 @@ package body Exp_Attr is -- See separate sections below for the generated code in each case. when Attribute_Valid => Valid : declare - PBtyp : Entity_Id := Base_Type (Validated_View (Ptyp)); + PBtyp : Entity_Id := Implementation_Base_Type (Validated_View (Ptyp)); + pragma Assert (Is_Scalar_Type (PBtyp) + or else Serious_Errors_Detected > 0); + -- The scalar base type, looking through private types Save_Validity_Checks_On : constant Boolean := Validity_Checks_On;