From patchwork Fri Jun 21 08:58:05 2024 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: 1950637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=adacore.com header.i=@adacore.com header.a=rsa-sha256 header.s=google header.b=d/Gak9Fy; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4W5BD83BRGz1ydW for ; Fri, 21 Jun 2024 19:01:12 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9D1D738A1401 for ; Fri, 21 Jun 2024 09:01:10 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by sourceware.org (Postfix) with ESMTPS id 529103896C2A for ; Fri, 21 Jun 2024 08:58:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 529103896C2A Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=adacore.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=adacore.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 529103896C2A Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::333 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718960320; cv=none; b=sdPsbYYv2i1Y/j5srNcDAKaxk/EYpQXrdS7oxkdqzJIN6OVEXtQr8GlzSbvqIQZjOmTqsPk4RIL3pinR4NOSwCph9qfyhfKiyWW5sdxSkctmh8VSWWSiWyHokSGyJzl9iTJnhP4jZXRAUhkmi/I+p5b0y9DFo55C3nAhm9HMr9E= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718960320; c=relaxed/simple; bh=/bdys62tjy7toEAnPoG3J+5PmC250JvytpXVnVayPTM=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=uXs+WFgnNc7Ot65Ht7WU8DeX23AmKmsWP6EiXb0NlAsrFd5T9uNt3yr+ESProOqLLOio36PxbV20ZMcTaUkQdJV5FcZy2v706Are7FYmjzyvAPFnZjcb/BKoY0/juir0rOVshh4kDH0UoRVvQm0shtW3Lwb8chH7I34rrBTQn3k= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-4247f36f689so11096515e9.1 for ; Fri, 21 Jun 2024 01:58:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718960317; x=1719565117; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f90hCGMs9ILPG1jXtDqZk3iVkU+nxEh9POQAjMQYDEY=; b=d/Gak9FyZDoD1S4lu0233dG5ZwSQ7EGTZKq3ZhxiyAsIy7oARB/dXkuqRDlaWC6S2f 4zUUX9wN6Ius5Ec0xcIzPzrTD4W/lInPXNFsTJZcASDxdDYji34DOHe8rUUKbkW0FJPU RT1CsLu3y+MDOieqSvChsp8pj2rCWSICbPimUqnaoHzwFau7gKfSV0Fo59qf6xsMM4f+ BKWaar2uDU3J7mY3atWe7hA9jLS8h2MtwhWP+L3sFAZiAv+gFcocMKG4Hqx/PTS5Z69j WJhyvf0lGyYbY+B7o0+Vgb9kHMDYfLMe5MwbrwyQDV7lje0RN+14Zy5DM3BiKq2SvWLL A54w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718960317; x=1719565117; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f90hCGMs9ILPG1jXtDqZk3iVkU+nxEh9POQAjMQYDEY=; b=Y0eizvc59uRg0E5vnZdkMF4s4VPG+eEljFkkmlc+YcBe5NOZrl0D15ChJtmzsX44xf yl+JXina4UX3EBM2jOlOP7ILblZou9pgXWkgnwnLIwuGfKXm9d/AkqFRRvagWFZcj1+Z SvUw9s/UO4c4HSDEFzU6M3NBzWsuvzMpS/4KyQZmC/o7PcCtCPlnlOVcdWqE9MZea9dp 7Ohl0pNEFnoAIlJnKweQC7MSWcQi+4ut+/p3i94sjadiVpG5Ek4hyKyV0kTNO9anH73u VvQqj5VmNgD8Wxu2SXPU825wbXkvIPVFviYk4uMlk2mw0vRzqv2SeisWOHJvSrR6ACt1 X5nw== X-Gm-Message-State: AOJu0YwiW3Q5caZ/kdvedp9RupKcwbOxqJz5OtXPnpAg99LGqFOXRn7F 1/a/Lm9DAPuJZiUTwSw5cJmYgZa6ty+Nu0dYKMojLl9xPNbGc1aGHLHXNfcmC+S7HDsGGlDPdgE = X-Google-Smtp-Source: AGHT+IEqb7zcoOBIZZFf5aReNfrY/8BQMAU1a45gryK5a4eoE8OThgSavoVK0fHvwFBKTbZx2VJhQg== X-Received: by 2002:a05:600c:491c:b0:422:2b9b:671d with SMTP id 5b1f17b1804b1-4247517dd8fmr62249635e9.19.1718960317078; Fri, 21 Jun 2024 01:58:37 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:a589:2704:bfe1:5d92]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-4247d0c5485sm55322375e9.21.2024.06.21.01.58.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Jun 2024 01:58:36 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Eric Botcazou Subject: [COMMITTED 09/22] ada: Fix missing index check with declare expression Date: Fri, 21 Jun 2024 10:58:05 +0200 Message-ID: <20240621085819.2485987-9-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240621085819.2485987-1-poulhies@adacore.com> References: <20240621085819.2485987-1-poulhies@adacore.com> MIME-Version: 1.0 X-Spam-Status: No, score=-13.7 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org From: Eric Botcazou The Do_Range_Check flag is properly set on the Expression of the EWA node built for the declare expression, so this instructs Generate_Index_Checks to look into this Expression. gcc/ada/ * checks.adb (Generate_Index_Checks): Add specific treatment for index expressions that are N_Expression_With_Actions nodes. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/checks.adb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/gcc/ada/checks.adb b/gcc/ada/checks.adb index bada3dffcbf..c8a0696be67 100644 --- a/gcc/ada/checks.adb +++ b/gcc/ada/checks.adb @@ -7248,7 +7248,8 @@ package body Checks is Loc : constant Source_Ptr := Sloc (N); A : constant Node_Id := Prefix (N); A_Ent : constant Entity_Id := Entity_Of_Prefix; - Sub : Node_Id; + + Expr : Node_Id; -- Start of processing for Generate_Index_Checks @@ -7294,13 +7295,13 @@ package body Checks is -- us to omit the check have already been taken into account in the -- setting of the Do_Range_Check flag earlier on. - Sub := First (Expressions (N)); + Expr := First (Expressions (N)); -- Handle string literals if Ekind (Etype (A)) = E_String_Literal_Subtype then - if Do_Range_Check (Sub) then - Set_Do_Range_Check (Sub, False); + if Do_Range_Check (Expr) then + Set_Do_Range_Check (Expr, False); -- For string literals we obtain the bounds of the string from the -- associated subtype. @@ -7310,8 +7311,8 @@ package body Checks is Condition => Make_Not_In (Loc, Left_Opnd => - Convert_To (Base_Type (Etype (Sub)), - Duplicate_Subexpr_Move_Checks (Sub)), + Convert_To (Base_Type (Etype (Expr)), + Duplicate_Subexpr_Move_Checks (Expr)), Right_Opnd => Make_Attribute_Reference (Loc, Prefix => New_Occurrence_Of (Etype (A), Loc), @@ -7330,11 +7331,19 @@ package body Checks is Ind : Pos; Num : List_Id; Range_N : Node_Id; + Stmt : Node_Id; + Sub : Node_Id; begin A_Idx := First_Index (Etype (A)); Ind := 1; - while Present (Sub) loop + while Present (Expr) loop + if Nkind (Expr) = N_Expression_With_Actions then + Sub := Expression (Expr); + else + Sub := Expr; + end if; + if Do_Range_Check (Sub) then Set_Do_Range_Check (Sub, False); @@ -7396,7 +7405,7 @@ package body Checks is Expressions => Num); end if; - Insert_Action (N, + Stmt := Make_Raise_Constraint_Error (Loc, Condition => Make_Not_In (Loc, @@ -7404,14 +7413,21 @@ package body Checks is Convert_To (Base_Type (Etype (Sub)), Duplicate_Subexpr_Move_Checks (Sub)), Right_Opnd => Range_N), - Reason => CE_Index_Check_Failed)); + Reason => CE_Index_Check_Failed); + + if Nkind (Expr) = N_Expression_With_Actions then + Append_To (Actions (Expr), Stmt); + Analyze (Stmt); + else + Insert_Action (Expr, Stmt); + end if; Checks_Generated.Elements (Ind) := True; end if; Next_Index (A_Idx); Ind := Ind + 1; - Next (Sub); + Next (Expr); end loop; end; end if;