From patchwork Mon Jun 10 09:07:40 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: 1945803 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=ZTx5XWC+; 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 4VyR735GSLz20Py for ; Mon, 10 Jun 2024 19:18:23 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 077DA3858417 for ; Mon, 10 Jun 2024 09:18:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id D19B73858402 for ; Mon, 10 Jun 2024 09:08:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D19B73858402 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 D19B73858402 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718010505; cv=none; b=d36oFsTLEd0pFbjT8B6qihVfuKNUTZGOWcF7DDBW9UMvHEFCJi2LQhucFtOWcdUotuuVjTW7TGRlkfYDRAfrjPw27F3RXgGeRksunJkxZMbgIewfv60p4Nxp1rWRGH66jAtErg0FucTYDmrsc/4pKS2J5JNCM75CL8MdcnUUKMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718010505; c=relaxed/simple; bh=FagBpALKC8jB7s5vYg8xnjo7dcIbgqXL9kU7+AncOvU=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=N6Gq+cSeqSgsL+ankCgeWNjGPVJ4MOj/Arl5e0t6Yoia0JkIONcRpyAfCjuiOVY+1OU4zMAXWZWgjO582dCSDnUZf9etF1N85Cu89HZI6IG2ZH9kluNqOE5GXIavA+tt353oq3kftFvWc6AMbKQhUVwAZ3Q5uwuLifWbUuYgzDQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-4218314a6c7so7455605e9.0 for ; Mon, 10 Jun 2024 02:08:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=adacore.com; s=google; t=1718010500; x=1718615300; 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=B1bnRavV1yb+e4AqWI8+8gsUL3iKUzcy24Uo+wT5Tgc=; b=ZTx5XWC+OBnndsW8zNdScBTwX5PMZ5etbF6maQNDhok0sw23vctk+9YpqI19ahINQH 8CZu7R2AxGiWEPB7fbaLHIai0NL52ZIltu7zBpxFkO/3J7n1zIBl1CnX/7v3a43BTWzm 7wM8BJTZGUF3YQAS9A+MQmOTJuvnUARfa2ZaWANOOHCCSwLPFDXCz9J6KecTWrpdAoAW eSxrkLruGWypjQYV0ec2pWGLlhQm8dNovH0jqlvvSY6Afc3bE4vJboAF9P2P6UkG2Y0G QYYFCcOxpZpRFyEx7WfDILxOnOkDaX+sCYSKMQQvJQ6IYVGunDS40DtnQfOsqO2yRzDh TJIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718010500; x=1718615300; 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=B1bnRavV1yb+e4AqWI8+8gsUL3iKUzcy24Uo+wT5Tgc=; b=Ah167fptmuLfG4Io7aEnApuxVSZfh14Yw2DaQnBvR4GvzEMPXOAtt7wLjJHjcf+EUW lHNP0RuvZGSckaSpUQxyqPTuKnMR3R3jcuImr8cO6jqix6jZFRRBwdBYQ23aILT0kssU SM65mqrbJWIwVZDKvlyxeMl9qxw64bJROL/AIOAznoXq8JL2aG0w04ZQcyb/DRklXtpN AlANnWT81Luespb0IK53PeD+K9Pgxc35Hq46AK8qZff32HqFturBeQAY3dOo4Q4kZW+A nNWWZ5K864e1s6afJNWGqFwWWVjL/ak4RUlZAD1QFYV0CjKbXzKaiXLtKFjmmHwynKbt VxoQ== X-Gm-Message-State: AOJu0YylHSVy6DnvMOIQiWmzor2ZCNG3NmjwcoYBPPazMeNCqncPu5yx FIOdApy9dh3O99csI5FeZIKK0pKJ4g0kkH1v3LHEcY7qZOHJXQHGTQBQ1oU5jCyuGQI0wENVcvI = X-Google-Smtp-Source: AGHT+IFmQMBDsSZJNR7ifld81BB6dhbVHK2ChyupJSOQafHJjLr4D5kZLXElkNTcq0Qm9/UisFwAxQ== X-Received: by 2002:a05:600c:474d:b0:420:29dd:84d0 with SMTP id 5b1f17b1804b1-42164a21e80mr65813765e9.29.1718010500638; Mon, 10 Jun 2024 02:08:20 -0700 (PDT) Received: from poulhies-Precision-5550.telnowedge.local (lmontsouris-659-1-24-67.w81-250.abo.wanadoo.fr. [81.250.175.67]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f0f551c20sm6454970f8f.69.2024.06.10.02.08.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 10 Jun 2024 02:08:20 -0700 (PDT) From: =?utf-8?q?Marc_Poulhi=C3=A8s?= To: gcc-patches@gcc.gnu.org Cc: Justin Squirek Subject: [COMMITTED 24/30] ada: Missing style check for extra parentheses in operators Date: Mon, 10 Jun 2024 11:07:40 +0200 Message-ID: <20240610090747.1557638-24-poulhies@adacore.com> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240610090747.1557638-1-poulhies@adacore.com> References: <20240610090747.1557638-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, T_SCC_BODY_TEXT_LINE 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: Justin Squirek This patch fixes an issue in the compiler whereby wrapping an operand of a boolean operator resulted in a failure to detect whether or not they were unnecessary for the -gnatyx style checks. gcc/ada/ * ali.adb (Get_Nat): Remove unnecessary parentheses. * exp_ch11.adb (Expand_Local_Exception_Handlers): Remove unnecessary parentheses. * freeze.adb (Freeze_Entity): Remove unnecessary parentheses. * lib-list.adb (List): Remove unnecessary parentheses. * par-ch5.adb (P_Condition): Add extra parentheses checks on condition operands. * sem_ch3.adb (Add_Interface_Tag_Components): Remove unnecessary parentheses. (Check_Delta_Expression): Remove unnecessary parenthesis. (Check_Digits_Expression): Remove unnecessary parentheses. * sem_ch12.adb (Validate_Array_Type_Instance): Remove unnecessary parentheses. Tested on x86_64-pc-linux-gnu, committed on master. --- gcc/ada/ali.adb | 2 +- gcc/ada/exp_ch11.adb | 2 +- gcc/ada/freeze.adb | 2 +- gcc/ada/lib-list.adb | 4 ++-- gcc/ada/par-ch5.adb | 25 +++++++++++++++++++++++++ gcc/ada/sem_ch12.adb | 2 +- gcc/ada/sem_ch3.adb | 6 +++--- 7 files changed, 34 insertions(+), 9 deletions(-) diff --git a/gcc/ada/ali.adb b/gcc/ada/ali.adb index 69a91bce5ab..7c7f790325b 100644 --- a/gcc/ada/ali.adb +++ b/gcc/ada/ali.adb @@ -1351,7 +1351,7 @@ package body ALI is -- Check if we are on a number. In the case of bad ALI files, this -- may not be true. - if not (Nextc in '0' .. '9') then + if Nextc not in '0' .. '9' then Fatal_Error; end if; diff --git a/gcc/ada/exp_ch11.adb b/gcc/ada/exp_ch11.adb index 9a0f66ff440..678d76cf3eb 100644 --- a/gcc/ada/exp_ch11.adb +++ b/gcc/ada/exp_ch11.adb @@ -552,7 +552,7 @@ package body Exp_Ch11 is -- Nothing to do if no handlers requiring the goto transformation - if not (Local_Expansion_Required) then + if not Local_Expansion_Required then return; end if; diff --git a/gcc/ada/freeze.adb b/gcc/ada/freeze.adb index ea6106e6455..ea18f87a4ab 100644 --- a/gcc/ada/freeze.adb +++ b/gcc/ada/freeze.adb @@ -6963,7 +6963,7 @@ package body Freeze is if Is_Type (Comp) then Freeze_And_Append (Comp, N, Result); - elsif (Ekind (Comp)) /= E_Function then + elsif Ekind (Comp) /= E_Function then -- The guard on the presence of the Etype seems to be needed -- for some CodePeer (-gnatcC) cases, but not clear why??? diff --git a/gcc/ada/lib-list.adb b/gcc/ada/lib-list.adb index ecc29258e13..210827abf8e 100644 --- a/gcc/ada/lib-list.adb +++ b/gcc/ada/lib-list.adb @@ -80,7 +80,7 @@ begin else Write_Unit_Name (Unit_Name (Sorted_Units (R))); - if Name_Len > (Unit_Length - 1) then + if Name_Len > Unit_Length - 1 then Write_Eol; Write_Str (Unit_Bln); else @@ -91,7 +91,7 @@ begin Write_Name (Full_File_Name (Source_Index (Sorted_Units (R)))); - if Name_Len > (File_Length - 1) then + if Name_Len > File_Length - 1 then Write_Eol; Write_Str (Unit_Bln); Write_Str (File_Bln); diff --git a/gcc/ada/par-ch5.adb b/gcc/ada/par-ch5.adb index d72ddffdece..68c3025e3a0 100644 --- a/gcc/ada/par-ch5.adb +++ b/gcc/ada/par-ch5.adb @@ -1360,6 +1360,31 @@ package body Ch5 is else if Style_Check then Style.Check_Xtra_Parens (Cond); + + -- When the condition is an operator then examine parentheses + -- surrounding the condition's operands - taking care to avoid + -- flagging operands which themselves are operators since they + -- may be required for resolution or precedence. + + if Nkind (Cond) in N_Op + | N_Membership_Test + | N_Short_Circuit + and then Nkind (Right_Opnd (Cond)) not in N_Op + | N_Membership_Test + | N_Short_Circuit + then + Style.Check_Xtra_Parens (Right_Opnd (Cond)); + end if; + + if Nkind (Cond) in N_Binary_Op + | N_Membership_Test + | N_Short_Circuit + and then Nkind (Left_Opnd (Cond)) not in N_Op + | N_Membership_Test + | N_Short_Circuit + then + Style.Check_Xtra_Parens (Left_Opnd (Cond)); + end if; end if; -- And return the result diff --git a/gcc/ada/sem_ch12.adb b/gcc/ada/sem_ch12.adb index 9919cda6340..7daa35f7fe1 100644 --- a/gcc/ada/sem_ch12.adb +++ b/gcc/ada/sem_ch12.adb @@ -13228,7 +13228,7 @@ package body Sem_Ch12 is Abandon_Instantiation (Actual); elsif Nkind (Def) = N_Constrained_Array_Definition then - if not (Is_Constrained (Act_T)) then + if not Is_Constrained (Act_T) then Error_Msg_NE ("expect constrained array in instantiation of &", Actual, Gen_T); diff --git a/gcc/ada/sem_ch3.adb b/gcc/ada/sem_ch3.adb index 0403babff13..cbe2ef8be54 100644 --- a/gcc/ada/sem_ch3.adb +++ b/gcc/ada/sem_ch3.adb @@ -1616,7 +1616,7 @@ package body Sem_Ch3 is Last_Tag := Empty; - if not (Present (Component_List (Ext))) then + if not Present (Component_List (Ext)) then Set_Null_Present (Ext, False); L := New_List; Set_Component_List (Ext, @@ -12454,7 +12454,7 @@ package body Sem_Ch3 is procedure Check_Delta_Expression (E : Node_Id) is begin - if not (Is_Real_Type (Etype (E))) then + if not Is_Real_Type (Etype (E)) then Wrong_Type (E, Any_Real); elsif not Is_OK_Static_Expression (E) then @@ -12482,7 +12482,7 @@ package body Sem_Ch3 is procedure Check_Digits_Expression (E : Node_Id) is begin - if not (Is_Integer_Type (Etype (E))) then + if not Is_Integer_Type (Etype (E)) then Wrong_Type (E, Any_Integer); elsif not Is_OK_Static_Expression (E) then