From patchwork Mon Oct 4 08:47:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pierre-Marie de Rodat X-Patchwork-Id: 1535999 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=MIfPe2yE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4HNF3b47kWz9t0k for ; Mon, 4 Oct 2021 19:57:47 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7B9B63858C3A for ; Mon, 4 Oct 2021 08:57:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 7B9B63858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1633337865; bh=ozLLgrNOq1NMoKwd6P7mhvB///m1UugXcRi0M6Z0jqM=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=MIfPe2yEL/PoFTCf1ogYkI82kYAWVvbcy8CpapYEm+HdeTozsfrxhF1OpqG1xM67f pMNQxRVzgrsC4MRGCVqjvzL0wMUlpIl4UEvN+daI6U5AjH5NW3E5iF3fEbnG7spXnC yH5eh80GfXzRfpSpE9oPxqOr/cxyakISylwz1ftA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [IPv6:2a00:1450:4864:20::129]) by sourceware.org (Postfix) with ESMTPS id 301743858420 for ; Mon, 4 Oct 2021 08:47:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 301743858420 Received: by mail-lf1-x129.google.com with SMTP id y15so2666071lfk.7 for ; Mon, 04 Oct 2021 01:47:51 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition; bh=ozLLgrNOq1NMoKwd6P7mhvB///m1UugXcRi0M6Z0jqM=; b=cxpuzPIhoH6bYyeKmCTZz+Ajjqk/aiau+weaVxS/LBPMcv11XFNCiBzAPkZjmWsmCL nV77r/aOYOhh5oNS0JxYMhP1Nqee/bgCeG2Os7LNUtqyq8BysaAGbbccN++3iWaZWoax YohlqIpJES/wgChAj7kFY7zY7+uQ5FAEyYqxXVtxT5ROPphJ/2/XC7nlbdrfkIpd8KK0 sqnPg+vkcnaxspoThaZBoIjMt97u6cxUzqBCM/0FYudib3KNTeHm8UFMYdnqGtmnpv2r ltqmkVs9xYwQNSIMimdexdMw2ZDIRkPqYkSMWPl9P8liLgaUt95Pb33haS3ZhWIpO8s9 uQ3Q== X-Gm-Message-State: AOAM5331nKaPaLntuOvQcORlc3yoCEm7EM0SdnJsCHE3Ryax4ebm0iT0 I/qeBBWzCFR7RamrfD97lUzLRPfrJAFWmw== X-Google-Smtp-Source: ABdhPJyW+xkUbT4cFUR3I3BABYddULnrO/wR27Mro5E+cAuN3SAWPNBucEo4Noe/yagfQy52tpV4Jg== X-Received: by 2002:ac2:4e04:: with SMTP id e4mr13120878lfr.565.1633337270085; Mon, 04 Oct 2021 01:47:50 -0700 (PDT) Received: from adacore.com ([2a02:2ab8:224:2ce:72b5:e8ff:feef:ee60]) by smtp.gmail.com with ESMTPSA id z1sm1547121lfu.222.2021.10.04.01.47.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 01:47:49 -0700 (PDT) Date: Mon, 4 Oct 2021 08:47:48 +0000 To: gcc-patches@gcc.gnu.org Subject: [Ada] Fix handling of 'Image acting as a prefix of a slice in CodePeer Message-ID: <20211004084748.GA1536652@adacore.com> MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-13.0 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.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: Pierre-Marie de Rodat via Gcc-patches From: Pierre-Marie de Rodat Reply-To: Pierre-Marie de Rodat Cc: Piotr Trojanek Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" In CodePeer mode attribute Image is not expanded and has its Etype set as the unconstrained String type. When this attribute appears as a prefix of an indexed component, we get a check; when it appears as a prefix of a slice, we don't get a check. For indexed components, the check effectively comes from Apply_Scalar_Range_Check, where prefixes of unconstrained array types are handled specifically. For slices, the seemingly similar routine Apply_Range_Check doesn't specifically handle such prefixes. Instead, we need to give this routine a constrained subtype, just like we do when slice is prefixed with a call to a function that returns an unconstrained array. Tested on x86_64-pc-linux-gnu, committed on trunk gcc/ada/ * sem_res.adb (Resolve_Slice): Add custom handling of attribute Image and similar in CodePeer mode. This complements the existing custom handling of these attributes in Expand_N_Attribute_Reference. diff --git a/gcc/ada/sem_res.adb b/gcc/ada/sem_res.adb --- a/gcc/ada/sem_res.adb +++ b/gcc/ada/sem_res.adb @@ -11275,10 +11275,20 @@ package body Sem_Res is end; end if; + -- In CodePeer mode the attribute Image is not expanded, so when it + -- acts as a prefix of a slice, we handle it like a call to function + -- returning an unconstrained string. Same for the Wide variants of + -- attribute Image. + elsif Is_Entity_Name (Name) or else Nkind (Name) = N_Explicit_Dereference or else (Nkind (Name) = N_Function_Call and then not Is_Constrained (Etype (Name))) + or else (CodePeer_Mode + and then Nkind (Name) = N_Attribute_Reference + and then Attribute_Name (Name) in Name_Image + | Name_Wide_Image + | Name_Wide_Wide_Image) then Array_Type := Get_Actual_Subtype (Name);