From patchwork Fri Aug 2 07:11:18 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: 1968189 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=clKh1C+j; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4WZxr73xqSz1yZl for ; Fri, 2 Aug 2024 17:13:11 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F254A385E82F for ; Fri, 2 Aug 2024 07:13:07 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by sourceware.org (Postfix) with ESMTPS id 9195E385DDFE for ; Fri, 2 Aug 2024 07:12:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9195E385DDFE 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 9195E385DDFE Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::435 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582745; cv=none; b=lSQuSbOe0d3CNlUL+XjmUeZAjuYwqMNOvfz1aP0pAqIIUW1/nQ6s3wkeI/uT+gv84N2u0EwIuwVXZuaS+TWoeD8Hs0XrjzCslBfSjmJKkWsSillhNDNiCyctWwN78/O0OChi6x1bXaDTZ+UhGle7vBEsyw+6VHqhBOJ3Q9p5zIs= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1722582745; c=relaxed/simple; bh=HRCNpdEbOgNk5Q9z4hr9Rq6+V4q1jHy/ctyt30qBcV4=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=iX8MX5v8x5KONAA/bxL4kkjfX3japBwFtvK6N4ZSIB3S48Wqy+Fz111zVPYAgzAbDFtlqYVBN1sidwZ5o0ToYQUiE74olKDQdv1MsOrZPfQsLFBD9PEy4E/2HUhU/fH1KR6XxJvm1Ejd2ZpkBG6qbSdyKtDEC7lu0AEtPtJW71Q= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wr1-x435.google.com with SMTP id ffacd0b85a97d-3684e8220f9so1577642f8f.1 for ; Fri, 02 Aug 2024 00:12:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1722582742; x=1723187542; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=DWddsJHqoPCJIGonGOgojn/wrP6TSUdvkatp9teyV4w=; b=clKh1C+ju5ZNZjqRTPXH1+vROPnSeUxdTtrGhodUL39f+4pYc0UXs8mfD8DQ8x+QGx th9gyGZxGDpKnxOCmuJM3EdMi0KjqN67oLcVe4MKdXdZPGPk4/5911+aeurSXnFvkEe2 +C93aThvK/9J6Go4k50PsB6WdYdszd7gqi8Ou10sBBZi+Rom4B8va4GJDa0ElZX6WtU5 /D8kK/ibc8x7i06lsdhhIgQoyQomGvSrdPww86eJbYRk0pF1g9HIL+LZ61Or5wE5qhC7 zE08rap1ECUJiIixWIjfSnfrymdv6yjybXDVXr1pA0hA0ffUonbZw4Sg1kGzgAB/uuPX 4Xpg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1722582742; x=1723187542; 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=DWddsJHqoPCJIGonGOgojn/wrP6TSUdvkatp9teyV4w=; b=ba8rHzfeorM+QuOCn5n0ovRg/WqI4jnvV89MJ4uhFgr4rA7EiEyQcUA8a7l/2CdOFM 8G0PvHlS61E/t0tUhfT4Y4LTxvmuGtx1W0BE0FqhGXUiqpbPcYVbrGWHWuXfWIYA3a2D oY7EzAIqsHv2dXGn4BLZlcMFAjlvx5UncCqg1o+hF2DukR+4GKMlVcUArxzFRu0c4JOM fregTfZjYgGmO29WQBFQ/vLQIaxgMJ+Z8lidwDFfQ+Lut46IBbSlDRMlzZHPBiYtaNAZ pLE+Wb3/qU5uzsu/3FuBJBaakIcbm6XZBV2TU+TmnBPuF1BcUR8PXeqXsNLayXEUAIbS Dvkw== X-Gm-Message-State: AOJu0Yzd/pIHTP8njA807j/UKy24Bi4zvn4/JNqwIJVf1MQsEeD3d0ZU XWOrSS5PTls0H0sDy8iiMYq+QHPHGoWkyapw1BzDwCRX8V0MhxJFHGzHhi+Cf7B1WwAmrVtEAgW sbw== X-Google-Smtp-Source: AGHT+IEmnksPXOnOPyMBcGARSX5gju+FjDBcHcLXnaeiKq7G4rwVnViqpwcHUHMTpdK4WE7jlmGcQw== X-Received: by 2002:adf:ab09:0:b0:366:dee6:a9ea with SMTP id ffacd0b85a97d-36bb35de1c4mr3205621f8f.26.1722582742017; Fri, 02 Aug 2024 00:12:22 -0700 (PDT) Received: from localhost.localdomain ([2001:861:3382:1a90:b6aa:4751:9ea1:da1e]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-36bbd059932sm1195770f8f.69.2024.08.02.00.12.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Aug 2024 00:12:21 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED 01/26] ada: Fix detection of suspicious loop patterns Date: Fri, 2 Aug 2024 09:11:18 +0200 Message-ID: <20240802071210.413366-1-poulhies@adacore.com> X-Mailer: git-send-email 2.45.2 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: Ronan Desplanques This patch fixes an assertion failure in some cases in the code to warn about possible misuse of range attributes in loop. The root of the problem is that this code failed to consider the case where the outer loop is a while loop. Also fix a typo in a nearby comment. gcc/ada/ * sem_ch5.adb (Analyze_Loop_Statement): Fix loop pattern detection code. Fix typo. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_ch5.adb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/gcc/ada/sem_ch5.adb b/gcc/ada/sem_ch5.adb index e4506036cc2..4db3a1a26ee 100644 --- a/gcc/ada/sem_ch5.adb +++ b/gcc/ada/sem_ch5.adb @@ -3967,7 +3967,7 @@ package body Sem_Ch5 is Push_Scope (Ent); Analyze_Iteration_Scheme (Iter); - -- Check for following case which merits a warning if the type E of is + -- Check for following case which merits a warning if the type of E is -- a multi-dimensional array (and no explicit subscript ranges present). -- for J in E'Range @@ -3992,6 +3992,10 @@ package body Sem_Ch5 is and then Number_Dimensions (Typ) > 1 and then Nkind (Parent (N)) = N_Loop_Statement and then Present (Iteration_Scheme (Parent (N))) + -- The next conjunct tests that the enclosing loop is + -- a for loop and not a while loop. + and then Present (Loop_Parameter_Specification + (Iteration_Scheme (Parent (N)))) then declare OIter : constant Node_Id :=