From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 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-x42c.google.com with SMTP id v1so18338460wrt.11 for ; Mon, 14 Nov 2022 05:52:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=ya06R1Htpyp064sHO79A5QMRo7xmhkYChlUnoyPFFuk=; b=OssJr4k5/cXERNq2k+HOIWuyVgLLu99Eq34zJckqK460fK7Q7AlLM6pCrxJKBWHuQp KnxsJ2kIYBm50jGmw88xxRG29R4EHgQWDN2ZYR4lioKDXGKBbH1BddDl71s7XaBq8mIQ xxDffONB6V+L5CaeI8JBAAsmZUhz0Ae6DvBdBM1ZNWtQd7REMPnlctKEpx1v6o/yhcv3 70XVjg9s0Aj5/CRocTNeoh/bYmse6r3uEX7ydHMiEu8Q3xu7k1LX0UXJScDEEgh8iY27 XzAkAZR6bDhOCEoprYqGe4RgAWsWDtH24sp+OUKqYpOKTfgIH43F9X8/47/U3nAfKDEb S36w== 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) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= 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 Content-Transfer-Encoding: 8bit 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 List-Id: 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 -- 2.34.1