From patchwork Mon Nov 14 13:52:29 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: 60585 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 95F2A3836644 for ; Mon, 14 Nov 2022 13:53:08 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 95F2A3836644 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1668433988; bh=ya06R1Htpyp064sHO79A5QMRo7xmhkYChlUnoyPFFuk=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=W8nwLDZ65Bh5tdN45SOIjCeOggz7yzJb6sgvXKRNjzUr1UGpGBZEOH7dXw1393Hci IUa5jE7QD3akq5etLnC/fO5K0Kj2a2DsBa17Fw+i3ffakuwdKGRxVWbdb/fzXQVWli nYRxX0A3CGmPKuarullvYOSK97b4yJVV5M3fjMs8= 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 6AEDF3832379 for ; Mon, 14 Nov 2022 13:52:33 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6AEDF3832379 Received: by mail-wr1-x42c.google.com with SMTP id v1so18338460wrt.11 for ; Mon, 14 Nov 2022 05:52:33 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=ya06R1Htpyp064sHO79A5QMRo7xmhkYChlUnoyPFFuk=; b=jJtt+FXJ08z0FjzSmpPP74kvD12aNnbk09OVqHmEJgXXp+xhVa7H+HHKUsOVzalGbX iZ6/iNP/Nc9unkAIN+De+PGHgYIrR8tMN6YoHEmSkSeF1nIXDR66NrOFm8hjXr7mkdS+ qphDNNJw9I+cyCiW3ypyTV+TRd28RWieYpHZ/6NGliZuV/U2mCLKGf7ShPVS96NvoIcK fty6yZsEqG+bPFzZ2ukPhd8xh5t6Nu6Fh7i/7bKjAlWp0Zff8UkG6z/RERBIVk7mWryK drJ8P0oUAy7xLw0yvTQJHKld6/LyIZVyof698GRERD+X6cZI1na3P7uwhtMNmrGU/lx2 qxPw== X-Gm-Message-State: ANoB5pk6j8OTBAAyqf8rnonFDL9Z0JGMNZEF9dCGcyliGtciasnU1y+n aQTZTpL0VmbwdDjx7279zuohoHuPay/XuQ== X-Google-Smtp-Source: AA0mqf4zijAcB9OPqel7/vx8inr2IvaHwT3k8PA51y8rS+KdrpcM+tx0cWreHsWtIz3ubbVFUjfSsQ== X-Received: by 2002:a05:6000:988:b0:241:792e:bdf9 with SMTP id by8-20020a056000098800b00241792ebdf9mr5402370wrb.540.1668433952259; Mon, 14 Nov 2022 05:52:32 -0800 (PST) Received: from localhost.localdomain (static-176-191-105-132.ftth.abo.bbox.fr. [176.191.105.132]) by smtp.gmail.com with ESMTPSA id ay19-20020a05600c1e1300b003c6bbe910fdsm22441870wmb.9.2022.11.14.05.52.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Nov 2022 05:52:31 -0800 (PST) To: gcc-patches@gcc.gnu.org Cc: Gary Dismukes Subject: [COMMITTED] ada: Crash on applying 'Pos to expression of a type derived from a formal type Date: Mon, 14 Nov 2022 14:52:29 +0100 Message-Id: <20221114135229.53029-1-poulhies@adacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Spam-Status: No, score=-13.4 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 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: =?utf-8?q?Marc_Poulhi=C3=A8s?= Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" From: Gary Dismukes The compiler crashes when trying to do a static check for a range violation in a type conversion of a Pos attribute applied to a prefix of a type derived from a generic formal discrete type. This optimization was suppressed in the case of formal types, because the upper bound may not be known, but it also needs to be suppressed for types derived from formal types. gcc/ada/ * checks.adb (Apply_Type_Conversion_Checks): Apply Root_Type to the type of the prefix of a Pos attribute when checking whether the type is a formal discrete type. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/checks.adb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index 96876672871..2a45f4d49b0 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -3789,13 +3789,14 @@ package body Checks is -- Universal_Integer. So in numeric conversions it is usually -- within range of the target integer type. Use the static -- bounds of the base types to check. Disable this optimization - -- in case of a generic formal discrete type, because we don't - -- necessarily know the upper bound yet. + -- in case of a descendant of a generic formal discrete type, + -- because we don't necessarily know the upper bound yet. if Nkind (Expr) = N_Attribute_Reference and then Attribute_Name (Expr) = Name_Pos and then Is_Enumeration_Type (Etype (Prefix (Expr))) - and then not Is_Generic_Type (Etype (Prefix (Expr))) + and then + not Is_Generic_Type (Root_Type (Etype (Prefix (Expr)))) and then Is_Integer_Type (Target_Type) then declare