From patchwork Tue Sep 6 07:15:44 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: 1012 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5044:0:0:0:0:0 with SMTP id h4csp504409wrt; Tue, 6 Sep 2022 00:19:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR5ccuEOWLP+/Pws6iJ2J+lszVSs8V0ZA87pmklhDlM8/waYLGkYQorX2a2CXzpMscr3qA6O X-Received: by 2002:a17:907:9708:b0:741:9618:c493 with SMTP id jg8-20020a170907970800b007419618c493mr27409066ejc.631.1662448780403; Tue, 06 Sep 2022 00:19:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662448780; cv=none; d=google.com; s=arc-20160816; b=EsN/h0j20TydweksLWkGedp9PQxx9FuTJUhmZcpSfYuXU5WZtwZBajmS8pM55BbCsE fiG1yaKYXa42WF/5cRgfp0Ku73HO8laOaViDrG37X0fvKiDg+C+CvlBpnkXTXHN5J5ro RKCSZuPDZ8b/Ym/GdcV+Mpwc0HmGtrfZyeB0cvnN5rtRieDtfT8nCSSoP/MpMzLRsy2K zooh7YZQQ5n4+CByyW/EdLYoCtJ4ZrlAmmMEQobjJWPR2wUhboxL0lGXvEWorerupWE5 J5nfVP8tJAAnYE2yVuzTwYQAK4tzuouyJY7I2/xdYMvsslB6A8xJBPDnOjh9vwdKmUVH u+MQ== 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=PqbfTZMaLFUgIytZ4+ymGzRRqGQeDWnY0WF4+rn55VM=; b=mk9GaZnXmB/4pMYHtKroU2bkYgXXCs2NHolxKlNEUIUWwJKA+4VeqE3SWRwzOnh21x xce7fAbcF8pRy8J1qFfIOyJhgdMSR15p6f94V1gwVKjsI7V+3WeVHfCEAW4YRWZ/SlST /WPQHbfE09zi9VsT78vC6gh+WnQdIXh5K8z7Ayr5TGgIP5DDQGwngjEFw/+ccendtxat ZfxHXBhjbE1wWsgcSEOxfYk1J3iidPpc/E8vR3W/oyEkDs9Z9OoVnMtyE9tnBKG4zjXE Dkse865qdeQtXG+aBdXhF19iTu+Bgu6DLS3MwP1DG7rp8pGufdtFOxrUTh9cBL1623vI RArQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=tmuV48ri; 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 dz14-20020a0564021d4e00b004483d16d216si8809135edb.623.2022.09.06.00.19.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 00:19: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=tmuV48ri; 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 B85FD3895FE0 for ; Tue, 6 Sep 2022 07:17:26 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B85FD3895FE0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1662448646; bh=PqbfTZMaLFUgIytZ4+ymGzRRqGQeDWnY0WF4+rn55VM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=tmuV48riD9GbW6pNE9otLVEsPkDXbrCrr4mKrgHXB68ytQGMqE0jAOK7MEVZ3Jrcb T080bdF7g+4iJFZlcCO+cIvQo7HySK9jyfx1GkKKrEV9DQbVjB2/AUc1h3e4EiL7Ha hVCHZfCgJouHMevoOr9oHXGAiE38wC3Ydn9X76D8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by sourceware.org (Postfix) with ESMTPS id 68B1938515F8 for ; Tue, 6 Sep 2022 07:15:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 68B1938515F8 Received: by mail-wr1-x42c.google.com with SMTP id e13so14034232wrm.1 for ; Tue, 06 Sep 2022 00:15:46 -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=PqbfTZMaLFUgIytZ4+ymGzRRqGQeDWnY0WF4+rn55VM=; b=F7BnL5Ccxp60+hwV7pZ9lATgg9YdPYakLHn0MZJDqx/TG0STKOSsePMzQ0BzZyJkYi pCZ0GhMApVmRhH70pjTpc6TTIW9Jxit2aTisFBA8gi3aB8ioOUHlEYQby2Wbbn0bqXVf kgi10K4hqQmBtod6rvFDpHpulsgJpaHC7KBIBFO02ghKsBbSbVT025ARkgThOn/fZKiv n0SE+pagtLNkPczSHkni9+Vxi7+zZntXSq2yK3BOfOkCHVgLwA0FT8UCPTIIs99SndUs TK1qzgMyS3UETs4Itk1ww4ndrVEqjOhreBTLpNqzu00GnSm8V/cGjshV9EgTUIOoEA8f J//g== X-Gm-Message-State: ACgBeo2m2oryav+86H6XGme4GyjS8jTAK17Oe+UJmfAS1didKQ2W//pz QE8vzSv6ohMx4LrsldmRM01ooli27X5+JA== X-Received: by 2002:adf:e98e:0:b0:228:5f8b:cda6 with SMTP id h14-20020adfe98e000000b002285f8bcda6mr7353507wrm.601.1662448545230; Tue, 06 Sep 2022 00:15:45 -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 l27-20020a05600c2cdb00b003a5c7a942edsm21237405wmc.28.2022.09.06.00.15.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Sep 2022 00:15:44 -0700 (PDT) Date: Tue, 6 Sep 2022 09:15:44 +0200 To: gcc-patches@gcc.gnu.org Subject: [Ada] Bad Valid_Scalars result if signed int component type signed has partial view. Message-ID: <20220906071544.GA1280263@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?1743203892262999268?= X-GMAIL-MSGID: =?utf-8?q?1743203892262999268?= For an object X of a composite type, the attribute X'Valid_Scalars should return False if and only if there exists at least one invalid scalar subcomponent of X. The validity test for a scalar part may include a range test. In some cases involving a private type that is implemented as a signed integer type, this range test was incorrectly implemented using unsigned comparisons. For an enclosing object X, this could result in X'Valid_Scalars yielding the wrong Boolean result. Such an incorrect result would almost always be False, although an incorrect True result is theoretically possible (this would require that both bounds of the component subtype are negative and that the invalid component has a positive value). Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * exp_attr.adb (Make_Range_Test): In determining which subtype's First and Last attributes are to be queried as part of a range test, call Validated_View in order to get a scalar (as opposed to private) subtype. (Attribute_Valid): In determining whether to perform a signed or unsigned comparison for a range test, call Validated_View in order to get a scalar (as opposed to private) type. Also correct a typo which, by itself, is the source of the problem reported for this ticket. 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,8 @@ 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 (Ptyp); + PBtyp : Entity_Id := Base_Type (Validated_View (Ptyp)); + -- The scalar base type, looking through private types Save_Validity_Checks_On : constant Boolean := Validity_Checks_On; -- Save the validity checking mode. We always turn off validity @@ -7150,21 +7151,27 @@ package body Exp_Attr is Temp := Duplicate_Subexpr (Pref); end if; - return - Make_In (Loc, - Left_Opnd => Unchecked_Convert_To (PBtyp, Temp), - Right_Opnd => - Make_Range (Loc, - Low_Bound => - Unchecked_Convert_To (PBtyp, - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Ptyp, Loc), - Attribute_Name => Name_First)), - High_Bound => - Unchecked_Convert_To (PBtyp, - Make_Attribute_Reference (Loc, - Prefix => New_Occurrence_Of (Ptyp, Loc), - Attribute_Name => Name_Last)))); + declare + Val_Typ : constant Entity_Id := Validated_View (Ptyp); + begin + return + Make_In (Loc, + Left_Opnd => Unchecked_Convert_To (PBtyp, Temp), + Right_Opnd => + Make_Range (Loc, + Low_Bound => + Unchecked_Convert_To (PBtyp, + Make_Attribute_Reference (Loc, + Prefix => + New_Occurrence_Of (Val_Typ, Loc), + Attribute_Name => Name_First)), + High_Bound => + Unchecked_Convert_To (PBtyp, + Make_Attribute_Reference (Loc, + Prefix => + New_Occurrence_Of (Val_Typ, Loc), + Attribute_Name => Name_Last)))); + end; end Make_Range_Test; -- Local variables @@ -7186,13 +7193,6 @@ package body Exp_Attr is Validity_Checks_On := False; - -- Retrieve the base type. Handle the case where the base type is a - -- private enumeration type. - - if Is_Private_Type (PBtyp) and then Present (Full_View (PBtyp)) then - PBtyp := Full_View (PBtyp); - end if; - -- Floating-point case. This case is handled by the Valid attribute -- code in the floating-point attribute run-time library. @@ -7462,7 +7462,7 @@ package body Exp_Attr is Uns : constant Boolean := Is_Unsigned_Type (Ptyp) or else (Is_Private_Type (Ptyp) - and then Is_Unsigned_Type (Btyp)); + and then Is_Unsigned_Type (PBtyp)); Size : Uint; P : Node_Id := Pref;