From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-wr1-x42a.google.com with SMTP id c11so9782489wrp.11 for ; Tue, 06 Sep 2022 00:15:51 -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=8BY5XfD8/wmAhH8GnDjhtqXjyk4RV7sDR4CyBaJL8EI=; b=PLVb9zc17rSeeQattNiWJK+QKBv0WlF7yzkwSrUZQBa9ccIu2E1P0VxCv/Kui9axvF Hj0ImphjPyouadkp7XlZZcy/N5kdRi3FDOZCT5Aru7gbHaKKqnj2bxBJtgf3Jl9zZU4g t3LjE5MXntRZIgKthR+xd2NuQ9zDcu89mw/4LDi9ZdpNQCCeNWKn+PbClr2gAIsQcgMX kydiltr+0cgoqXuevvqXgwMy5IyOtMXxuu+GZ19LCVLscmMrdWC8s0OxL/Gulw8XlKRV rxGuv4B5cCzwQDd7PtdPEcoIckqWLm8AhprLcLb/9Lh8dpeShK5BqNdx4KDqlgUd8AoD LCPQ== 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-Google-Smtp-Source: AA6agR4LlADQqFazgy5hCK7ygM7FRMdfy+BP2ZC4X4EdidulZT8f8ZwRHn8mhtxUrH1yKFs/3NtwSg== 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 From: Marc =?iso-8859-1?Q?Poulhi=E8s?= To: gcc-patches@gcc.gnu.org Cc: Steve Baird Subject: [Ada] Cope with scalar subtypes that have a non-scalar basetype. Message-ID: <20220906071549.GA1280346@poulhies-Precision-5550> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="OXfL5xGRrasGEqWY" 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 List-Id: --OXfL5xGRrasGEqWY Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --OXfL5xGRrasGEqWY Content-Type: text/x-diff; charset=us-ascii Content-Disposition: attachment; filename="patch.diff" 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; --OXfL5xGRrasGEqWY--