From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by sourceware.org (Postfix) with ESMTPS id 3396F384AB6F for ; Fri, 17 May 2024 08:32:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 3396F384AB6F 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 3396F384AB6F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715934777; cv=none; b=dkaO90Ut3h/Dym9B57VT5Isa/kjFHeSIgYViEsMOgVcH2qfHxR4Q6TwpHOad5ci2krixZyhDFqwH38fSZIAJcSaI/w7quH9gDFrYLr6rp6MVQFX4DPKWhT2I9bB0AGKOxmhOvGWtjRFh+KY12cQTtsbvbU30EKLl5T5e2Y/MSTA= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1715934777; c=relaxed/simple; bh=PXxrC+DKUZfBlQJemi/f7RABfJdIITNxNsXmHpJ4jHA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=Onfe8WC+skrjOK1NrWDPPCWp2fmCYMgQqyPdZsniPeud0Gfa0EnNbFTwlPZxFDcmF21o4X3qKmpGgBqtB+dUEJYuZaTezarM6SYLtdRtRdnyZ+d4BYR6ZFWGIss48G1u1CUiwCEUcUVTm0nrFlsvbBVIvJefzGYd8joP7m9oos0= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32d.google.com with SMTP id 5b1f17b1804b1-420180b5897so38522455e9.3 for ; Fri, 17 May 2024 01:32:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1715934757; x=1716539557; 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=XJOxzBM46jrlhJsN8ee1snrgwcQL8E8P505Mnofc4o0=; b=F+wIKR2CuimKmPOWgvj60pba0VezDMJh0InQjiLSBrqWuN7kuzJ2I/1NpC7EvJMJvo d7qP/KKQNl6JCjyI1YlIkr/bm04rXvD/QM5sk7yBFNiSyRhTj21ClzVK23mG2rLQTsS7 THTXJ0dLBk691EplRj/uroOpu0XDhr7ZQRLoxDFK9IjK4PWrrIu5Jm/Bf5jcRWZlzAiC kaQCvynUXSdRxF9/tBt2U8/LFt4b/NQslQjkzrzfcm6ZdWS36FYowYJNPK3SAmhUhYrv OIxoZ5VauH1clMtq6gYdt+B1p1MbMOHp6JUf1eN6KnlbkLNkL+xR0QsQfoBkLxg0BVPd fj0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1715934757; x=1716539557; 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=XJOxzBM46jrlhJsN8ee1snrgwcQL8E8P505Mnofc4o0=; b=m2z0CRf2f8p0cGpK0gTDbQDv88V43LNlbejnC8WiA9yJtX9pbAE8mOssY28bn1FstT FxoX8KLanPnfM1CJI/5+513wC7D12VuYbkpyZOwUowxDiH0ZkBJj52FZ/mdv5rC0b/6D fw6OZnnNXNTyEFqIp9uA71VgGPDJ17dBIOlJln6QtnLUtnT5fAK+xJx5HAhgllE/FMOK hfhfmyLHCZB6Yt2LcQEpihbRWgkCUfhe88b0k7uIhl2ZzQWQGF+PNPcA9dPIeom7AlBp dVUtM/GtX4AKSK2LwtMuNxi57CP1EblGKKIFecXCfmnC4KTnebFJeCXJ2sy09+IHbZfD ygLA== X-Gm-Message-State: AOJu0YznahmvP8CqO89u5hf3diPt8tACdwcwKZjZnUX0bUqFiEuhvCCA zFw+Dh3wYMmENzOhXv2OtOwU4KbzptYhjp4Du9TADqTl2xyf1mcBfsOzQewudGIO7X7XBlpDwSo = X-Google-Smtp-Source: AGHT+IGxgbVyiBb4vn0eFVzBer7CVoNu7poeJ/LQFBeTkUF4TPLoVKEZOCSGbHBT+qcZavrSAw0MOA== X-Received: by 2002:a05:600c:4e88:b0:420:1551:96ab with SMTP id 5b1f17b1804b1-42015519952mr111155385e9.10.1715934756958; Fri, 17 May 2024 01:32:36 -0700 (PDT) Received: from poulhies-Precision-5550.lan ([2001:861:3382:1a90:de37:8b1c:1f33:2610]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-420273cff03sm75197045e9.26.2024.05.17.01.32.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 May 2024 01:32:36 -0700 (PDT) From: =?UTF-8?q?Marc=20Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Ronan Desplanques Subject: [COMMITTED 22/35] ada: Clarify code for aggregate warnings Date: Fri, 17 May 2024 10:31:54 +0200 Message-ID: <20240517083207.130391-22-poulhies@adacore.com> X-Mailer: git-send-email 2.43.2 In-Reply-To: <20240517083207.130391-1-poulhies@adacore.com> References: <20240517083207.130391-1-poulhies@adacore.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-14.1 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: Ronan Desplanques This patch improves comments in code that emits warnings about particular situations involving aggregates. It also removes a conjunct in a condition that's useless because always true in the context of the test. gcc/ada/ * sem_aggr.adb (Resolve_Array_Aggregate): Improve comments and condition. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/sem_aggr.adb | 52 +++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/gcc/ada/sem_aggr.adb b/gcc/ada/sem_aggr.adb index ee9beb04c9a..14c68b5eaf3 100644 --- a/gcc/ada/sem_aggr.adb +++ b/gcc/ada/sem_aggr.adb @@ -2873,9 +2873,9 @@ package body Sem_Aggr is -- No others clause present else - -- Special processing if others allowed and not present. This - -- means that the bounds of the aggregate come from the index - -- constraint (and the length must match). + -- Special processing if others allowed and not present. In + -- this case, the bounds of the aggregate come from the + -- choices (RM 4.3.3 (27)). if Others_Allowed then Get_Index_Bounds (Index_Constr, Aggr_Low, Aggr_High); @@ -2890,30 +2890,28 @@ package body Sem_Aggr is return False; end if; - -- If others allowed, and no others present, then the array - -- should cover all index values. If it does not, we will - -- get a length check warning, but there is two cases where - -- an additional warning is useful: - - -- If we have no positional components, and the length is - -- wrong (which we can tell by others being allowed with - -- missing components), and the index type is an enumeration - -- type, then issue appropriate warnings about these missing - -- components. They are only warnings, since the aggregate - -- is fine, it's just the wrong length. We skip this check - -- for standard character types (since there are no literals - -- and it is too much trouble to concoct them), and also if - -- any of the bounds have values that are not known at - -- compile time. - - -- Another case warranting a warning is when the length - -- is right, but as above we have an index type that is - -- an enumeration, and the bounds do not match. This is a - -- case where dubious sliding is allowed and we generate a - -- warning that the bounds do not match. - - if No (Expressions (N)) - and then Nkind (Index) = N_Range + -- If there is an applicable index constraint and others is + -- not present, then sliding is allowed and only a length + -- check will be performed. However, additional warnings are + -- useful if the index type is an enumeration type, as + -- sliding is dubious in this case. We emit two kinds of + -- warnings: + -- + -- 1. If the length is wrong then there are missing + -- components; we issue appropriate warnings about + -- these missing components. They are only warnings, + -- since the aggregate is fine, it's just the wrong + -- length. We skip this check for standard character + -- types (since there are no literals and it is too + -- much trouble to concoct them), and also if any of + -- the bounds have values that are not known at compile + -- time. + -- + -- 2. If the length is right but the bounds do not match, + -- we issue a warning, as we consider sliding dubious + -- when the index type is an enumeration type. + + if Nkind (Index) = N_Range and then Is_Enumeration_Type (Etype (Index)) and then not Is_Standard_Character_Type (Etype (Index)) and then Compile_Time_Known_Value (Aggr_Low) -- 2.43.2